@elizaos/plugin-openai 1.0.0-alpha.6 → 1.0.0-alpha.60
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/dist/index.js +272 -137
- package/dist/index.js.map +1 -1
- package/package.json +12 -14
- package/dist/index.d.ts +0 -5
package/dist/index.js
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { createOpenAI } from "@ai-sdk/openai";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
ModelType,
|
|
5
|
+
logger
|
|
5
6
|
} from "@elizaos/core";
|
|
6
|
-
import { generateText } from "ai";
|
|
7
|
+
import { generateObject, generateText } from "ai";
|
|
7
8
|
import { encodingForModel } from "js-tiktoken";
|
|
8
9
|
import { z } from "zod";
|
|
9
10
|
async function tokenizeText(model, prompt) {
|
|
10
|
-
const modelName = model ===
|
|
11
|
+
const modelName = model === ModelType.TEXT_SMALL ? process.env.OPENAI_SMALL_MODEL ?? process.env.SMALL_MODEL ?? "gpt-4o-mini" : process.env.LARGE_MODEL ?? "gpt-4o";
|
|
11
12
|
const encoding = encodingForModel(modelName);
|
|
12
13
|
const tokens = encoding.encode(prompt);
|
|
13
14
|
return tokens;
|
|
14
15
|
}
|
|
15
16
|
async function detokenizeText(model, tokens) {
|
|
16
|
-
const modelName = model ===
|
|
17
|
+
const modelName = model === ModelType.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
18
|
const encoding = encodingForModel(modelName);
|
|
18
19
|
return encoding.decode(tokens);
|
|
19
20
|
}
|
|
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
21
|
var openaiPlugin = {
|
|
29
22
|
name: "openai",
|
|
30
23
|
description: "OpenAI plugin",
|
|
@@ -38,60 +31,110 @@ var openaiPlugin = {
|
|
|
38
31
|
},
|
|
39
32
|
async init(config) {
|
|
40
33
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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}`
|
|
34
|
+
if (!process.env.OPENAI_API_KEY) {
|
|
35
|
+
logger.warn(
|
|
36
|
+
"OPENAI_API_KEY is not set in environment - OpenAI functionality will be limited"
|
|
52
37
|
);
|
|
38
|
+
return;
|
|
53
39
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
40
|
+
try {
|
|
41
|
+
const baseURL = process.env.OPENAI_BASE_URL ?? "https://api.openai.com/v1";
|
|
42
|
+
const response = await fetch(`${baseURL}/models`, {
|
|
43
|
+
headers: { Authorization: `Bearer ${process.env.OPENAI_API_KEY}` }
|
|
44
|
+
});
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
logger.warn(
|
|
47
|
+
`OpenAI API key validation failed: ${response.statusText}`
|
|
48
|
+
);
|
|
49
|
+
logger.warn(
|
|
50
|
+
"OpenAI functionality will be limited until a valid API key is provided"
|
|
51
|
+
);
|
|
52
|
+
} else {
|
|
53
|
+
}
|
|
54
|
+
} catch (fetchError) {
|
|
55
|
+
logger.warn(`Error validating OpenAI API key: ${fetchError}`);
|
|
56
|
+
logger.warn(
|
|
57
|
+
"OpenAI functionality will be limited until a valid API key is provided"
|
|
60
58
|
);
|
|
61
59
|
}
|
|
62
|
-
|
|
60
|
+
} catch (error) {
|
|
61
|
+
logger.warn(
|
|
62
|
+
`OpenAI plugin configuration issue: ${error.errors.map((e) => e.message).join(
|
|
63
|
+
", "
|
|
64
|
+
)} - You need to configure the OPENAI_API_KEY in your environment variables`
|
|
65
|
+
);
|
|
63
66
|
}
|
|
64
67
|
},
|
|
65
68
|
models: {
|
|
66
|
-
[
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
+
[ModelType.TEXT_EMBEDDING]: async (runtime, params) => {
|
|
70
|
+
if (params === null) {
|
|
71
|
+
logger.debug("Creating test embedding for initialization");
|
|
72
|
+
const testVector = Array(1536).fill(0);
|
|
73
|
+
testVector[0] = 0.1;
|
|
74
|
+
return testVector;
|
|
69
75
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
let text;
|
|
77
|
+
if (typeof params === "string") {
|
|
78
|
+
text = params;
|
|
79
|
+
} else if (typeof params === "object" && params.text) {
|
|
80
|
+
text = params.text;
|
|
81
|
+
} else {
|
|
82
|
+
logger.warn("Invalid input format for embedding");
|
|
83
|
+
const fallbackVector = Array(1536).fill(0);
|
|
84
|
+
fallbackVector[0] = 0.2;
|
|
85
|
+
return fallbackVector;
|
|
86
|
+
}
|
|
87
|
+
if (!text.trim()) {
|
|
88
|
+
logger.warn("Empty text for embedding");
|
|
89
|
+
const emptyVector = Array(1536).fill(0);
|
|
90
|
+
emptyVector[0] = 0.3;
|
|
91
|
+
return emptyVector;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const baseURL = process.env.OPENAI_BASE_URL ?? "https://api.openai.com/v1";
|
|
95
|
+
const response = await fetch(`${baseURL}/embeddings`, {
|
|
96
|
+
method: "POST",
|
|
97
|
+
headers: {
|
|
98
|
+
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
|
|
99
|
+
"Content-Type": "application/json"
|
|
100
|
+
},
|
|
101
|
+
body: JSON.stringify({
|
|
102
|
+
model: "text-embedding-3-small",
|
|
103
|
+
input: text
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
if (!response.ok) {
|
|
107
|
+
logger.error(
|
|
108
|
+
`OpenAI API error: ${response.status} - ${response.statusText}`
|
|
109
|
+
);
|
|
110
|
+
const errorVector = Array(1536).fill(0);
|
|
111
|
+
errorVector[0] = 0.4;
|
|
112
|
+
return errorVector;
|
|
113
|
+
}
|
|
114
|
+
const data = await response.json();
|
|
115
|
+
if (!data?.data?.[0]?.embedding) {
|
|
116
|
+
logger.error("API returned invalid structure");
|
|
117
|
+
const errorVector = Array(1536).fill(0);
|
|
118
|
+
errorVector[0] = 0.5;
|
|
119
|
+
return errorVector;
|
|
120
|
+
}
|
|
121
|
+
const embedding = data.data[0].embedding;
|
|
122
|
+
logger.log(`Got valid embedding with length ${embedding.length}`);
|
|
123
|
+
return embedding;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
logger.error("Error generating embedding:", error);
|
|
126
|
+
const errorVector = Array(1536).fill(0);
|
|
127
|
+
errorVector[0] = 0.6;
|
|
128
|
+
return errorVector;
|
|
84
129
|
}
|
|
85
|
-
const data = await response.json();
|
|
86
|
-
return data.data[0].embedding;
|
|
87
130
|
},
|
|
88
|
-
[
|
|
89
|
-
return await tokenizeText(modelType ??
|
|
131
|
+
[ModelType.TEXT_TOKENIZER_ENCODE]: async (_runtime, { prompt, modelType = ModelType.TEXT_LARGE }) => {
|
|
132
|
+
return await tokenizeText(modelType ?? ModelType.TEXT_LARGE, prompt);
|
|
90
133
|
},
|
|
91
|
-
[
|
|
92
|
-
return await detokenizeText(modelType ??
|
|
134
|
+
[ModelType.TEXT_TOKENIZER_DECODE]: async (_runtime, { tokens, modelType = ModelType.TEXT_LARGE }) => {
|
|
135
|
+
return await detokenizeText(modelType ?? ModelType.TEXT_LARGE, tokens);
|
|
93
136
|
},
|
|
94
|
-
[
|
|
137
|
+
[ModelType.TEXT_SMALL]: async (runtime, { prompt, stopSequences = [] }) => {
|
|
95
138
|
const temperature = 0.7;
|
|
96
139
|
const frequency_penalty = 0.7;
|
|
97
140
|
const presence_penalty = 0.7;
|
|
@@ -102,8 +145,8 @@ var openaiPlugin = {
|
|
|
102
145
|
baseURL
|
|
103
146
|
});
|
|
104
147
|
const model = runtime.getSetting("OPENAI_SMALL_MODEL") ?? runtime.getSetting("SMALL_MODEL") ?? "gpt-4o-mini";
|
|
105
|
-
|
|
106
|
-
|
|
148
|
+
logger.log("generating text");
|
|
149
|
+
logger.log(prompt);
|
|
107
150
|
const { text: openaiResponse } = await generateText({
|
|
108
151
|
model: openai.languageModel(model),
|
|
109
152
|
prompt,
|
|
@@ -116,7 +159,7 @@ var openaiPlugin = {
|
|
|
116
159
|
});
|
|
117
160
|
return openaiResponse;
|
|
118
161
|
},
|
|
119
|
-
[
|
|
162
|
+
[ModelType.TEXT_LARGE]: async (runtime, {
|
|
120
163
|
prompt,
|
|
121
164
|
stopSequences = [],
|
|
122
165
|
maxTokens = 8192,
|
|
@@ -142,7 +185,7 @@ var openaiPlugin = {
|
|
|
142
185
|
});
|
|
143
186
|
return openaiResponse;
|
|
144
187
|
},
|
|
145
|
-
[
|
|
188
|
+
[ModelType.IMAGE]: async (runtime, params) => {
|
|
146
189
|
const baseURL = runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
|
|
147
190
|
const response = await fetch(`${baseURL}/images/generations`, {
|
|
148
191
|
method: "POST",
|
|
@@ -163,51 +206,77 @@ var openaiPlugin = {
|
|
|
163
206
|
const typedData = data;
|
|
164
207
|
return typedData.data;
|
|
165
208
|
},
|
|
166
|
-
[
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
209
|
+
[ModelType.IMAGE_DESCRIPTION]: async (runtime, params) => {
|
|
210
|
+
let imageUrl;
|
|
211
|
+
let prompt;
|
|
212
|
+
if (typeof params === "string") {
|
|
213
|
+
imageUrl = params;
|
|
214
|
+
prompt = void 0;
|
|
215
|
+
} else {
|
|
216
|
+
imageUrl = params.imageUrl;
|
|
217
|
+
prompt = params.prompt;
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
const baseURL = process.env.OPENAI_BASE_URL ?? "https://api.openai.com/v1";
|
|
221
|
+
const apiKey = process.env.OPENAI_API_KEY;
|
|
222
|
+
if (!apiKey) {
|
|
223
|
+
logger.error("OpenAI API key not set");
|
|
224
|
+
return {
|
|
225
|
+
title: "Failed to analyze image",
|
|
226
|
+
description: "API key not configured"
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const response = await fetch(`${baseURL}/chat/completions`, {
|
|
230
|
+
method: "POST",
|
|
231
|
+
headers: {
|
|
232
|
+
"Content-Type": "application/json",
|
|
233
|
+
Authorization: `Bearer ${apiKey}`
|
|
182
234
|
},
|
|
183
|
-
{
|
|
184
|
-
|
|
185
|
-
|
|
235
|
+
body: JSON.stringify({
|
|
236
|
+
model: "gpt-4-vision-preview",
|
|
237
|
+
messages: [
|
|
186
238
|
{
|
|
187
|
-
|
|
188
|
-
|
|
239
|
+
role: "user",
|
|
240
|
+
content: [
|
|
241
|
+
{
|
|
242
|
+
type: "text",
|
|
243
|
+
text: prompt || "Please analyze this image and provide a title and detailed description."
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
type: "image_url",
|
|
247
|
+
image_url: { url: imageUrl }
|
|
248
|
+
}
|
|
249
|
+
]
|
|
189
250
|
}
|
|
190
|
-
]
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
251
|
+
],
|
|
252
|
+
max_tokens: 300
|
|
253
|
+
})
|
|
254
|
+
});
|
|
255
|
+
if (!response.ok) {
|
|
256
|
+
throw new Error(`OpenAI API error: ${response.status}`);
|
|
257
|
+
}
|
|
258
|
+
const result = await response.json();
|
|
259
|
+
const content = result.choices?.[0]?.message?.content;
|
|
260
|
+
if (!content) {
|
|
261
|
+
return {
|
|
262
|
+
title: "Failed to analyze image",
|
|
263
|
+
description: "No response from API"
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
const titleMatch = content.match(/title[:\s]+(.+?)(?:\n|$)/i);
|
|
267
|
+
const title = titleMatch?.[1] || "Image Analysis";
|
|
268
|
+
const description = content.replace(/title[:\s]+(.+?)(?:\n|$)/i, "").trim();
|
|
269
|
+
return { title, description };
|
|
270
|
+
} catch (error) {
|
|
271
|
+
logger.error("Error analyzing image:", error);
|
|
272
|
+
return {
|
|
273
|
+
title: "Failed to analyze image",
|
|
274
|
+
description: `Error: ${error instanceof Error ? error.message : String(error)}`
|
|
275
|
+
};
|
|
203
276
|
}
|
|
204
|
-
return {
|
|
205
|
-
title: titleMatch[1],
|
|
206
|
-
description: descriptionMatch[1]
|
|
207
|
-
};
|
|
208
277
|
},
|
|
209
|
-
[
|
|
210
|
-
|
|
278
|
+
[ModelType.TRANSCRIPTION]: async (runtime, audioBuffer) => {
|
|
279
|
+
logger.log("audioBuffer", audioBuffer);
|
|
211
280
|
const baseURL = runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
|
|
212
281
|
const formData = new FormData();
|
|
213
282
|
formData.append("file", new Blob([audioBuffer], { type: "audio/mp3" }));
|
|
@@ -220,12 +289,70 @@ var openaiPlugin = {
|
|
|
220
289
|
},
|
|
221
290
|
body: formData
|
|
222
291
|
});
|
|
223
|
-
|
|
292
|
+
logger.log("response", response);
|
|
224
293
|
if (!response.ok) {
|
|
225
294
|
throw new Error(`Failed to transcribe audio: ${response.statusText}`);
|
|
226
295
|
}
|
|
227
296
|
const data = await response.json();
|
|
228
297
|
return data.text;
|
|
298
|
+
},
|
|
299
|
+
[ModelType.OBJECT_SMALL]: async (runtime, params) => {
|
|
300
|
+
const baseURL = runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
|
|
301
|
+
const openai = createOpenAI({
|
|
302
|
+
apiKey: runtime.getSetting("OPENAI_API_KEY"),
|
|
303
|
+
baseURL
|
|
304
|
+
});
|
|
305
|
+
const model = runtime.getSetting("OPENAI_SMALL_MODEL") ?? runtime.getSetting("SMALL_MODEL") ?? "gpt-4o-mini";
|
|
306
|
+
try {
|
|
307
|
+
if (params.schema) {
|
|
308
|
+
const { object: object2 } = await generateObject({
|
|
309
|
+
model: openai.languageModel(model),
|
|
310
|
+
schema: z.object(params.schema),
|
|
311
|
+
prompt: params.prompt,
|
|
312
|
+
temperature: params.temperature
|
|
313
|
+
});
|
|
314
|
+
return object2;
|
|
315
|
+
}
|
|
316
|
+
const { object } = await generateObject({
|
|
317
|
+
model: openai.languageModel(model),
|
|
318
|
+
output: "no-schema",
|
|
319
|
+
prompt: params.prompt,
|
|
320
|
+
temperature: params.temperature
|
|
321
|
+
});
|
|
322
|
+
return object;
|
|
323
|
+
} catch (error) {
|
|
324
|
+
logger.error("Error generating object:", error);
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
[ModelType.OBJECT_LARGE]: async (runtime, params) => {
|
|
329
|
+
const baseURL = runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
|
|
330
|
+
const openai = createOpenAI({
|
|
331
|
+
apiKey: runtime.getSetting("OPENAI_API_KEY"),
|
|
332
|
+
baseURL
|
|
333
|
+
});
|
|
334
|
+
const model = runtime.getSetting("OPENAI_LARGE_MODEL") ?? runtime.getSetting("LARGE_MODEL") ?? "gpt-4o";
|
|
335
|
+
try {
|
|
336
|
+
if (params.schema) {
|
|
337
|
+
const { object: object2 } = await generateObject({
|
|
338
|
+
model: openai.languageModel(model),
|
|
339
|
+
schema: z.object(params.schema),
|
|
340
|
+
prompt: params.prompt,
|
|
341
|
+
temperature: params.temperature
|
|
342
|
+
});
|
|
343
|
+
return object2;
|
|
344
|
+
}
|
|
345
|
+
const { object } = await generateObject({
|
|
346
|
+
model: openai.languageModel(model),
|
|
347
|
+
output: "no-schema",
|
|
348
|
+
prompt: params.prompt,
|
|
349
|
+
temperature: params.temperature
|
|
350
|
+
});
|
|
351
|
+
return object;
|
|
352
|
+
} catch (error) {
|
|
353
|
+
logger.error("Error generating object:", error);
|
|
354
|
+
throw error;
|
|
355
|
+
}
|
|
229
356
|
}
|
|
230
357
|
},
|
|
231
358
|
tests: [
|
|
@@ -242,7 +369,7 @@ var openaiPlugin = {
|
|
|
242
369
|
}
|
|
243
370
|
});
|
|
244
371
|
const data = await response.json();
|
|
245
|
-
|
|
372
|
+
logger.log("Models Available:", data?.data.length);
|
|
246
373
|
if (!response.ok) {
|
|
247
374
|
throw new Error(
|
|
248
375
|
`Failed to validate OpenAI API key: ${response.statusText}`
|
|
@@ -255,12 +382,14 @@ var openaiPlugin = {
|
|
|
255
382
|
fn: async (runtime) => {
|
|
256
383
|
try {
|
|
257
384
|
const embedding = await runtime.useModel(
|
|
258
|
-
|
|
259
|
-
|
|
385
|
+
ModelType.TEXT_EMBEDDING,
|
|
386
|
+
{
|
|
387
|
+
text: "Hello, world!"
|
|
388
|
+
}
|
|
260
389
|
);
|
|
261
|
-
|
|
390
|
+
logger.log("embedding", embedding);
|
|
262
391
|
} catch (error) {
|
|
263
|
-
|
|
392
|
+
logger.error("Error in test_text_embedding:", error);
|
|
264
393
|
throw error;
|
|
265
394
|
}
|
|
266
395
|
}
|
|
@@ -269,15 +398,15 @@ var openaiPlugin = {
|
|
|
269
398
|
name: "openai_test_text_large",
|
|
270
399
|
fn: async (runtime) => {
|
|
271
400
|
try {
|
|
272
|
-
const text = await runtime.useModel(
|
|
401
|
+
const text = await runtime.useModel(ModelType.TEXT_LARGE, {
|
|
273
402
|
prompt: "What is the nature of reality in 10 words?"
|
|
274
403
|
});
|
|
275
404
|
if (text.length === 0) {
|
|
276
405
|
throw new Error("Failed to generate text");
|
|
277
406
|
}
|
|
278
|
-
|
|
407
|
+
logger.log("generated with test_text_large:", text);
|
|
279
408
|
} catch (error) {
|
|
280
|
-
|
|
409
|
+
logger.error("Error in test_text_large:", error);
|
|
281
410
|
throw error;
|
|
282
411
|
}
|
|
283
412
|
}
|
|
@@ -286,15 +415,15 @@ var openaiPlugin = {
|
|
|
286
415
|
name: "openai_test_text_small",
|
|
287
416
|
fn: async (runtime) => {
|
|
288
417
|
try {
|
|
289
|
-
const text = await runtime.useModel(
|
|
418
|
+
const text = await runtime.useModel(ModelType.TEXT_SMALL, {
|
|
290
419
|
prompt: "What is the nature of reality in 10 words?"
|
|
291
420
|
});
|
|
292
421
|
if (text.length === 0) {
|
|
293
422
|
throw new Error("Failed to generate text");
|
|
294
423
|
}
|
|
295
|
-
|
|
424
|
+
logger.log("generated with test_text_small:", text);
|
|
296
425
|
} catch (error) {
|
|
297
|
-
|
|
426
|
+
logger.error("Error in test_text_small:", error);
|
|
298
427
|
throw error;
|
|
299
428
|
}
|
|
300
429
|
}
|
|
@@ -302,56 +431,62 @@ var openaiPlugin = {
|
|
|
302
431
|
{
|
|
303
432
|
name: "openai_test_image_generation",
|
|
304
433
|
fn: async (runtime) => {
|
|
305
|
-
|
|
434
|
+
logger.log("openai_test_image_generation");
|
|
306
435
|
try {
|
|
307
|
-
const image = await runtime.useModel(
|
|
436
|
+
const image = await runtime.useModel(ModelType.IMAGE, {
|
|
308
437
|
prompt: "A beautiful sunset over a calm ocean",
|
|
309
438
|
n: 1,
|
|
310
439
|
size: "1024x1024"
|
|
311
440
|
});
|
|
312
|
-
|
|
441
|
+
logger.log("generated with test_image_generation:", image);
|
|
313
442
|
} catch (error) {
|
|
314
|
-
|
|
443
|
+
logger.error("Error in test_image_generation:", error);
|
|
315
444
|
throw error;
|
|
316
445
|
}
|
|
317
446
|
}
|
|
318
447
|
},
|
|
319
448
|
{
|
|
320
|
-
name: "
|
|
449
|
+
name: "image-description",
|
|
321
450
|
fn: async (runtime) => {
|
|
322
|
-
console.log("openai_test_image_description");
|
|
323
451
|
try {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
title
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
452
|
+
logger.log("openai_test_image_description");
|
|
453
|
+
try {
|
|
454
|
+
const result = await runtime.useModel(
|
|
455
|
+
ModelType.IMAGE_DESCRIPTION,
|
|
456
|
+
"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"
|
|
457
|
+
);
|
|
458
|
+
if (result && typeof result === "object" && "title" in result && "description" in result) {
|
|
459
|
+
logger.log("Image description:", result);
|
|
460
|
+
} else {
|
|
461
|
+
logger.error(
|
|
462
|
+
"Invalid image description result format:",
|
|
463
|
+
result
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
} catch (e) {
|
|
467
|
+
logger.error("Error in image description test:", e);
|
|
468
|
+
}
|
|
469
|
+
} catch (e) {
|
|
470
|
+
logger.error("Error in openai_test_image_description:", e);
|
|
336
471
|
}
|
|
337
472
|
}
|
|
338
473
|
},
|
|
339
474
|
{
|
|
340
475
|
name: "openai_test_transcription",
|
|
341
476
|
fn: async (runtime) => {
|
|
342
|
-
|
|
477
|
+
logger.log("openai_test_transcription");
|
|
343
478
|
try {
|
|
344
479
|
const response = await fetch(
|
|
345
480
|
"https://upload.wikimedia.org/wikipedia/en/4/40/Chris_Benoit_Voice_Message.ogg"
|
|
346
481
|
);
|
|
347
482
|
const arrayBuffer = await response.arrayBuffer();
|
|
348
483
|
const transcription = await runtime.useModel(
|
|
349
|
-
|
|
484
|
+
ModelType.TRANSCRIPTION,
|
|
350
485
|
Buffer.from(new Uint8Array(arrayBuffer))
|
|
351
486
|
);
|
|
352
|
-
|
|
487
|
+
logger.log("generated with test_transcription:", transcription);
|
|
353
488
|
} catch (error) {
|
|
354
|
-
|
|
489
|
+
logger.error("Error in test_transcription:", error);
|
|
355
490
|
throw error;
|
|
356
491
|
}
|
|
357
492
|
}
|
|
@@ -361,7 +496,7 @@ var openaiPlugin = {
|
|
|
361
496
|
fn: async (runtime) => {
|
|
362
497
|
const prompt = "Hello tokenizer encode!";
|
|
363
498
|
const tokens = await runtime.useModel(
|
|
364
|
-
|
|
499
|
+
ModelType.TEXT_TOKENIZER_ENCODE,
|
|
365
500
|
{ prompt }
|
|
366
501
|
);
|
|
367
502
|
if (!Array.isArray(tokens) || tokens.length === 0) {
|
|
@@ -369,7 +504,7 @@ var openaiPlugin = {
|
|
|
369
504
|
"Failed to tokenize text: expected non-empty array of tokens"
|
|
370
505
|
);
|
|
371
506
|
}
|
|
372
|
-
|
|
507
|
+
logger.log("Tokenized output:", tokens);
|
|
373
508
|
}
|
|
374
509
|
},
|
|
375
510
|
{
|
|
@@ -377,11 +512,11 @@ var openaiPlugin = {
|
|
|
377
512
|
fn: async (runtime) => {
|
|
378
513
|
const prompt = "Hello tokenizer decode!";
|
|
379
514
|
const tokens = await runtime.useModel(
|
|
380
|
-
|
|
515
|
+
ModelType.TEXT_TOKENIZER_ENCODE,
|
|
381
516
|
{ prompt }
|
|
382
517
|
);
|
|
383
518
|
const decodedText = await runtime.useModel(
|
|
384
|
-
|
|
519
|
+
ModelType.TEXT_TOKENIZER_DECODE,
|
|
385
520
|
{ tokens }
|
|
386
521
|
);
|
|
387
522
|
if (decodedText !== prompt) {
|
|
@@ -389,7 +524,7 @@ var openaiPlugin = {
|
|
|
389
524
|
`Decoded text does not match original. Expected "${prompt}", got "${decodedText}"`
|
|
390
525
|
);
|
|
391
526
|
}
|
|
392
|
-
|
|
527
|
+
logger.log("Decoded text:", decodedText);
|
|
393
528
|
}
|
|
394
529
|
}
|
|
395
530
|
]
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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,gBACE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B,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":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createOpenAI } from \"@ai-sdk/openai\";\nimport type {\n\tImageDescriptionParams,\n\tModelTypeName,\n\tObjectGenerationParams,\n\tPlugin,\n\tTextEmbeddingParams,\n} from \"@elizaos/core\";\nimport {\n\ttype DetokenizeTextParams,\n\ttype GenerateTextParams,\n\tModelType,\n\ttype TokenizeTextParams,\n\tlogger,\n} from \"@elizaos/core\";\nimport { generateObject, generateText } from \"ai\";\nimport { type TiktokenModel, encodingForModel } from \"js-tiktoken\";\nimport { z } from \"zod\";\n\n/**\n * Asynchronously tokenizes the given text based on the specified model and prompt.\n *\n * @param {ModelTypeName} model - The type of model to use for tokenization.\n * @param {string} prompt - The text prompt to tokenize.\n * @returns {number[]} - An array of tokens representing the encoded prompt.\n */\nasync function tokenizeText(model: ModelTypeName, prompt: string) {\n\tconst modelName =\n\t\tmodel === ModelType.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\n/**\n * Detokenize a sequence of tokens back into text using the specified model.\n *\n * @param {ModelTypeName} model - The type of model to use for detokenization.\n * @param {number[]} tokens - The sequence of tokens to detokenize.\n * @returns {string} The detokenized text.\n */\nasync function detokenizeText(model: ModelTypeName, tokens: number[]) {\n\tconst modelName =\n\t\tmodel === ModelType.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\n/**\n * Defines the OpenAI plugin with its name, description, and configuration options.\n * @type {Plugin}\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\t// const validatedConfig = await configSchema.parseAsync(config);\n\n\t\t\t// // Set all environment variables at once\n\t\t\t// for (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// If API key is not set, we'll show a warning but continue\n\t\t\tif (!process.env.OPENAI_API_KEY) {\n\t\t\t\tlogger.warn(\n\t\t\t\t\t\"OPENAI_API_KEY is not set in environment - OpenAI functionality will be limited\",\n\t\t\t\t);\n\t\t\t\t// Return early without throwing an error\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Verify API key only if we have one\n\t\t\ttry {\n\t\t\t\tconst baseURL =\n\t\t\t\t\tprocess.env.OPENAI_BASE_URL ?? \"https://api.openai.com/v1\";\n\t\t\t\tconst response = await fetch(`${baseURL}/models`, {\n\t\t\t\t\theaders: { Authorization: `Bearer ${process.env.OPENAI_API_KEY}` },\n\t\t\t\t});\n\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t`OpenAI API key validation failed: ${response.statusText}`,\n\t\t\t\t\t);\n\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t\"OpenAI functionality will be limited until a valid API key is provided\",\n\t\t\t\t\t);\n\t\t\t\t\t// Continue execution instead of throwing\n\t\t\t\t} else {\n\t\t\t\t\t// logger.log(\"OpenAI API key validated successfully\");\n\t\t\t\t}\n\t\t\t} catch (fetchError) {\n\t\t\t\tlogger.warn(`Error validating OpenAI API key: ${fetchError}`);\n\t\t\t\tlogger.warn(\n\t\t\t\t\t\"OpenAI functionality will be limited until a valid API key is provided\",\n\t\t\t\t);\n\t\t\t\t// Continue execution instead of throwing\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t\t// Convert to warning instead of error\n\t\t\t\tlogger.warn(\n\t\t\t\t\t`OpenAI plugin configuration issue: ${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}\n\t},\n\tmodels: {\n\t\t[ModelType.TEXT_EMBEDDING]: async (\n\t\t\truntime,\n\t\t\tparams: TextEmbeddingParams | string | null,\n\t\t): Promise<number[]> => {\n\t\t\t// Handle null input (initialization case)\n\t\t\tif (params === null) {\n\t\t\t\tlogger.debug(\"Creating test embedding for initialization\");\n\t\t\t\t// Return a consistent vector for null input\n\t\t\t\tconst testVector = Array(1536).fill(0);\n\t\t\t\ttestVector[0] = 0.1; // Make it non-zero\n\t\t\t\treturn testVector;\n\t\t\t}\n\n\t\t\t// Get the text from whatever format was provided\n\t\t\tlet text: string;\n\t\t\tif (typeof params === \"string\") {\n\t\t\t\ttext = params; // Direct string input\n\t\t\t} else if (typeof params === \"object\" && params.text) {\n\t\t\t\ttext = params.text; // Object with text property\n\t\t\t} else {\n\t\t\t\tlogger.warn(\"Invalid input format for embedding\");\n\t\t\t\t// Return a fallback for invalid input\n\t\t\t\tconst fallbackVector = Array(1536).fill(0);\n\t\t\t\tfallbackVector[0] = 0.2; // Different value for tracking\n\t\t\t\treturn fallbackVector;\n\t\t\t}\n\n\t\t\t// Skip API call for empty text\n\t\t\tif (!text.trim()) {\n\t\t\t\tlogger.warn(\"Empty text for embedding\");\n\t\t\t\tconst emptyVector = Array(1536).fill(0);\n\t\t\t\temptyVector[0] = 0.3; // Different value for tracking\n\t\t\t\treturn emptyVector;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst baseURL =\n\t\t\t\t\tprocess.env.OPENAI_BASE_URL ?? \"https://api.openai.com/v1\";\n\n\t\t\t\t// Call the OpenAI API\n\t\t\t\tconst response = await fetch(`${baseURL}/embeddings`, {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${process.env.OPENAI_API_KEY}`,\n\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tmodel: \"text-embedding-3-small\",\n\t\t\t\t\t\tinput: text,\n\t\t\t\t\t}),\n\t\t\t\t});\n\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t`OpenAI API error: ${response.status} - ${response.statusText}`,\n\t\t\t\t\t);\n\t\t\t\t\tconst errorVector = Array(1536).fill(0);\n\t\t\t\t\terrorVector[0] = 0.4; // Different value for tracking\n\t\t\t\t\treturn errorVector;\n\t\t\t\t}\n\n\t\t\t\tconst data = (await response.json()) as {\n\t\t\t\t\tdata: [{ embedding: number[] }];\n\t\t\t\t};\n\n\t\t\t\tif (!data?.data?.[0]?.embedding) {\n\t\t\t\t\tlogger.error(\"API returned invalid structure\");\n\t\t\t\t\tconst errorVector = Array(1536).fill(0);\n\t\t\t\t\terrorVector[0] = 0.5; // Different value for tracking\n\t\t\t\t\treturn errorVector;\n\t\t\t\t}\n\n\t\t\t\tconst embedding = data.data[0].embedding;\n\t\t\t\tlogger.log(`Got valid embedding with length ${embedding.length}`);\n\t\t\t\treturn embedding;\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(\"Error generating embedding:\", error);\n\t\t\t\tconst errorVector = Array(1536).fill(0);\n\t\t\t\terrorVector[0] = 0.6; // Different value for tracking\n\t\t\t\treturn errorVector;\n\t\t\t}\n\t\t},\n\t\t[ModelType.TEXT_TOKENIZER_ENCODE]: async (\n\t\t\t_runtime,\n\t\t\t{ prompt, modelType = ModelType.TEXT_LARGE }: TokenizeTextParams,\n\t\t) => {\n\t\t\treturn await tokenizeText(modelType ?? ModelType.TEXT_LARGE, prompt);\n\t\t},\n\t\t[ModelType.TEXT_TOKENIZER_DECODE]: async (\n\t\t\t_runtime,\n\t\t\t{ tokens, modelType = ModelType.TEXT_LARGE }: DetokenizeTextParams,\n\t\t) => {\n\t\t\treturn await detokenizeText(modelType ?? ModelType.TEXT_LARGE, tokens);\n\t\t},\n\t\t[ModelType.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\tlogger.log(\"generating text\");\n\t\t\tlogger.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[ModelType.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[ModelType.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[ModelType.IMAGE_DESCRIPTION]: async (\n\t\t\truntime,\n\t\t\tparams: ImageDescriptionParams | string,\n\t\t) => {\n\t\t\t// Handle string case (direct URL)\n\t\t\tlet imageUrl: string;\n\t\t\tlet prompt: string | undefined;\n\n\t\t\tif (typeof params === \"string\") {\n\t\t\t\timageUrl = params;\n\t\t\t\tprompt = undefined;\n\t\t\t} else {\n\t\t\t\t// Object parameter case\n\t\t\t\timageUrl = params.imageUrl;\n\t\t\t\tprompt = params.prompt;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst baseURL =\n\t\t\t\t\tprocess.env.OPENAI_BASE_URL ?? \"https://api.openai.com/v1\";\n\t\t\t\tconst apiKey = process.env.OPENAI_API_KEY;\n\n\t\t\t\tif (!apiKey) {\n\t\t\t\t\tlogger.error(\"OpenAI API key not set\");\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttitle: \"Failed to analyze image\",\n\t\t\t\t\t\tdescription: \"API key not configured\",\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// Call the GPT-4 Vision API\n\t\t\t\tconst response = await fetch(`${baseURL}/chat/completions`, {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tmodel: \"gpt-4-vision-preview\",\n\t\t\t\t\t\tmessages: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\t\t\t\t\tprompt ||\n\t\t\t\t\t\t\t\t\t\t\t\"Please analyze this image and provide a title and detailed description.\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttype: \"image_url\",\n\t\t\t\t\t\t\t\t\t\timage_url: { url: imageUrl },\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tmax_tokens: 300,\n\t\t\t\t\t}),\n\t\t\t\t});\n\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new Error(`OpenAI API error: ${response.status}`);\n\t\t\t\t}\n\n\t\t\t\tconst result: any = await response.json();\n\t\t\t\tconst content = result.choices?.[0]?.message?.content;\n\n\t\t\t\tif (!content) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttitle: \"Failed to analyze image\",\n\t\t\t\t\t\tdescription: \"No response from API\",\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// Extract title and description\n\t\t\t\tconst titleMatch = content.match(/title[:\\s]+(.+?)(?:\\n|$)/i);\n\t\t\t\tconst title = titleMatch?.[1] || \"Image Analysis\";\n\n\t\t\t\t// Rest of content is the description\n\t\t\t\tconst description = content\n\t\t\t\t\t.replace(/title[:\\s]+(.+?)(?:\\n|$)/i, \"\")\n\t\t\t\t\t.trim();\n\n\t\t\t\treturn { title, description };\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(\"Error analyzing image:\", error);\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Failed to analyze image\",\n\t\t\t\t\tdescription: `Error: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t\t[ModelType.TRANSCRIPTION]: async (runtime, audioBuffer: Buffer) => {\n\t\t\tlogger.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\tlogger.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\t[ModelType.OBJECT_SMALL]: async (runtime, params: ObjectGenerationParams) => {\n\t\t\tconst baseURL = runtime.getSetting(\"OPENAI_BASE_URL\") ?? \"https://api.openai.com/v1\";\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\t\t\tconst model = runtime.getSetting(\"OPENAI_SMALL_MODEL\") ?? runtime.getSetting(\"SMALL_MODEL\") ?? \"gpt-4o-mini\";\n\t\t\t\n\t\t\ttry {\n\t\t\t\tif (params.schema) {\n\t\t\t\t\tconst { object } = await generateObject({\n\t\t\t\t\t\tmodel: openai.languageModel(model),\n\t\t\t\t\t\tschema: z.object(params.schema),\n\t\t\t\t\t\tprompt: params.prompt,\n\t\t\t\t\t\ttemperature: params.temperature,\n\t\t\t\t\t});\n\t\t\t\t\treturn object;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tconst { object } = await generateObject({\n\t\t\t\t\tmodel: openai.languageModel(model),\n\t\t\t\t\toutput: 'no-schema',\n\t\t\t\t\tprompt: params.prompt,\n\t\t\t\t\ttemperature: params.temperature,\n\t\t\t\t});\n\t\t\t\treturn object;\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(\"Error generating object:\", error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\t[ModelType.OBJECT_LARGE]: async (runtime, params: ObjectGenerationParams) => {\n\t\t\tconst baseURL = runtime.getSetting(\"OPENAI_BASE_URL\") ?? \"https://api.openai.com/v1\";\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\t\t\tconst model = runtime.getSetting(\"OPENAI_LARGE_MODEL\") ?? runtime.getSetting(\"LARGE_MODEL\") ?? \"gpt-4o\";\n\t\t\t\n\t\t\ttry {\n\t\t\t\tif (params.schema) {\n\t\t\t\t\tconst { object } = await generateObject({\n\t\t\t\t\t\tmodel: openai.languageModel(model),\n\t\t\t\t\t\tschema: z.object(params.schema),\n\t\t\t\t\t\tprompt: params.prompt,\n\t\t\t\t\t\ttemperature: params.temperature,\n\t\t\t\t\t});\n\t\t\t\t\treturn object;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tconst { object } = await generateObject({\n\t\t\t\t\tmodel: openai.languageModel(model),\n\t\t\t\t\toutput: 'no-schema',\n\t\t\t\t\tprompt: params.prompt,\n\t\t\t\t\ttemperature: params.temperature,\n\t\t\t\t});\n\t\t\t\treturn object;\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(\"Error generating object:\", error);\n\t\t\t\tthrow error;\n\t\t\t}\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\tlogger.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\tModelType.TEXT_EMBEDDING,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttext: \"Hello, world!\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tlogger.log(\"embedding\", embedding);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tlogger.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(ModelType.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\tlogger.log(\"generated with test_text_large:\", text);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tlogger.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(ModelType.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\tlogger.log(\"generated with test_text_small:\", text);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tlogger.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\tlogger.log(\"openai_test_image_generation\");\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst image = await runtime.useModel(ModelType.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\tlogger.log(\"generated with test_image_generation:\", image);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tlogger.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: \"image-description\",\n\t\t\t\t\tfn: async (runtime) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tlogger.log(\"openai_test_image_description\");\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst result = await runtime.useModel(\n\t\t\t\t\t\t\t\t\tModelType.IMAGE_DESCRIPTION,\n\t\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\t);\n\n\t\t\t\t\t\t\t\t// Check if result has the expected structure\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tresult &&\n\t\t\t\t\t\t\t\t\ttypeof result === \"object\" &&\n\t\t\t\t\t\t\t\t\t\"title\" in result &&\n\t\t\t\t\t\t\t\t\t\"description\" in result\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tlogger.log(\"Image description:\", result);\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t\t\t\t\t\"Invalid image description result format:\",\n\t\t\t\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\tlogger.error(\"Error in image description test:\", e);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\tlogger.error(\"Error in openai_test_image_description:\", e);\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\tlogger.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\tModelType.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\tlogger.log(\"generated with test_transcription:\", transcription);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tlogger.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\tModelType.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\tlogger.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\tModelType.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\tModelType.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\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;AAAA,YACV;AACA,gBAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,OAAO,WAAW,GAAG;AAClD,oBAAM,IAAI;AAAA,gBACT;AAAA,cACD;AAAA,YACD;AACA,mBAAO,IAAI,qBAAqB,MAAM;AAAA,UACvC;AAAA,QACD;AAAA,QACA;AAAA,UACC,MAAM;AAAA,UACN,IAAI,OAAO,YAAY;AACtB,kBAAM,SAAS;AAEf,kBAAM,SAAS,MAAM,QAAQ;AAAA,cAC5B,UAAU;AAAA,cACV,EAAE,OAAO;AAAA,YACV;AAEA,kBAAM,cAAc,MAAM,QAAQ;AAAA,cACjC,UAAU;AAAA,cACV,EAAE,OAAO;AAAA,YACV;AACA,gBAAI,gBAAgB,QAAQ;AAC3B,oBAAM,IAAI;AAAA,gBACT,mDAAmD,MAAM,WAAW,WAAW;AAAA,cAChF;AAAA,YACD;AACA,mBAAO,IAAI,iBAAiB,WAAW;AAAA,UACxC;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;AACA,IAAO,gBAAQ;","names":["object"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/plugin-openai",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.60",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/elizaos-plugins/plugin-openai"
|
|
11
|
+
},
|
|
8
12
|
"exports": {
|
|
9
13
|
"./package.json": "./package.json",
|
|
10
14
|
".": {
|
|
@@ -20,26 +24,20 @@
|
|
|
20
24
|
"dependencies": {
|
|
21
25
|
"@ai-sdk/openai": "^1.1.9",
|
|
22
26
|
"@ai-sdk/ui-utils": "1.1.9",
|
|
23
|
-
"@elizaos/core": "1.0.0-alpha.
|
|
27
|
+
"@elizaos/core": "^1.0.0-alpha.60",
|
|
24
28
|
"ai": "^4.1.25",
|
|
25
29
|
"js-tiktoken": "^1.0.18",
|
|
26
|
-
"tsup": "8.4.0"
|
|
27
|
-
"zod": "3.21.4"
|
|
30
|
+
"tsup": "8.4.0"
|
|
28
31
|
},
|
|
29
32
|
"scripts": {
|
|
30
|
-
"build": "tsup
|
|
31
|
-
"dev": "tsup --
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"whatwg-url": "7.1.0"
|
|
33
|
+
"build": "tsup",
|
|
34
|
+
"dev": "tsup --watch",
|
|
35
|
+
"lint": "biome check ./src --config-path=./ --apply-unsafe && biome format ./ --config-path=./ --write",
|
|
36
|
+
"clean": "rm -rf dist .turbo node_modules .turbo-tsconfig.json tsconfig.tsbuildinfo"
|
|
36
37
|
},
|
|
37
38
|
"publishConfig": {
|
|
38
39
|
"access": "public"
|
|
39
40
|
},
|
|
40
|
-
"resolutions": {
|
|
41
|
-
"zod": "3.24.1"
|
|
42
|
-
},
|
|
43
41
|
"agentConfig": {
|
|
44
42
|
"pluginType": "elizaos:plugin:1.0.0",
|
|
45
43
|
"pluginParameters": {
|
|
@@ -49,5 +47,5 @@
|
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
},
|
|
52
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "5d49393471bc8f81c5d9852d6ed70875c70e1227"
|
|
53
51
|
}
|