@elizaos/plugin-openai 0.25.6-alpha.1 → 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,63 +1,84 @@
1
+ # OpenAI Plugin
1
2
 
2
- # @elizaos/plugin-openai
3
+ This plugin provides integration with OpenAI's models through the ElizaOS platform.
3
4
 
4
- A plugin for OpenAI integration, providing automated text generation capabilities.
5
-
6
- ## Overview
7
-
8
- This plugin provides functionality to:
9
-
10
- - Generate text using OpenAI's GPT models.
11
- - Customize prompts for context-aware content generation.
5
+ ## Usage
12
6
 
13
- ## Installation
7
+ Add the plugin to your character configuration:
14
8
 
15
- ```bash
16
- npm install @elizaos/plugin-openai
9
+ ```json
10
+ "plugins": ["@elizaos/plugin-openai"]
17
11
  ```
18
12
 
19
13
  ## Configuration
20
14
 
21
- The plugin requires the following environment variable:
15
+ The plugin requires these environment variables (can be set in .env file or character settings):
22
16
 
23
- ```env
24
- OPENAI_API_KEY=your_openai_api_key
17
+ ```json
18
+ "settings": {
19
+ "OPENAI_API_KEY": "your_openai_api_key",
20
+ "OPENAI_BASE_URL": "optional_custom_endpoint",
21
+ "OPENAI_SMALL_MODEL": "gpt-4o-mini",
22
+ "OPENAI_LARGE_MODEL": "gpt-4o"
23
+ }
25
24
  ```
26
25
 
27
- ## Usage
28
-
29
- Import and register the plugin in your Eliza configuration:
30
-
31
- ```typescript
32
- import { openaiPlugin } from "@elizaos/plugin-openai";
33
-
34
- export default {
35
- plugins: [openaiPlugin],
36
- // ... other configuration
37
- };
26
+ Or in `.env` file:
38
27
  ```
39
-
40
- ### Generating Text
41
-
42
- ```typescript
43
- const result = await generateTextAction.handler(runtime, message, state);
44
- console.log(result.text); // Output generated by OpenAI
28
+ OPENAI_API_KEY=your_openai_api_key
29
+ # Optional overrides:
30
+ OPENAI_BASE_URL=optional_custom_endpoint
31
+ OPENAI_SMALL_MODEL=gpt-4o-mini
32
+ OPENAI_LARGE_MODEL=gpt-4o
45
33
  ```
46
34
 
47
- ## Development
48
-
49
- ### Building
50
-
51
- ```bash
52
- npm run build
35
+ ### Configuration Options
36
+ - `OPENAI_API_KEY` (required): Your OpenAI API credentials
37
+ - `OPENAI_BASE_URL`: Custom API endpoint (default: https://api.openai.com/v1)
38
+ - `OPENAI_SMALL_MODEL`: Defaults to GPT-4o Mini ("gpt-4o-mini")
39
+ - `OPENAI_LARGE_MODEL`: Defaults to GPT-4o ("gpt-4o")
40
+
41
+ The plugin provides these model classes:
42
+ - `TEXT_SMALL`: Optimized for fast, cost-effective responses
43
+ - `TEXT_LARGE`: For complex tasks requiring deeper reasoning
44
+ - `TEXT_EMBEDDING`: Text embedding model (text-embedding-3-small)
45
+ - `IMAGE`: DALL-E image generation
46
+ - `IMAGE_DESCRIPTION`: GPT-4o image analysis
47
+ - `TRANSCRIPTION`: Whisper audio transcription
48
+ - `TEXT_TOKENIZER_ENCODE`: Text tokenization
49
+ - `TEXT_TOKENIZER_DECODE`: Token decoding
50
+
51
+ ## Additional Features
52
+
53
+ ### Image Generation
54
+ ```js
55
+ await runtime.useModel(ModelClass.IMAGE, {
56
+ prompt: "A sunset over mountains",
57
+ n: 1, // number of images
58
+ size: "1024x1024" // image resolution
59
+ });
53
60
  ```
54
61
 
55
- ### Testing
56
-
57
- ```bash
58
- npm run test
62
+ ### Audio Transcription
63
+ ```js
64
+ const transcription = await runtime.useModel(
65
+ ModelClass.TRANSCRIPTION,
66
+ audioBuffer
67
+ );
59
68
  ```
60
69
 
61
- ## License
70
+ ### Image Analysis
71
+ ```js
72
+ const { title, description } = await runtime.useModel(
73
+ ModelClass.IMAGE_DESCRIPTION,
74
+ "https://example.com/image.jpg"
75
+ );
76
+ ```
62
77
 
