Skip to content

Commit 374e6ad

Browse files
authored
Merge branch 'develop' into feature/add-coinmarketcap-plugin
2 parents a06c96c + 71180ba commit 374e6ad

15 files changed

+582
-20
lines changed

.env.example

+5
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ HELIUS_API_KEY=
227227

228228
# Telegram Configuration
229229
TELEGRAM_BOT_TOKEN=
230+
TELEGRAM_API_ROOT=
230231

231232
# Together Configuration
232233
TOGETHER_API_KEY=
@@ -419,6 +420,10 @@ FUEL_WALLET_PRIVATE_KEY=
419420
TOKENIZER_MODEL= # Specify the tokenizer model to be used.
420421
TOKENIZER_TYPE= # Options: tiktoken (for OpenAI models) or auto (AutoTokenizer from Hugging Face for non-OpenAI models). Default: tiktoken.
421422

423+
#LetzAI
424+
LETZAI_API_KEY= # LetzAI API Key
425+
LETZAI_MODELS= # list of Letzai models to add to each prompt, e.g.: "@modelname1, @modelname2"
426+
422427

423428
# Spheron
424429
SPHERON_PRIVATE_KEY=

agent/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"@elizaos/plugin-fuel": "workspace:*",
7373
"@elizaos/plugin-avalanche": "workspace:*",
7474
"@elizaos/plugin-web-search": "workspace:*",
75+
"@elizaos/plugin-letzai": "workspace:*",
7576
"@elizaos/plugin-thirdweb": "workspace:*",
7677
"@elizaos/plugin-genlayer": "workspace:*",
7778
"@elizaos/plugin-depin": "workspace:*",

agent/src/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import { webSearchPlugin } from "@elizaos/plugin-web-search";
8282

8383
import { giphyPlugin } from "@elizaos/plugin-giphy";
8484
import { echoChamberPlugin } from "@elizaos/plugin-echochambers";
85+
import { letzAIPlugin } from "@elizaos/plugin-letzai";
8586
import { thirdwebPlugin } from "@elizaos/plugin-thirdweb";
8687