63
- This plugin is part of the Eliza project. See the main project repository for license information.
78
+ ### Text Embeddings
79
+ ```js
80
+ const embedding = await runtime.useModel(
81
+ ModelClass.TEXT_EMBEDDING,
82
+ "text to embed"
83
+ );
84
+ ```
package/dist/index.js CHANGED
@@ -1,248 +1,404 @@
1
- // src/actions/action.ts
2
- import axios from "axios";
3
- var DEFAULT_MODEL = process.env.OPENAI_DEFAULT_MODEL || "text-davinci-003";
4
- var DEFAULT_MAX_TOKENS = Number.parseInt(process.env.OPENAI_MAX_TOKENS || "200", 10);
5
- var DEFAULT_TEMPERATURE = Number.parseFloat(process.env.OPENAI_TEMPERATURE || "0.7");
6
- var DEFAULT_TIMEOUT = 3e4;
7
- function validatePrompt(prompt) {
8
- if (!prompt.trim()) {
9
- throw new Error("Prompt cannot be empty");
10
- }
11
- if (prompt.length > 4e3) {
12
- throw new Error("Prompt exceeds maximum length of 4000 characters");
13
- }
1
+ // src/index.ts
2
+ import { createOpenAI } from "@ai-sdk/openai";
3
+ import {
4
+ ModelTypes
5
+ } from "@elizaos/core";
6
+ import { generateText } from "ai";
7
+ import { encodingForModel } from "js-tiktoken";
8
+ import { z } from "zod";
9
+ async function tokenizeText(model, prompt) {
10
+ const modelName = model === ModelTypes.TEXT_SMALL ? process.env.OPENAI_SMALL_MODEL ?? process.env.SMALL_MODEL ?? "gpt-4o-mini" : process.env.LARGE_MODEL ?? "gpt-4o";
11
+ const encoding = encodingForModel(modelName);
12
+ const tokens = encoding.encode(prompt);
13
+ return tokens;
14
14
  }
15
- function validateApiKey() {
16
- const apiKey = process.env.OPENAI_API_KEY;
17
- if (!apiKey) {
18
- throw new Error("OpenAI API key is not set");
19
- }
20
- return apiKey;
15
+ async function detokenizeText(model, tokens) {
16
+ const modelName = model === ModelTypes.TEXT_SMALL ? process.env.OPENAI_SMALL_MODEL ?? process.env.SMALL_MODEL ?? "gpt-4o-mini" : process.env.OPENAI_LARGE_MODEL ?? process.env.LARGE_MODEL ?? "gpt-4o";
17
+ const encoding = encodingForModel(modelName);
18
+ return encoding.decode(tokens);
21
19
  }
22
- async function callOpenAiApi(url, data, apiKey) {
23
- try {
24
- const config = {
25
- headers: {
26
- Authorization: `Bearer ${apiKey}`,
27
- "Content-Type": "application/json"
28
- },
29
- timeout: DEFAULT_TIMEOUT
30
- };
31
- const response = await axios.post(url, data, config);
32
- return response.data;
33
- } catch (error) {
34
- console.error("Error communicating with OpenAI API:", error instanceof Error ? error.message : String(error));
35
- if (axios.isAxiosError(error)) {
36
- if (error.response?.status === 429) {
37
- throw new Error("Rate limit exceeded. Please try again later.");
20
+ var configSchema = z.object({
21
+ OPENAI_API_KEY: z.string().min(1, "OpenAI API key is required"),
22
+ OPENAI_BASE_URL: z.string().url().optional(),
23
+ OPENAI_SMALL_MODEL: z.string().optional(),
24
+ OPENAI_LARGE_MODEL: z.string().optional(),
25
+ SMALL_MODEL: z.string().optional(),
26
+ LARGE_MODEL: z.string().optional()
27
+ });
28
+ var openaiPlugin = {
29
+ name: "openai",
30
+ description: "OpenAI plugin",
31
+ config: {
32
+ OPENAI_API_KEY: process.env.OPENAI_API_KEY,
33
+ OPENAI_BASE_URL: process.env.OPENAI_BASE_URL,
34
+ OPENAI_SMALL_MODEL: process.env.OPENAI_SMALL_MODEL,
35
+ OPENAI_LARGE_MODEL: process.env.OPENAI_LARGE_MODEL,
36
+ SMALL_MODEL: process.env.SMALL_MODEL,
37
+ LARGE_MODEL: process.env.LARGE_MODEL
38
+ },
39
+ async init(config) {
40
+ try {
41
+ const validatedConfig = await configSchema.parseAsync(config);
42
+ for (const [key, value] of Object.entries(validatedConfig)) {
43
+ if (value) process.env[key] = value;
44
+ }
45
+ const baseURL = process.env.OPENAI_BASE_URL ?? "https://api.openai.com/v1";
46
+ const response = await fetch(`${baseURL}/models`, {
47
+ headers: { Authorization: `Bearer ${process.env.OPENAI_API_KEY}` }
48
+ });
49
+ if (!response.ok) {
50
+ throw new Error(
51
+ `Failed to validate OpenAI API key: ${response.statusText}`
52
+ );
38
53
  }
54
+ } catch (error) {
55
+ if (error instanceof z.ZodError) {
56
+ throw new Error(
57
+ `Invalid plugin configuration: ${error.errors.map((e) => e.message).join(
58
+ ", "
59
+ )} - You need to configure the OPENAI_API_KEY in your environment variables`
60
+ );
61
+ }
62
+ throw error;
39
63
  }
40
- throw new Error("Failed to communicate with OpenAI API");
41
- }
42
- }
43
- function buildRequestData(prompt, model = DEFAULT_MODEL, maxTokens = DEFAULT_MAX_TOKENS, temperature = DEFAULT_TEMPERATURE) {
44
- return {
45
- model,
46
- prompt,
47
- max_tokens: maxTokens,
48
- temperature
49
- };
50
- }
51
-
52
- // src/actions/generateTextAction.ts
53
- var generateTextAction = {
54
- name: "generateText",
55
- description: "Generate text using OpenAI",
56
- similes: [],
57
- async handler(_runtime, message, _state) {
58
- const prompt = message.content.text?.trim() || "";
59
- validatePrompt(prompt);
60
- const apiKey = validateApiKey();
61
- const requestData = buildRequestData(
62
- String(message.content.model),
63
- prompt,
64
- typeof message.content.maxTokens === "number" ? message.content.maxTokens : void 0,
65
- typeof message.content.temperature === "number" ? message.content.temperature : void 0
66
- );
67
- const response = await callOpenAiApi(
68
- "https://api.openai.com/v1/completions",
69
- requestData,
70
- apiKey
71
- );
72
- return { text: response.choices[0].text.trim() };
73
64
  },
74
- validate: async (runtime, _message) => {
75
- return !!runtime.getSetting("OPENAI_API_KEY");
76
- },
77
- examples: []
78
- };
79
-
80
- // src/actions/generateEmbeddingAction.ts
81
- var generateEmbeddingAction = {
82
- name: "generateEmbedding",
83
- description: "Generate embeddings using OpenAI",
84
- similes: [],
85
- async handler(_runtime, message, _state) {
86
- const input = message.content.text?.trim() || "";
87
- validatePrompt(input);
88
- const apiKey = validateApiKey();
89
- const requestData = buildRequestData(
90
- "text-embedding-ada-002",
91
- input
92
- );
93
- const response = await callOpenAiApi(
94
- "https://api.openai.com/v1/embeddings",
95
- requestData,
96
- apiKey
97
- );
98
- return response.data.map((item) => item.embedding);
99
- },
100
- validate: async (runtime, _message) => {
101
- return !!runtime.getSetting("OPENAI_API_KEY");
102
- },
103
- examples: []
104
- };
105
-
106
- // src/actions/analyzeSentimentAction.ts
107
- var analyzeSentimentAction = {
108
- name: "analyzeSentiment",
109
- description: "Analyze sentiment using OpenAI",
110
- similes: [],
111
- // Added missing required property
112
- async handler(_runtime, message, _state) {
113
- const prompt = `Analyze the sentiment of the following text: "${message.content.text?.trim() || ""}"`;
114
- validatePrompt(prompt);
115
- const apiKey = validateApiKey();
116
- const requestData = buildRequestData(prompt);
117
- const response = await callOpenAiApi(
118
- "https://api.openai.com/v1/completions",
119
- requestData,
120
- apiKey
121
- );
122
- return response.choices[0].text.trim();
123
- },
124
- validate: async (runtime, _message) => {
125
- return !!runtime.getSetting("OPENAI_API_KEY");
126
- },
127
- examples: []
128
- };
129
-
130
- // src/actions/transcribeAudioAction.ts
131
- var transcribeAudioAction = {
132
- name: "transcribeAudio",
133
- description: "Transcribe audio using OpenAI Whisper",
134
- similes: [],
135
- async handler(_runtime, message, _state) {
136
- const file = message.content.file;
137
- if (!file) {
138
- throw new Error("No audio file provided");
65
+ models: {
66
+ [ModelTypes.TEXT_EMBEDDING]: async (_runtime, text) => {
67
+ if (!text) {
68
+ return new Array(1536).fill(0);
69
+ }
70
+ const baseURL = process.env.OPENAI_BASE_URL ?? "https://api.openai.com/v1";
71
+ const response = await fetch(`${baseURL}/embeddings`, {
72
+ method: "POST",
73
+ headers: {
74
+ Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
75
+ "Content-Type": "application/json"
76
+ },
77
+ body: JSON.stringify({
78
+ model: "text-embedding-3-small",
79
+ input: text
80
+ })
81
+ });
82
+ if (!response.ok) {
83
+ throw new Error(`Failed to get embedding: ${response.statusText}`);
84
+ }
85
+ const data = await response.json();
86
+ return data.data[0].embedding;
87
+ },
88
+ [ModelTypes.TEXT_TOKENIZER_ENCODE]: async (_runtime, { prompt, modelType = ModelTypes.TEXT_LARGE }) => {
89
+ return await tokenizeText(modelType ?? ModelTypes.TEXT_LARGE, prompt);
90
+ },
91
+ [ModelTypes.TEXT_TOKENIZER_DECODE]: async (_runtime, { tokens, modelType = ModelTypes.TEXT_LARGE }) => {
92
+ return await detokenizeText(modelType ?? ModelTypes.TEXT_LARGE, tokens);
93
+ },
94
+ [ModelTypes.TEXT_SMALL]: async (runtime, { prompt, stopSequences = [] }) => {
95
+ const temperature = 0.7;
96
+ const frequency_penalty = 0.7;
97
+ const presence_penalty = 0.7;
98
+ const max_response_length = 8192;
99
+ const baseURL = runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
100
+ const openai = createOpenAI({
101
+ apiKey: runtime.getSetting("OPENAI_API_KEY"),
102
+ baseURL
103
+ });
104
+ const model = runtime.getSetting("OPENAI_SMALL_MODEL") ?? runtime.getSetting("SMALL_MODEL") ?? "gpt-4o-mini";
105
+ console.log("generating text");
106
+ console.log(prompt);
107
+ const { text: openaiResponse } = await generateText({
108
+ model: openai.languageModel(model),
109
+ prompt,
110
+ system: runtime.character.system ?? void 0,
111
+ temperature,
112
+ maxTokens: max_response_length,
113
+ frequencyPenalty: frequency_penalty,
114
+ presencePenalty: presence_penalty,
115
+ stopSequences
116
+ });
117
+ return openaiResponse;
118
+ },
119
+ [ModelTypes.TEXT_LARGE]: async (runtime, {
120
+ prompt,
121
+ stopSequences = [],
122
+ maxTokens = 8192,
123
+ temperature = 0.7,
124
+ frequencyPenalty = 0.7,
125
+ presencePenalty = 0.7
126
+ }) => {
127
+ const baseURL = runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
128
+ const openai = createOpenAI({
129
+ apiKey: runtime.getSetting("OPENAI_API_KEY"),
130
+ baseURL
131
+ });
132
+ const model = runtime.getSetting("OPENAI_LARGE_MODEL") ?? runtime.getSetting("LARGE_MODEL") ?? "gpt-4o";
133
+ const { text: openaiResponse } = await generateText({
134
+ model: openai.languageModel(model),
135
+ prompt,
136
+ system: runtime.character.system ?? void 0,
137
+ temperature,
138
+ maxTokens,
139
+ frequencyPenalty,
140
+ presencePenalty,
141
+ stopSequences
142
+ });
143
+ return openaiResponse;
144
+ },
145
+ [ModelTypes.IMAGE]: async (runtime, params) => {
146
+ const baseURL = runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
147
+ const response = await fetch(`${baseURL}/images/generations`, {
148
+ method: "POST",
149
+ headers: {
150
+ Authorization: `Bearer ${runtime.getSetting("OPENAI_API_KEY")}`,
151
+ "Content-Type": "application/json"
152
+ },
153
+ body: JSON.stringify({
154
+ prompt: params.prompt,
155
+ n: params.n || 1,
156
+ size: params.size || "1024x1024"
157
+ })
158
+ });
159
+ if (!response.ok) {
160
+ throw new Error(`Failed to generate image: ${response.statusText}`);
161
+ }
162
+ const data = await response.json();
163
+ const typedData = data;
164
+ return typedData.data;
165
+ },
166
+ [ModelTypes.IMAGE_DESCRIPTION]: async (runtime, imageUrl) => {
167
+ console.log("IMAGE_DESCRIPTION");
168
+ const baseURL = runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
169
+ console.log("baseURL", baseURL);
170
+ const openai = createOpenAI({
171
+ apiKey: runtime.getSetting("OPENAI_API_KEY"),
172
+ baseURL
173
+ });
174
+ const { text } = await generateText({
175
+ model: openai.languageModel(
176
+ runtime.getSetting("OPENAI_SMALL_MODEL") ?? "gpt-4o-mini"
177
+ ),
178
+ messages: [
179
+ {
180
+ role: "system",
181
+ content: "Provide a title and brief description of the image. Structure this as XML with the following syntax:\n<title>{{title}}</title>\n<description>{{description}}</description>\nReplacing the handlerbars with the actual text"
182
+ },
183
+ {
184
+ role: "user",
185
+ content: [
186
+ {
187
+ type: "image",
188
+ image: imageUrl
189
+ }
190
+ ]
191
+ }
192
+ ],
193
+ temperature: 0.7,
194
+ maxTokens: 1024,
195
+ frequencyPenalty: 0,
196
+ presencePenalty: 0,
197
+ stopSequences: []
198
+ });
199
+ const titleMatch = text.match(/<title>(.*?)<\/title>/);
200
+ const descriptionMatch = text.match(/<description>(.*?)<\/description>/);
201
+ if (!titleMatch || !descriptionMatch) {
202
+ throw new Error("Could not parse title or description from response");
203
+ }
204
+ return {
205
+ title: titleMatch[1],
206
+ description: descriptionMatch[1]
207
+ };
208
+ },
209
+ [ModelTypes.TRANSCRIPTION]: async (runtime, audioBuffer) => {
210
+ console.log("audioBuffer", audioBuffer);
211
+ const baseURL = runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
212
+ const formData = new FormData();
213
+ formData.append("file", new Blob([audioBuffer], { type: "audio/mp3" }));
214
+ formData.append("model", "whisper-1");
215
+ const response = await fetch(`${baseURL}/audio/transcriptions`, {
216
+ method: "POST",
217
+ headers: {
218
+ Authorization: `Bearer ${runtime.getSetting("OPENAI_API_KEY")}`
219
+ // Note: Do not set a Content-Type header—letting fetch set it for FormData is best
220
+ },
221
+ body: formData
222
+ });
223
+ console.log("response", response);
224
+ if (!response.ok) {
225
+ throw new Error(`Failed to transcribe audio: ${response.statusText}`);
226
+ }
227
+ const data = await response.json();
228
+ return data.text;
139
229
  }
140
- const apiKey = validateApiKey();
141
- const formData = new FormData();
142
- formData.append("file", file);
143
- formData.append("model", "whisper-1");
144
- const response = await callOpenAiApi(
145
- "https://api.openai.com/v1/audio/transcriptions",
146
- formData,
147
- apiKey
148
- );
149
- return response.text;
150
- },
151
- validate: async (runtime, _message) => {
152
- return !!runtime.getSetting("OPENAI_API_KEY");
153
- },
154
- examples: []
155
- };
156
-
157
- // src/actions/moderateContentAction.ts
158
- var moderateContentAction = {
159
- name: "moderateContent",
160
- description: "Moderate content using OpenAI",
161
- similes: [],
162
- async handler(_runtime, message, _state) {
163
- const input = message.content.text?.trim() || "";
164
- validatePrompt(input);
165
- const apiKey = validateApiKey();
166
- const requestData = buildRequestData(
167
- "text-moderation-latest",
168
- input
169
- );
170
- const response = await callOpenAiApi(
171
- "https://api.openai.com/v1/moderations",
172
- requestData,
173
- apiKey
174
- );
175
- return response.results;
176
- },
177
- validate: async (runtime, _message) => {
178
- return !!runtime.getSetting("OPENAI_API_KEY");
179
230
  },
180
- examples: []
181
- };
182
-
183
- // src/actions/editTextAction.ts
184
- var editTextAction = {
185
- name: "editText",
186
- description: "Edit text using OpenAI",
187
- similes: [],
188
- async handler(_runtime, message, _state) {
189
- const input = message.content.input?.trim() || "";
190
- const instruction = message.content.instruction?.trim() || "";
191
- validatePrompt(input);
192
- validatePrompt(instruction);
193
- const apiKey = validateApiKey();
194
- const requestData = {
195
- model: "text-davinci-edit-001",
196
- input,
197
- instruction,
198
- max_tokens: 1e3,
199
- temperature: 0.7
200
- };
201
- const response = await callOpenAiApi(
202
- "https://api.openai.com/v1/edits",
203
- requestData,
204
- apiKey
205
- );
206
- return response.choices[0].text.trim();
207
- },
208
- validate: async (runtime, _message) => {
209
- return !!runtime.getSetting("OPENAI_API_KEY");
210
- },
211
- examples: []
212
- };
213
-
214
- // src/index.ts
215
- console.log("\n===============================");
216
- console.log(" OpenAI Plugin Loaded ");
217
- console.log("===============================");
218
- console.log("Name : openai-plugin");
219
- console.log("Version : 0.1.0");
220
- console.log("X Account : https://x.com/Data0x88850");
221
- console.log("GitHub : https://github.com/0xrubusdata");
222
- console.log("Actions :");
223
- console.log(" - generateTextAction");
224
- console.log(" - generateEmbeddingAction");
225
- console.log(" - analyzeSentimentAction");
226
- console.log(" - transcribeAudioAction");
227
- console.log(" - moderateContentAction");
228
- console.log(" - editTextAction");
229
- console.log("===============================\n");
230
- var openaiPlugin = {
231
- name: "openai",
232
- description: "OpenAI integration plugin for various AI capabilities",
233
- actions: [
234
- generateTextAction,
235
- generateEmbeddingAction,
236
- analyzeSentimentAction,
237
- transcribeAudioAction,
238
- moderateContentAction,
239
- editTextAction
240
- ],
241
- evaluators: [],
242
- providers: []
231
+ tests: [
232
+ {
233
+ name: "openai_plugin_tests",
234
+ tests: [
235
+ {
236
+ name: "openai_test_url_and_api_key_validation",
237
+ fn: async (runtime) => {
238
+ const baseURL = runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
239
+ const response = await fetch(`${baseURL}/models`, {
240
+ headers: {
241
+ Authorization: `Bearer ${runtime.getSetting("OPENAI_API_KEY")}`
242
+ }
243
+ });
244
+ const data = await response.json();
245
+ console.log("Models Available:", data?.data.length);
246
+ if (!response.ok) {
247
+ throw new Error(
248
+ `Failed to validate OpenAI API key: ${response.statusText}`
249
+ );
250
+ }
251
+ }
252
+ },
253
+ {
254
+ name: "openai_test_text_embedding",
255
+ fn: async (runtime) => {
256
+ try {
257
+ const embedding = await runtime.useModel(
258
+ ModelTypes.TEXT_EMBEDDING,
259
+ "Hello, world!"
260
+ );
261
+ console.log("embedding", embedding);
262
+ } catch (error) {
263
+ console.error("Error in test_text_embedding:", error);
264
+ throw error;
265
+ }
266
+ }
267
+ },
268
+ {
269
+ name: "openai_test_text_large",
270
+ fn: async (runtime) => {
271
+ try {
272
+ const text = await runtime.useModel(ModelTypes.TEXT_LARGE, {
273
+ prompt: "What is the nature of reality in 10 words?"
274
+ });
275
+ if (text.length === 0) {
276
+ throw new Error("Failed to generate text");
277
+ }
278
+ console.log("generated with test_text_large:", text);
279
+ } catch (error) {
280
+ console.error("Error in test_text_large:", error);
281
+ throw error;
282
+ }
283
+ }
284
+ },
285
+ {
286
+ name: "openai_test_text_small",
287
+ fn: async (runtime) => {
288
+ try {
289
+ const text = await runtime.useModel(ModelTypes.TEXT_SMALL, {
290
+ prompt: "What is the nature of reality in 10 words?"
291
+ });
292
+ if (text.length === 0) {
293
+ throw new Error("Failed to generate text");
294
+ }
295
+ console.log("generated with test_text_small:", text);
296
+ } catch (error) {
297
+ console.error("Error in test_text_small:", error);
298
+ throw error;
299
+ }
300
+ }
301
+ },
302
+ {
303
+ name: "openai_test_image_generation",
304
+ fn: async (runtime) => {
305
+ console.log("openai_test_image_generation");
306
+ try {
307
+ const image = await runtime.useModel(ModelTypes.IMAGE, {
308
+ prompt: "A beautiful sunset over a calm ocean",
309
+ n: 1,
310
+ size: "1024x1024"
311
+ });
312
+ console.log("generated with test_image_generation:", image);
313
+ } catch (error) {
314
+ console.error("Error in test_image_generation:", error);
315
+ throw error;
316
+ }
317
+ }
318
+ },
319
+ {
320
+ name: "openai_test_image_description",
321
+ fn: async (runtime) => {
322
+ console.log("openai_test_image_description");
323
+ try {
324
+ const { title, description } = await runtime.useModel(
325
+ ModelTypes.IMAGE_DESCRIPTION,
326
+ "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Vitalik_Buterin_TechCrunch_London_2015_%28cropped%29.jpg/537px-Vitalik_Buterin_TechCrunch_London_2015_%28cropped%29.jpg"
327
+ );
328
+ console.log(
329
+ "generated with test_image_description:",
330
+ title,
331
+ description
332
+ );
333
+ } catch (error) {
334
+ console.error("Error in test_image_description:", error);
335
+ throw error;
336
+ }
337
+ }
338
+ },
339
+ {
340
+ name: "openai_test_transcription",
341
+ fn: async (runtime) => {
342
+ console.log("openai_test_transcription");
343
+ try {
344
+ const response = await fetch(
345
+ "https://upload.wikimedia.org/wikipedia/en/4/40/Chris_Benoit_Voice_Message.ogg"
346
+ );
347
+ const arrayBuffer = await response.arrayBuffer();
348
+ const transcription = await runtime.useModel(
349
+ ModelTypes.TRANSCRIPTION,
350
+ Buffer.from(new Uint8Array(arrayBuffer))
351
+ );
352
+ console.log("generated with test_transcription:", transcription);
353
+ } catch (error) {
354
+ console.error("Error in test_transcription:", error);
355
+ throw error;
356
+ }
357
+ }
358
+ },
359
+ {
360
+ name: "openai_test_text_tokenizer_encode",
361
+ fn: async (runtime) => {
362
+ const prompt = "Hello tokenizer encode!";
363
+ const tokens = await runtime.useModel(
364
+ ModelTypes.TEXT_TOKENIZER_ENCODE,
365
+ { prompt }
366
+ );
367
+ if (!Array.isArray(tokens) || tokens.length === 0) {
368
+ throw new Error(
369
+ "Failed to tokenize text: expected non-empty array of tokens"
370
+ );
371
+ }
372
+ console.log("Tokenized output:", tokens);
373
+ }
374
+ },
375
+ {
376
+ name: "openai_test_text_tokenizer_decode",
377
+ fn: async (runtime) => {
378
+ const prompt = "Hello tokenizer decode!";
379
+ const tokens = await runtime.useModel(
380
+ ModelTypes.TEXT_TOKENIZER_ENCODE,
381
+ { prompt }
382
+ );
383
+ const decodedText = await runtime.useModel(
384
+ ModelTypes.TEXT_TOKENIZER_DECODE,
385
+ { tokens }
386
+ );
387
+ if (decodedText !== prompt) {
388
+ throw new Error(
389
+ `Decoded text does not match original. Expected "${prompt}", got "${decodedText}"`
390
+ );
391
+ }
392
+ console.log("Decoded text:", decodedText);
393
+ }
394
+ }
395
+ ]
396
+ }
397
+ ]
243
398
  };
244
399
  var index_default = openaiPlugin;
245
400
  export {
246
401
  index_default as default,
247
402
  openaiPlugin
248
403
  };
404
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createOpenAI } from \"@ai-sdk/openai\";\nimport type { IAgentRuntime, ModelType, Plugin } from \"@elizaos/core\";\nimport {\n\ttype DetokenizeTextParams,\n\ttype GenerateTextParams,\n\tModelTypes,\n\ttype TokenizeTextParams,\n} from \"@elizaos/core\";\nimport { generateText } from \"ai\";\nimport { encodingForModel, type TiktokenModel } from \"js-tiktoken\";\nimport { z } from \"zod\";\n\nasync function tokenizeText(model: ModelType, prompt: string) {\n\tconst modelName =\n\t\tmodel === ModelTypes.TEXT_SMALL\n\t\t\t? (process.env.OPENAI_SMALL_MODEL ??\n\t\t\t\tprocess.env.SMALL_MODEL ??\n\t\t\t\t\"gpt-4o-mini\")\n\t\t\t: (process.env.LARGE_MODEL ?? \"gpt-4o\");\n\tconst encoding = encodingForModel(modelName as TiktokenModel);\n\tconst tokens = encoding.encode(prompt);\n\treturn tokens;\n}\n\nasync function detokenizeText(model: ModelType, tokens: number[]) {\n\tconst modelName =\n\t\tmodel === ModelTypes.TEXT_SMALL\n\t\t\t? (process.env.OPENAI_SMALL_MODEL ??\n\t\t\t\tprocess.env.SMALL_MODEL ??\n\t\t\t\t\"gpt-4o-mini\")\n\t\t\t: (process.env.OPENAI_LARGE_MODEL ?? process.env.LARGE_MODEL ?? \"gpt-4o\");\n\tconst encoding = encodingForModel(modelName as TiktokenModel);\n\treturn encoding.decode(tokens);\n}\n\nconst configSchema = z.object({\n\tOPENAI_API_KEY: z.string().min(1, \"OpenAI API key is required\"),\n\tOPENAI_BASE_URL: z.string().url().optional(),\n\tOPENAI_SMALL_MODEL: z.string().optional(),\n\tOPENAI_LARGE_MODEL: z.string().optional(),\n\tSMALL_MODEL: z.string().optional(),\n\tLARGE_MODEL: z.string().optional(),\n});\n\nexport const openaiPlugin: Plugin = {\n\tname: \"openai\",\n\tdescription: \"OpenAI plugin\",\n\tconfig: {\n\t\tOPENAI_API_KEY: process.env.OPENAI_API_KEY,\n\t\tOPENAI_BASE_URL: process.env.OPENAI_BASE_URL,\n\t\tOPENAI_SMALL_MODEL: process.env.OPENAI_SMALL_MODEL,\n\t\tOPENAI_LARGE_MODEL: process.env.OPENAI_LARGE_MODEL,\n\t\tSMALL_MODEL: process.env.SMALL_MODEL,\n\t\tLARGE_MODEL: process.env.LARGE_MODEL,\n\t},\n\tasync init(config: Record<string, string>) {\n\t\ttry {\n\t\t\tconst validatedConfig = await configSchema.parseAsync(config);\n\n\t\t\t// Set all environment variables at once\n\t\t\tfor (const [key, value] of Object.entries(validatedConfig)) {\n\t\t\t\tif (value) process.env[key] = value;\n\t\t\t}\n\n\t\t\t// Verify API key\n\t\t\tconst baseURL =\n\t\t\t\tprocess.env.OPENAI_BASE_URL ?? \"https://api.openai.com/v1\";\n\t\t\tconst response = await fetch(`${baseURL}/models`, {\n\t\t\t\theaders: { Authorization: `Bearer ${process.env.OPENAI_API_KEY}` },\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to validate OpenAI API key: ${response.statusText}`,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (error instanceof z.ZodError) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid plugin configuration: ${error.errors\n\t\t\t\t\t\t.map((e) => e.message)\n\t\t\t\t\t\t.join(\n\t\t\t\t\t\t\t\", \",\n\t\t\t\t\t\t)} - You need to configure the OPENAI_API_KEY in your environment variables`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t},\n\tmodels: {\n\t\t[ModelTypes.TEXT_EMBEDDING]: async (\n\t\t\t_runtime: IAgentRuntime,\n\t\t\ttext: string | null,\n\t\t) => {\n\t\t\tif (!text) {\n\t\t\t\t// Return zero vector of appropriate length for model\n\t\t\t\treturn new Array(1536).fill(0);\n\t\t\t}\n\n\t\t\tconst baseURL =\n\t\t\t\tprocess.env.OPENAI_BASE_URL ?? \"https://api.openai.com/v1\";\n\n\t\t\t// use fetch to call embedding endpoint\n\t\t\tconst response = await fetch(`${baseURL}/embeddings`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${process.env.OPENAI_API_KEY}`,\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tmodel: \"text-embedding-3-small\",\n\t\t\t\t\tinput: text,\n\t\t\t\t}),\n\t\t\t});\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`Failed to get embedding: ${response.statusText}`);\n\t\t\t}\n\n\t\t\tconst data = (await response.json()) as {\n\t\t\t\tdata: [{ embedding: number[] }];\n\t\t\t};\n\t\t\treturn data.data[0].embedding;\n\t\t},\n\t\t[ModelTypes.TEXT_TOKENIZER_ENCODE]: async (\n\t\t\t_runtime,\n\t\t\t{ prompt, modelType = ModelTypes.TEXT_LARGE }: TokenizeTextParams,\n\t\t) => {\n\t\t\treturn await tokenizeText(modelType ?? ModelTypes.TEXT_LARGE, prompt);\n\t\t},\n\t\t[ModelTypes.TEXT_TOKENIZER_DECODE]: async (\n\t\t\t_runtime,\n\t\t\t{ tokens, modelType = ModelTypes.TEXT_LARGE }: DetokenizeTextParams,\n\t\t) => {\n\t\t\treturn await detokenizeText(modelType ?? ModelTypes.TEXT_LARGE, tokens);\n\t\t},\n\t\t[ModelTypes.TEXT_SMALL]: async (\n\t\t\truntime,\n\t\t\t{ prompt, stopSequences = [] }: GenerateTextParams,\n\t\t) => {\n\t\t\tconst temperature = 0.7;\n\t\t\tconst frequency_penalty = 0.7;\n\t\t\tconst presence_penalty = 0.7;\n\t\t\tconst max_response_length = 8192;\n\n\t\t\tconst baseURL =\n\t\t\t\truntime.getSetting(\"OPENAI_BASE_URL\") ?? \"https://api.openai.com/v1\";\n\n\t\t\tconst openai = createOpenAI({\n\t\t\t\tapiKey: runtime.getSetting(\"OPENAI_API_KEY\"),\n\t\t\t\tbaseURL,\n\t\t\t});\n\n\t\t\tconst model =\n\t\t\t\truntime.getSetting(\"OPENAI_SMALL_MODEL\") ??\n\t\t\t\truntime.getSetting(\"SMALL_MODEL\") ??\n\t\t\t\t\"gpt-4o-mini\";\n\n\t\t\tconsole.log(\"generating text\");\n\t\t\tconsole.log(prompt);\n\n\t\t\tconst { text: openaiResponse } = await generateText({\n\t\t\t\tmodel: openai.languageModel(model),\n\t\t\t\tprompt: prompt,\n\t\t\t\tsystem: runtime.character.system ?? undefined,\n\t\t\t\ttemperature: temperature,\n\t\t\t\tmaxTokens: max_response_length,\n\t\t\t\tfrequencyPenalty: frequency_penalty,\n\t\t\t\tpresencePenalty: presence_penalty,\n\t\t\t\tstopSequences: stopSequences,\n\t\t\t});\n\n\t\t\treturn openaiResponse;\n\t\t},\n\t\t[ModelTypes.TEXT_LARGE]: async (\n\t\t\truntime,\n\t\t\t{\n\t\t\t\tprompt,\n\t\t\t\tstopSequences = [],\n\t\t\t\tmaxTokens = 8192,\n\t\t\t\ttemperature = 0.7,\n\t\t\t\tfrequencyPenalty = 0.7,\n\t\t\t\tpresencePenalty = 0.7,\n\t\t\t}: GenerateTextParams,\n\t\t) => {\n\t\t\tconst baseURL =\n\t\t\t\truntime.getSetting(\"OPENAI_BASE_URL\") ?? \"https://api.openai.com/v1\";\n\n\t\t\tconst openai = createOpenAI({\n\t\t\t\tapiKey: runtime.getSetting(\"OPENAI_API_KEY\"),\n\t\t\t\tbaseURL,\n\t\t\t});\n\n\t\t\tconst model =\n\t\t\t\truntime.getSetting(\"OPENAI_LARGE_MODEL\") ??\n\t\t\t\truntime.getSetting(\"LARGE_MODEL\") ??\n\t\t\t\t\"gpt-4o\";\n\n\t\t\tconst { text: openaiResponse } = await generateText({\n\t\t\t\tmodel: openai.languageModel(model),\n\t\t\t\tprompt: prompt,\n\t\t\t\tsystem: runtime.character.system ?? undefined,\n\t\t\t\ttemperature: temperature,\n\t\t\t\tmaxTokens: maxTokens,\n\t\t\t\tfrequencyPenalty: frequencyPenalty,\n\t\t\t\tpresencePenalty: presencePenalty,\n\t\t\t\tstopSequences: stopSequences,\n\t\t\t});\n\n\t\t\treturn openaiResponse;\n\t\t},\n\t\t[ModelTypes.IMAGE]: async (\n\t\t\truntime,\n\t\t\tparams: {\n\t\t\t\tprompt: string;\n\t\t\t\tn?: number;\n\t\t\t\tsize?: string;\n\t\t\t},\n\t\t) => {\n\t\t\tconst baseURL =\n\t\t\t\truntime.getSetting(\"OPENAI_BASE_URL\") ?? \"https://api.openai.com/v1\";\n\t\t\tconst response = await fetch(`${baseURL}/images/generations`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${runtime.getSetting(\"OPENAI_API_KEY\")}`,\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tprompt: params.prompt,\n\t\t\t\t\tn: params.n || 1,\n\t\t\t\t\tsize: params.size || \"1024x1024\",\n\t\t\t\t}),\n\t\t\t});\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`Failed to generate image: ${response.statusText}`);\n\t\t\t}\n\t\t\tconst data = await response.json();\n\t\t\tconst typedData = data as { data: { url: string }[] };\n\t\t\treturn typedData.data;\n\t\t},\n\t\t[ModelTypes.IMAGE_DESCRIPTION]: async (runtime, imageUrl) => {\n\t\t\tconsole.log(\"IMAGE_DESCRIPTION\");\n\t\t\tconst baseURL =\n\t\t\t\truntime.getSetting(\"OPENAI_BASE_URL\") ?? \"https://api.openai.com/v1\";\n\t\t\tconsole.log(\"baseURL\", baseURL);\n\t\t\tconst openai = createOpenAI({\n\t\t\t\tapiKey: runtime.getSetting(\"OPENAI_API_KEY\"),\n\t\t\t\tbaseURL,\n\t\t\t});\n\n\t\t\tconst { text } = await generateText({\n\t\t\t\tmodel: openai.languageModel(\n\t\t\t\t\truntime.getSetting(\"OPENAI_SMALL_MODEL\") ?? \"gpt-4o-mini\",\n\t\t\t\t),\n\t\t\t\tmessages: [\n\t\t\t\t\t{\n\t\t\t\t\t\trole: \"system\",\n\t\t\t\t\t\tcontent:\n\t\t\t\t\t\t\t\"Provide a title and brief description of the image. Structure this as XML with the following syntax:\\n<title>{{title}}</title>\\n<description>{{description}}</description>\\nReplacing the handlerbars with the actual text\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"image\" as const,\n\t\t\t\t\t\t\t\timage: imageUrl,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\ttemperature: 0.7,\n\t\t\t\tmaxTokens: 1024,\n\t\t\t\tfrequencyPenalty: 0,\n\t\t\t\tpresencePenalty: 0,\n\t\t\t\tstopSequences: [],\n\t\t\t});\n\n\t\t\tconst titleMatch = text.match(/<title>(.*?)<\\/title>/);\n\t\t\tconst descriptionMatch = text.match(/<description>(.*?)<\\/description>/);\n\n\t\t\tif (!titleMatch || !descriptionMatch) {\n\t\t\t\tthrow new Error(\"Could not parse title or description from response\");\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ttitle: titleMatch[1],\n\t\t\t\tdescription: descriptionMatch[1],\n\t\t\t};\n\t\t},\n\t\t[ModelTypes.TRANSCRIPTION]: async (runtime, audioBuffer: Buffer) => {\n\t\t\tconsole.log(\"audioBuffer\", audioBuffer);\n\t\t\tconst baseURL =\n\t\t\t\truntime.getSetting(\"OPENAI_BASE_URL\") ?? \"https://api.openai.com/v1\";\n\t\t\tconst formData = new FormData();\n\t\t\tformData.append(\"file\", new Blob([audioBuffer], { type: \"audio/mp3\" }));\n\t\t\tformData.append(\"model\", \"whisper-1\");\n\t\t\tconst response = await fetch(`${baseURL}/audio/transcriptions`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${runtime.getSetting(\"OPENAI_API_KEY\")}`,\n\t\t\t\t\t// Note: Do not set a Content-Type header—letting fetch set it for FormData is best\n\t\t\t\t},\n\t\t\t\tbody: formData,\n\t\t\t});\n\n\t\t\tconsole.log(\"response\", response);\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`Failed to transcribe audio: ${response.statusText}`);\n\t\t\t}\n\t\t\tconst data = (await response.json()) as { text: string };\n\t\t\treturn data.text;\n\t\t},\n\t},\n\ttests: [\n\t\t{\n\t\t\tname: \"openai_plugin_tests\",\n\t\t\ttests: [\n\t\t\t\t{\n\t\t\t\t\tname: \"openai_test_url_and_api_key_validation\",\n\t\t\t\t\tfn: async (runtime) => {\n\t\t\t\t\t\tconst baseURL =\n\t\t\t\t\t\t\truntime.getSetting(\"OPENAI_BASE_URL\") ??\n\t\t\t\t\t\t\t\"https://api.openai.com/v1\";\n\t\t\t\t\t\tconst response = await fetch(`${baseURL}/models`, {\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\tAuthorization: `Bearer ${runtime.getSetting(\"OPENAI_API_KEY\")}`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst data = await response.json();\n\t\t\t\t\t\tconsole.log(\"Models Available:\", (data as any)?.data.length);\n\t\t\t\t\t\tif (!response.ok) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Failed to validate OpenAI API key: ${response.statusText}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"openai_test_text_embedding\",\n\t\t\t\t\tfn: async (runtime) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst embedding = await runtime.useModel(\n\t\t\t\t\t\t\t\tModelTypes.TEXT_EMBEDDING,\n\t\t\t\t\t\t\t\t\"Hello, world!\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconsole.log(\"embedding\", embedding);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tconsole.error(\"Error in test_text_embedding:\", error);\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"openai_test_text_large\",\n\t\t\t\t\tfn: async (runtime) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst text = await runtime.useModel(ModelTypes.TEXT_LARGE, {\n\t\t\t\t\t\t\t\tprompt: \"What is the nature of reality in 10 words?\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (text.length === 0) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Failed to generate text\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconsole.log(\"generated with test_text_large:\", text);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tconsole.error(\"Error in test_text_large:\", error);\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"openai_test_text_small\",\n\t\t\t\t\tfn: async (runtime) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst text = await runtime.useModel(ModelTypes.TEXT_SMALL, {\n\t\t\t\t\t\t\t\tprompt: \"What is the nature of reality in 10 words?\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (text.length === 0) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Failed to generate text\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconsole.log(\"generated with test_text_small:\", text);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tconsole.error(\"Error in test_text_small:\", error);\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"openai_test_image_generation\",\n\t\t\t\t\tfn: async (runtime) => {\n\t\t\t\t\t\tconsole.log(\"openai_test_image_generation\");\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst image = await runtime.useModel(ModelTypes.IMAGE, {\n\t\t\t\t\t\t\t\tprompt: \"A beautiful sunset over a calm ocean\",\n\t\t\t\t\t\t\t\tn: 1,\n\t\t\t\t\t\t\t\tsize: \"1024x1024\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tconsole.log(\"generated with test_image_generation:\", image);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tconsole.error(\"Error in test_image_generation:\", error);\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"openai_test_image_description\",\n\t\t\t\t\tfn: async (runtime) => {\n\t\t\t\t\t\tconsole.log(\"openai_test_image_description\");\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst { title, description } = await runtime.useModel(\n\t\t\t\t\t\t\t\tModelTypes.IMAGE_DESCRIPTION,\n\t\t\t\t\t\t\t\t\"https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Vitalik_Buterin_TechCrunch_London_2015_%28cropped%29.jpg/537px-Vitalik_Buterin_TechCrunch_London_2015_%28cropped%29.jpg\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t\"generated with test_image_description:\",\n\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tconsole.error(\"Error in test_image_description:\", error);\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"openai_test_transcription\",\n\t\t\t\t\tfn: async (runtime) => {\n\t\t\t\t\t\tconsole.log(\"openai_test_transcription\");\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst response = await fetch(\n\t\t\t\t\t\t\t\t\"https://upload.wikimedia.org/wikipedia/en/4/40/Chris_Benoit_Voice_Message.ogg\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconst arrayBuffer = await response.arrayBuffer();\n\t\t\t\t\t\t\tconst transcription = await runtime.useModel(\n\t\t\t\t\t\t\t\tModelTypes.TRANSCRIPTION,\n\t\t\t\t\t\t\t\tBuffer.from(new Uint8Array(arrayBuffer)),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconsole.log(\"generated with test_transcription:\", transcription);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tconsole.error(\"Error in test_transcription:\", error);\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"openai_test_text_tokenizer_encode\",\n\t\t\t\t\tfn: async (runtime) => {\n\t\t\t\t\t\tconst prompt = \"Hello tokenizer encode!\";\n\t\t\t\t\t\tconst tokens = await runtime.useModel(\n\t\t\t\t\t\t\tModelTypes.TEXT_TOKENIZER_ENCODE,\n\t\t\t\t\t\t\t{ prompt },\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (!Array.isArray(tokens) || tokens.length === 0) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\"Failed to tokenize text: expected non-empty array of tokens\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconsole.log(\"Tokenized output:\", tokens);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"openai_test_text_tokenizer_decode\",\n\t\t\t\t\tfn: async (runtime) => {\n\t\t\t\t\t\tconst prompt = \"Hello tokenizer decode!\";\n\t\t\t\t\t\t// Encode the string into tokens first\n\t\t\t\t\t\tconst tokens = await runtime.useModel(\n\t\t\t\t\t\t\tModelTypes.TEXT_TOKENIZER_ENCODE,\n\t\t\t\t\t\t\t{ prompt },\n\t\t\t\t\t\t);\n\t\t\t\t\t\t// Now decode tokens back into text\n\t\t\t\t\t\tconst decodedText = await runtime.useModel(\n\t\t\t\t\t\t\tModelTypes.TEXT_TOKENIZER_DECODE,\n\t\t\t\t\t\t\t{ tokens },\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (decodedText !== prompt) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Decoded text does not match original. Expected \"${prompt}\", got \"${decodedText}\"`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconsole.log(\"Decoded text:\", decodedText);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t],\n};\nexport default openaiPlugin;\n"],"mappings":";AAAA,SAAS,oBAAoB;AAE7B;AAAA,EAGC;AAAA,OAEM;AACP,SAAS,oBAAoB;AAC7B,SAAS,wBAA4C;AACrD,SAAS,SAAS;AAElB,eAAe,aAAa,OAAkB,QAAgB;AAC7D,QAAM,YACL,UAAU,WAAW,aACjB,QAAQ,IAAI,sBACd,QAAQ,IAAI,eACZ,gBACE,QAAQ,IAAI,eAAe;AAChC,QAAM,WAAW,iBAAiB,SAA0B;AAC5D,QAAM,SAAS,SAAS,OAAO,MAAM;AACrC,SAAO;AACR;AAEA,eAAe,eAAe,OAAkB,QAAkB;AACjE,QAAM,YACL,UAAU,WAAW,aACjB,QAAQ,IAAI,sBACd,QAAQ,IAAI,eACZ,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;AACtB,kBAAM,SAAS;AACf,kBAAM,SAAS,MAAM,QAAQ;AAAA,cAC5B,WAAW;AAAA,cACX,EAAE,OAAO;AAAA,YACV;AACA,gBAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,OAAO,WAAW,GAAG;AAClD,oBAAM,IAAI;AAAA,gBACT;AAAA,cACD;AAAA,YACD;AACA,oBAAQ,IAAI,qBAAqB,MAAM;AAAA,UACxC;AAAA,QACD;AAAA,QACA;AAAA,UACC,MAAM;AAAA,UACN,IAAI,OAAO,YAAY;AACtB,kBAAM,SAAS;AAEf,kBAAM,SAAS,MAAM,QAAQ;AAAA,cAC5B,WAAW;AAAA,cACX,EAAE,OAAO;AAAA,YACV;AAEA,kBAAM,cAAc,MAAM,QAAQ;AAAA,cACjC,WAAW;AAAA,cACX,EAAE,OAAO;AAAA,YACV;AACA,gBAAI,gBAAgB,QAAQ;AAC3B,oBAAM,IAAI;AAAA,gBACT,mDAAmD,MAAM,WAAW,WAAW;AAAA,cAChF;AAAA,YACD;AACA,oBAAQ,IAAI,iBAAiB,WAAW;AAAA,UACzC;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;AACA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,37 +1,53 @@
1
1
  {
2
- "name": "@elizaos/plugin-openai",
3
- "version": "0.25.6-alpha.1",
4
- "type": "module",
5
- "main": "dist/index.js",
6
- "module": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "exports": {
9
- "./package.json": "./package.json",
10
- ".": {
11
- "import": {
12
- "@elizaos/source": "./src/index.ts",
13
- "types": "./dist/index.d.ts",
14
- "default": "./dist/index.js"
15
- }
16
- }
17
- },
18
- "files": [
19
- "dist"
20
- ],
21
- "dependencies": {
22
- "@elizaos/core": "0.25.6-alpha.1",
23
- "axios": "^1.0.0"
24
- },
25
- "devDependencies": {
26
- "tsup": "8.3.5",
27
- "vitest": "^3.0.0"
28
- },
29
- "scripts": {
30
- "build": "tsup src/index.ts --format esm --dts --tsconfig ./tsconfig.json",
31
- "dev": "tsup src/index.ts --format esm --dts --watch --tsconfig ./tsconfig.json"
32
- },
33
- "publishConfig": {
34
- "access": "public"
35
- },
36
- "gitHead": "81a35281b93d5e8ca0745e9d13a1943e9a90681b"
2
+ "name": "@elizaos/plugin-openai",
3
+ "version": "1.0.0-alpha.1",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "dependencies": {
21
+ "@ai-sdk/openai": "^1.1.9",
22
+ "@ai-sdk/ui-utils": "1.1.9",
23
+ "@elizaos/core": "^1.0.0-alpha.1",
24
+ "ai": "^4.1.25",
25
+ "js-tiktoken": "^1.0.18",
26
+ "tsup": "8.4.0",
27
+ "zod": "3.21.4"
28
+ },
29
+ "scripts": {
30
+ "build": "tsup --format esm --dts",
31
+ "dev": "tsup --format esm --dts --watch",
32
+ "test": "vitest run"
33
+ },
34
+ "peerDependencies": {
35
+ "whatwg-url": "7.1.0"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "resolutions": {
41
+ "zod": "3.24.1"
42
+ },
43
+ "agentConfig": {
44
+ "pluginType": "elizaos:plugin:1.0.0",
45
+ "pluginParameters": {
46
+ "OPENAI_API_KEY": {
47
+ "type": "string",
48
+ "description": "API key for the service"
49
+ }
50
+ }
51
+ },
52
+ "gitHead": "6a2982a05074c2ddc0c76684ce373b6deec27e56"
37
53
  }