8788
import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
@@ -369,6 +370,11 @@ export function getTokenForProvider(
369370
character.settings?.secrets?.GOOGLE_GENERATIVE_AI_API_KEY ||
370371
settings.GOOGLE_GENERATIVE_AI_API_KEY
371372
);
373+
case ModelProviderName.LETZAI:
374+
return (
375+
character.settings?.secrets?.LETZAI_API_KEY ||
376+
settings.LETZAI_API_KEY
377+
);
372378
case ModelProviderName.INFERA:
373379
return (
374380
character.settings?.secrets?.INFERA_API_KEY ||
@@ -690,6 +696,7 @@ export async function createAgent(
690696
getSecret(character, "ECHOCHAMBERS_API_KEY")
691697
? echoChambersPlugin
692698
: null,
699+
getSecret(character, "LETZAI_API_KEY") ? letzAIPlugin : null,
693700
getSecret(character, "STARGAZE_ENDPOINT") ? stargazePlugin : null,
694701
getSecret(character, "GIPHY_API_KEY") ? giphyPlugin : null,
695702
getSecret(character, "GENLAYER_PRIVATE_KEY")

packages/client-telegram/src/telegramClient.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ export class TelegramClient {
1111
private backend;
1212
private backendToken;
1313
private tgTrader;
14+
private options;
1415

1516
constructor(runtime: IAgentRuntime, botToken: string) {
1617
elizaLogger.log("📱 Constructing new TelegramClient...");
18+
this.options = {
19+
telegram: {
20+
apiRoot: runtime.getSetting("TELEGRAM_API_ROOT") || process.env.TELEGRAM_API_ROOT || "https://api.telegram.org"
21+
},
22+
};
1723
this.runtime = runtime;
18-
this.bot = new Telegraf(botToken);
24+
this.bot = new Telegraf(botToken,this.options);
1925
this.messageManager = new MessageManager(this.bot, this.runtime);
2026
this.backend = runtime.getSetting("BACKEND_URL");
2127
this.backendToken = runtime.getSetting("BACKEND_TOKEN");

packages/core/src/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ export enum ModelProviderName {
255255
VENICE = "venice",
256256
AKASH_CHAT_API = "akash_chat_api",
257257
LIVEPEER = "livepeer",
258+
LETZAI = "letzai",
258259
INFERA = "infera",
259260
}
260261

@@ -1119,7 +1120,7 @@ export interface IRAGKnowledgeManager {
11191120
processFile(file: {
11201121
path: string;
11211122
content: string;
1122-
type: 'pdf' | 'md' | 'txt',
1123+
type: "pdf" | "md" | "txt";
11231124
isShared: boolean;
11241125
}): Promise<void>;
11251126
}

packages/plugin-letzai/.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
3+
!dist/**
4+
!package.json
5+
!readme.md
6+
!tsup.config.ts

packages/plugin-letzai/README.md

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# @elizaos/plugin-letzai
2+
3+
![LetzAI Logo](https://letz.ai/_next/image?url=%2FL.png&w=64&q=100)
4+
5+
A plugin to integrate LetzAI Image Generation capabilities into the elizaOS ecosystem.
6+
7+
It uses the [LetzAI API](https://www.letz.ai/docs/api) and can use any models available to API user.
8+
9+
Users need to add their LETZAI_API_KEY in .env file.
10+
11+
12+
## Description
13+
14+
[LetzAI](https://www.letz.ai) is an image generation platform and visual discovery engine. It enables anyone to generate images about anything, by allowing users to add themselves, their products or their art style to the platform as AI Models.
15+
16+
This plugin integrates LetzAI with Eliza, enabling agents to generate images using any LetzAI Models, including the ones you may have created specifically of or for your agent.
17+
18+
To use this plugin, you will need a LetzAI API Key, which [can be created on your subscription page here](https://www.letz.ai/subscription). A subscription is required to create an API key.
19+
20+
To generate images the plugin introduces its own GENERATE_IMAGE action.
21+
22+
The plugin was not tested together with other image generation functionalities.
23+
24+
25+
## Installation
26+
27+
```bash
28+
pnpm install @elizaos/plugin-letzai
29+
```
30+
31+
32+
## Configuration
33+
34+
### Environment Variables
35+
```typescript
36+
LETZAI_API_LEY=<Your LetzAI API Key>
37+
LETZAI_MODELS="@hailee, @examplemodel2"
38+
```
39+
40+
Inside the plugin's index.tsx file is a "improvePrompt" variable and some code that is commented out. This code could be enhanced to make the instructions from chat be passed to the API in a better way. This is an open TO DO.
41+
42+
## Development Guide
43+
44+
### Setting Up Development Environment
45+
46+
1. Clone the repository
47+
2. Install dependencies:
48+
49+
```bash
50+
pnpm install
51+
```
52+
53+
3. Build the plugin:
54+
55+
```bash
56+
pnpm run build
57+
```
58+
59+
60+
## Example
61+
62+
I am currently working on an example Agent called ["HaileeAgent"](https://x.com/AgentHailee).
63+
Will share more information on this as I progress.
64+
65+
66+
67+
## Other Notes
68+
In my own character.json file for Hailee, I have integrated the plugin like this:
69+
```json
70+
"plugins": ["../../packages/plugin-letzai/src/index.ts"],
71+
"actions": ["GENERATE_IMAGE"],
72+
```
73+
74+
But I'm not sure yet this is the correct way for public repos.
75+
76+
77+
## Future Enhancements
78+
79+
- Interactive agent with better image polling
80+
- Enable "Improve prompt" functionality
81+
82+
If anybody knows how to make the agent be pro-active and send multiple callbacks(), please reach out.
83+
84+
85+
86+
## Contributing
87+
88+
This Plugin is developed by LetzAI. Any helpful contributions are welcome!
89+
90+
91+
## Credits
92+
93+
Built by [mitch0z](https://www.mitchoz.com)
94+
95+
96+
## License
97+
98+
This plugin is part of the Eliza project. See the main project repository for license information.
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintGlobalConfig from "../../eslint.config.mjs";
2+
3+
export default [...eslintGlobalConfig];

packages/plugin-letzai/package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@elizaos/plugin-letzai",
3+
"version": "0.0.1",
4+
"author": "LetzAI",
5+
"description": "Enables Image Generation through LetzAI API",
6+
"main": "dist/index.js",
7+
"type": "module",
8+
"types": "dist/index.d.ts",
9+
"dependencies": {
10+
"@elizaos/core": "workspace:*",
11+
"tsup": "8.3.5"
12+
},
13+
"scripts": {
14+
"build": "tsup --format esm --dts",
15+
"dev": "tsup --format esm --dts --watch",
16+
"lint": "eslint --fix --cache ."
17+
}
18+
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { IAgentRuntime } from "@elizaos/core";
2+
import { z } from "zod";
3+
4+
export const imageGenEnvSchema = z
5+
.object({
6+
LETZAI_API_KEY: z.string().optional(),
7+
})
8+
.refine(
9+
(data) => {
10+
return !!data.LETZAI_API_KEY;
11+
},
12+
{
13+
message: "The LetzAI API KEY has not been set.",
14+
},
15+
);
16+
17+
export type ImageGenConfig = z.infer<typeof imageGenEnvSchema>;
18+
19+
export async function validateImageGenConfig(
20+
runtime: IAgentRuntime,
21+
): Promise<ImageGenConfig> {
22+
try {
23+
const config = {
24+
LETZAI_API_KEY: runtime.getSetting("LETZAI_API_KEY"),
25+
};
26+
27+
return imageGenEnvSchema.parse(config);
28+
} catch (error) {
29+
if (error instanceof z.ZodError) {
30+
const errorMessages = error.errors
31+
.map((err) => `${err.path.join(".")}: ${err.message}`)
32+
.join("\n");
33+
throw new Error(
34+
`Image generation configuration validation failed:\n${errorMessages}`,
35+
);
36+
}
37+
throw error;
38+
}
39+
}
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// I left this file here, because I was using it to test multiple callbacks in one file.
2+
// If anybody knows how to achieve that, please lmk
3+
4+
export const letzAiImageGeneration = {
5+
name: "GENERATE_IMAGE",
6+
similes: ["IMAGE_GENERATION", "IMAGE_GEN"],
7+
description: "Generate an image via LetzAI API (with polling).",
8+
suppressInitialMessage: true,
9+
10+
// Provide a default validate() that simply returns true
11+
validate: async (_runtime: any, _message: any, _state: any) => {
12+
return true;
13+
},
14+
15+
// Add a simple handler that outputs "OK" when triggered
16+
handler: (
17+
runtime: any,
18+
message: any,
19+
state: any,
20+
options: any,
21+
callback: any,
22+
) => {
23+
// For now, just call the callback with "OK"
24+
callback({
25+
text: "OK",
26+
});
27+
28+
callback({
29+
text: "OK2",
30+
});
31+
},
32+
33+
// Add examples to show how this action might be used in conversation
34+
examples: [
35+
[
36+
{
37+
user: "{{user1}}",
38+
content: {
39+
text: "Generate an image of a neon futuristic cityscape",
40+
},
41+
},
42+
{
43+
user: "{{agentName}}",
44+
content: {
45+
text: "Okay give me a second",
46+
action: "GENERATE_IMAGE",
47+
},
48+
},
49+
{
50+
user: "{{agentName}}",
51+
content: {
52+
text: "Sure, generating image via LetzAI...",
53+
action: "GENERATE_IMAGE",
54+
},
55+
},
56+
],
57+
[
58+
{
59+
user: "{{user2}}",
60+
content: {
61+
text: "Please make a fantasy landscape with dragons and castles",
62+
},
63+
},
64+
{
65+
user: "{{agentName}}",
66+
content: {
67+
text: "Alright, generating image now...",
68+
action: "GENERATE_IMAGE",
69+
},
70+
},
71+
],
72+
],
73+
};
74+
75+
export const letzAIPlugin = {
76+
name: "letzai",
77+
actions: [letzAiImageGeneration],
78+
};
79+

0 commit comments

Comments
 (0)