@elizaos/plugin-openai 1.0.0-alpha.5 → 1.0.0-alpha.51
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 +328 -119
- 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,11 +1,11 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { createOpenAI } from "@ai-sdk/openai";
|
|
3
3
|
import {
|
|
4
|
-
ModelTypes
|
|
4
|
+
ModelTypes,
|
|
5
|
+
logger
|
|
5
6
|
} from "@elizaos/core";
|
|
6
7
|
import { generateText } from "ai";
|
|
7
8
|
import { encodingForModel } from "js-tiktoken";
|
|
8
|
-
import { z } from "zod";
|
|
9
9
|
async function tokenizeText(model, prompt) {
|
|
10
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
11
|
const encoding = encodingForModel(modelName);
|
|
@@ -17,14 +17,6 @@ async function detokenizeText(model, tokens) {
|
|
|
17
17
|
const encoding = encodingForModel(modelName);
|
|
18
18
|
return encoding.decode(tokens);
|
|
19
19
|
}
|
|
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
20
|
var openaiPlugin = {
|
|
29
21
|
name: "openai",
|
|
30
22
|
description: "OpenAI plugin",
|
|
@@ -38,52 +30,102 @@ var openaiPlugin = {
|
|
|
38
30
|
},
|
|
39
31
|
async init(config) {
|
|
40
32
|
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}`
|
|
33
|
+
if (!process.env.OPENAI_API_KEY) {
|
|
34
|
+
logger.warn(
|
|
35
|
+
"OPENAI_API_KEY is not set in environment - OpenAI functionality will be limited"
|
|
52
36
|
);
|
|
37
|
+
return;
|
|
53
38
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
39
|
+
try {
|
|
40
|
+
const baseURL = process.env.OPENAI_BASE_URL ?? "https://api.openai.com/v1";
|
|
41
|
+
const response = await fetch(`${baseURL}/models`, {
|
|
42
|
+
headers: { Authorization: `Bearer ${process.env.OPENAI_API_KEY}` }
|
|
43
|
+
});
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
logger.warn(
|
|
46
|
+
`OpenAI API key validation failed: ${response.statusText}`
|
|
47
|
+
);
|
|
48
|
+
logger.warn(
|
|
49
|
+
"OpenAI functionality will be limited until a valid API key is provided"
|
|
50
|
+
);
|
|
51
|
+
} else {
|
|
52
|
+
}
|
|
53
|
+
} catch (fetchError) {
|
|
54
|
+
logger.warn(`Error validating OpenAI API key: ${fetchError}`);
|
|
55
|
+
logger.warn(
|
|
56
|
+
"OpenAI functionality will be limited until a valid API key is provided"
|
|
60
57
|
);
|
|
61
58
|
}
|
|
62
|
-
|
|
59
|
+
} catch (error) {
|
|
60
|
+
logger.warn(
|
|
61
|
+
`OpenAI plugin configuration issue: ${error.errors.map((e) => e.message).join(
|
|
62
|
+
", "
|
|
63
|
+
)} - You need to configure the OPENAI_API_KEY in your environment variables`
|
|
64
|
+
);
|
|
63
65
|
}
|
|
64
66
|
},
|
|
65
67
|
models: {
|
|
66
|
-
[ModelTypes.TEXT_EMBEDDING]: async (
|
|
67
|
-
if (
|
|
68
|
-
|
|
68
|
+
[ModelTypes.TEXT_EMBEDDING]: async (runtime, params) => {
|
|
69
|
+
if (params === null) {
|
|
70
|
+
logger.debug("Creating test embedding for initialization");
|
|
71
|
+
const testVector = Array(1536).fill(0);
|
|
72
|
+
testVector[0] = 0.1;
|
|
73
|
+
return testVector;
|
|
69
74
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
let text;
|
|
76
|
+
if (typeof params === "string") {
|
|
77
|
+
text = params;
|
|
78
|
+
} else if (typeof params === "object" && params.text) {
|
|
79
|
+
text = params.text;
|
|
80
|
+
} else {
|
|
81
|
+
logger.warn("Invalid input format for embedding");
|
|
82
|
+
const fallbackVector = Array(1536).fill(0);
|
|
83
|
+
fallbackVector[0] = 0.2;
|
|
84
|
+
return fallbackVector;
|
|
85
|
+
}
|
|
86
|
+
if (!text.trim()) {
|
|
87
|
+
logger.warn("Empty text for embedding");
|
|
88
|
+
const emptyVector = Array(1536).fill(0);
|
|
89
|
+
emptyVector[0] = 0.3;
|
|
90
|
+
return emptyVector;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const baseURL = process.env.OPENAI_BASE_URL ?? "https://api.openai.com/v1";
|
|
94
|
+
const response = await fetch(`${baseURL}/embeddings`, {
|
|
95
|
+
method: "POST",
|
|
96
|
+
headers: {
|
|
97
|
+
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
|
|
98
|
+
"Content-Type": "application/json"
|
|
99
|
+
},
|
|
100
|
+
body: JSON.stringify({
|
|
101
|
+
model: "text-embedding-3-small",
|
|
102
|
+
input: text
|
|
103
|
+
})
|
|
104
|
+
});
|
|
105
|
+
if (!response.ok) {
|
|
106
|
+
logger.error(
|
|
107
|
+
`OpenAI API error: ${response.status} - ${response.statusText}`
|
|
108
|
+
);
|
|
109
|
+
const errorVector = Array(1536).fill(0);
|
|
110
|
+
errorVector[0] = 0.4;
|
|
111
|
+
return errorVector;
|
|
112
|
+
}
|
|
113
|
+
const data = await response.json();
|
|
114
|
+
if (!data?.data?.[0]?.embedding) {
|
|
115
|
+
logger.error("API returned invalid structure");
|
|
116
|
+
const errorVector = Array(1536).fill(0);
|
|
117
|
+
errorVector[0] = 0.5;
|
|
118
|
+
return errorVector;
|
|
119
|
+
}
|
|
120
|
+
const embedding = data.data[0].embedding;
|
|
121
|
+
logger.log(`Got valid embedding with length ${embedding.length}`);
|
|
122
|
+
return embedding;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
logger.error("Error generating embedding:", error);
|
|
125
|
+
const errorVector = Array(1536).fill(0);
|
|
126
|
+
errorVector[0] = 0.6;
|
|
127
|
+
return errorVector;
|
|
84
128
|
}
|
|
85
|
-
const data = await response.json();
|
|
86
|
-
return data.data[0].embedding;
|
|
87
129
|
},
|
|
88
130
|
[ModelTypes.TEXT_TOKENIZER_ENCODE]: async (_runtime, { prompt, modelType = ModelTypes.TEXT_LARGE }) => {
|
|
89
131
|
return await tokenizeText(modelType ?? ModelTypes.TEXT_LARGE, prompt);
|
|
@@ -102,8 +144,8 @@ var openaiPlugin = {
|
|
|
102
144
|
baseURL
|
|
103
145
|
});
|
|
104
146
|
const model = runtime.getSetting("OPENAI_SMALL_MODEL") ?? runtime.getSetting("SMALL_MODEL") ?? "gpt-4o-mini";
|
|
105
|
-
|
|
106
|
-
|
|
147
|
+
logger.log("generating text");
|
|
148
|
+
logger.log(prompt);
|
|
107
149
|
const { text: openaiResponse } = await generateText({
|
|
108
150
|
model: openai.languageModel(model),
|
|
109
151
|
prompt,
|
|
@@ -163,51 +205,77 @@ var openaiPlugin = {
|
|
|
163
205
|
const typedData = data;
|
|
164
206
|
return typedData.data;
|
|
165
207
|
},
|
|
166
|
-
[ModelTypes.IMAGE_DESCRIPTION]: async (runtime,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
208
|
+
[ModelTypes.IMAGE_DESCRIPTION]: async (runtime, params) => {
|
|
209
|
+
let imageUrl;
|
|
210
|
+
let prompt;
|
|
211
|
+
if (typeof params === "string") {
|
|
212
|
+
imageUrl = params;
|
|
213
|
+
prompt = void 0;
|
|
214
|
+
} else {
|
|
215
|
+
imageUrl = params.imageUrl;
|
|
216
|
+
prompt = params.prompt;
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
const baseURL = process.env.OPENAI_BASE_URL ?? "https://api.openai.com/v1";
|
|
220
|
+
const apiKey = process.env.OPENAI_API_KEY;
|
|
221
|
+
if (!apiKey) {
|
|
222
|
+
logger.error("OpenAI API key not set");
|
|
223
|
+
return {
|
|
224
|
+
title: "Failed to analyze image",
|
|
225
|
+
description: "API key not configured"
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
const response = await fetch(`${baseURL}/chat/completions`, {
|
|
229
|
+
method: "POST",
|
|
230
|
+
headers: {
|
|
231
|
+
"Content-Type": "application/json",
|
|
232
|
+
Authorization: `Bearer ${apiKey}`
|
|
182
233
|
},
|
|
183
|
-
{
|
|
184
|
-
|
|
185
|
-
|
|
234
|
+
body: JSON.stringify({
|
|
235
|
+
model: "gpt-4-vision-preview",
|
|
236
|
+
messages: [
|
|
186
237
|
{
|
|
187
|
-
|
|
188
|
-
|
|
238
|
+
role: "user",
|
|
239
|
+
content: [
|
|
240
|
+
{
|
|
241
|
+
type: "text",
|
|
242
|
+
text: prompt || "Please analyze this image and provide a title and detailed description."
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
type: "image_url",
|
|
246
|
+
image_url: { url: imageUrl }
|
|
247
|
+
}
|
|
248
|
+
]
|
|
189
249
|
}
|
|
190
|
-
]
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
250
|
+
],
|
|
251
|
+
max_tokens: 300
|
|
252
|
+
})
|
|
253
|
+
});
|
|
254
|
+
if (!response.ok) {
|
|
255
|
+
throw new Error(`OpenAI API error: ${response.status}`);
|
|
256
|
+
}
|
|
257
|
+
const result = await response.json();
|
|
258
|
+
const content = result.choices?.[0]?.message?.content;
|
|
259
|
+
if (!content) {
|
|
260
|
+
return {
|
|
261
|
+
title: "Failed to analyze image",
|
|
262
|
+
description: "No response from API"
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
const titleMatch = content.match(/title[:\s]+(.+?)(?:\n|$)/i);
|
|
266
|
+
const title = titleMatch?.[1] || "Image Analysis";
|
|
267
|
+
const description = content.replace(/title[:\s]+(.+?)(?:\n|$)/i, "").trim();
|
|
268
|
+
return { title, description };
|
|
269
|
+
} catch (error) {
|
|
270
|
+
logger.error("Error analyzing image:", error);
|
|
271
|
+
return {
|
|
272
|
+
title: "Failed to analyze image",
|
|
273
|
+
description: `Error: ${error instanceof Error ? error.message : String(error)}`
|
|
274
|
+
};
|
|
203
275
|
}
|
|
204
|
-
return {
|
|
205
|
-
title: titleMatch[1],
|
|
206
|
-
description: descriptionMatch[1]
|
|
207
|
-
};
|
|
208
276
|
},
|
|
209
277
|
[ModelTypes.TRANSCRIPTION]: async (runtime, audioBuffer) => {
|
|
210
|
-
|
|
278
|
+
logger.log("audioBuffer", audioBuffer);
|
|
211
279
|
const baseURL = runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
|
|
212
280
|
const formData = new FormData();
|
|
213
281
|
formData.append("file", new Blob([audioBuffer], { type: "audio/mp3" }));
|
|
@@ -220,12 +288,24 @@ var openaiPlugin = {
|
|
|
220
288
|
},
|
|
221
289
|
body: formData
|
|
222
290
|
});
|
|
223
|
-
|
|
291
|
+
logger.log("response", response);
|
|
224
292
|
if (!response.ok) {
|
|
225
293
|
throw new Error(`Failed to transcribe audio: ${response.statusText}`);
|
|
226
294
|
}
|
|
227
295
|
const data = await response.json();
|
|
228
296
|
return data.text;
|
|
297
|
+
},
|
|
298
|
+
[ModelTypes.OBJECT_SMALL]: async (runtime, params) => {
|
|
299
|
+
return await generateObject(runtime, {
|
|
300
|
+
...params,
|
|
301
|
+
modelType: ModelTypes.OBJECT_SMALL
|
|
302
|
+
});
|
|
303
|
+
},
|
|
304
|
+
[ModelTypes.OBJECT_LARGE]: async (runtime, params) => {
|
|
305
|
+
return await generateObject(runtime, {
|
|
306
|
+
...params,
|
|
307
|
+
modelType: ModelTypes.OBJECT_LARGE
|
|
308
|
+
});
|
|
229
309
|
}
|
|
230
310
|
},
|
|
231
311
|
tests: [
|
|
@@ -242,7 +322,7 @@ var openaiPlugin = {
|
|
|
242
322
|
}
|
|
243
323
|
});
|
|
244
324
|
const data = await response.json();
|
|
245
|
-
|
|
325
|
+
logger.log("Models Available:", data?.data.length);
|
|
246
326
|
if (!response.ok) {
|
|
247
327
|
throw new Error(
|
|
248
328
|
`Failed to validate OpenAI API key: ${response.statusText}`
|
|
@@ -256,11 +336,13 @@ var openaiPlugin = {
|
|
|
256
336
|
try {
|
|
257
337
|
const embedding = await runtime.useModel(
|
|
258
338
|
ModelTypes.TEXT_EMBEDDING,
|
|
259
|
-
|
|
339
|
+
{
|
|
340
|
+
text: "Hello, world!"
|
|
341
|
+
}
|
|
260
342
|
);
|
|
261
|
-
|
|
343
|
+
logger.log("embedding", embedding);
|
|
262
344
|
} catch (error) {
|
|
263
|
-
|
|
345
|
+
logger.error("Error in test_text_embedding:", error);
|
|
264
346
|
throw error;
|
|
265
347
|
}
|
|
266
348
|
}
|
|
@@ -275,9 +357,9 @@ var openaiPlugin = {
|
|
|
275
357
|
if (text.length === 0) {
|
|
276
358
|
throw new Error("Failed to generate text");
|
|
277
359
|
}
|
|
278
|
-
|
|
360
|
+
logger.log("generated with test_text_large:", text);
|
|
279
361
|
} catch (error) {
|
|
280
|
-
|
|
362
|
+
logger.error("Error in test_text_large:", error);
|
|
281
363
|
throw error;
|
|
282
364
|
}
|
|
283
365
|
}
|
|
@@ -292,9 +374,9 @@ var openaiPlugin = {
|
|
|
292
374
|
if (text.length === 0) {
|
|
293
375
|
throw new Error("Failed to generate text");
|
|
294
376
|
}
|
|
295
|
-
|
|
377
|
+
logger.log("generated with test_text_small:", text);
|
|
296
378
|
} catch (error) {
|
|
297
|
-
|
|
379
|
+
logger.error("Error in test_text_small:", error);
|
|
298
380
|
throw error;
|
|
299
381
|
}
|
|
300
382
|
}
|
|
@@ -302,44 +384,50 @@ var openaiPlugin = {
|
|
|
302
384
|
{
|
|
303
385
|
name: "openai_test_image_generation",
|
|
304
386
|
fn: async (runtime) => {
|
|
305
|
-
|
|
387
|
+
logger.log("openai_test_image_generation");
|
|
306
388
|
try {
|
|
307
389
|
const image = await runtime.useModel(ModelTypes.IMAGE, {
|
|
308
390
|
prompt: "A beautiful sunset over a calm ocean",
|
|
309
391
|
n: 1,
|
|
310
392
|
size: "1024x1024"
|
|
311
393
|
});
|
|
312
|
-
|
|
394
|
+
logger.log("generated with test_image_generation:", image);
|
|
313
395
|
} catch (error) {
|
|
314
|
-
|
|
396
|
+
logger.error("Error in test_image_generation:", error);
|
|
315
397
|
throw error;
|
|
316
398
|
}
|
|
317
399
|
}
|
|
318
400
|
},
|
|
319
401
|
{
|
|
320
|
-
name: "
|
|
402
|
+
name: "image-description",
|
|
321
403
|
fn: async (runtime) => {
|
|
322
|
-
console.log("openai_test_image_description");
|
|
323
404
|
try {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
title
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
405
|
+
logger.log("openai_test_image_description");
|
|
406
|
+
try {
|
|
407
|
+
const result = await runtime.useModel(
|
|
408
|
+
ModelTypes.IMAGE_DESCRIPTION,
|
|
409
|
+
"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"
|
|
410
|
+
);
|
|
411
|
+
if (result && typeof result === "object" && "title" in result && "description" in result) {
|
|
412
|
+
logger.log("Image description:", result);
|
|
413
|
+
} else {
|
|
414
|
+
logger.error(
|
|
415
|
+
"Invalid image description result format:",
|
|
416
|
+
result
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
} catch (e) {
|
|
420
|
+
logger.error("Error in image description test:", e);
|
|
421
|
+
}
|
|
422
|
+
} catch (e) {
|
|
423
|
+
logger.error("Error in openai_test_image_description:", e);
|
|
336
424
|
}
|
|
337
425
|
}
|
|
338
426
|
},
|
|
339
427
|
{
|
|
340
428
|
name: "openai_test_transcription",
|
|
341
429
|
fn: async (runtime) => {
|
|
342
|
-
|
|
430
|
+
logger.log("openai_test_transcription");
|
|
343
431
|
try {
|
|
344
432
|
const response = await fetch(
|
|
345
433
|
"https://upload.wikimedia.org/wikipedia/en/4/40/Chris_Benoit_Voice_Message.ogg"
|
|
@@ -349,9 +437,9 @@ var openaiPlugin = {
|
|
|
349
437
|
ModelTypes.TRANSCRIPTION,
|
|
350
438
|
Buffer.from(new Uint8Array(arrayBuffer))
|
|
351
439
|
);
|
|
352
|
-
|
|
440
|
+
logger.log("generated with test_transcription:", transcription);
|
|
353
441
|
} catch (error) {
|
|
354
|
-
|
|
442
|
+
logger.error("Error in test_transcription:", error);
|
|
355
443
|
throw error;
|
|
356
444
|
}
|
|
357
445
|
}
|
|
@@ -369,7 +457,7 @@ var openaiPlugin = {
|
|
|
369
457
|
"Failed to tokenize text: expected non-empty array of tokens"
|
|
370
458
|
);
|
|
371
459
|
}
|
|
372
|
-
|
|
460
|
+
logger.log("Tokenized output:", tokens);
|
|
373
461
|
}
|
|
374
462
|
},
|
|
375
463
|
{
|
|
@@ -389,7 +477,7 @@ var openaiPlugin = {
|
|
|
389
477
|
`Decoded text does not match original. Expected "${prompt}", got "${decodedText}"`
|
|
390
478
|
);
|
|
391
479
|
}
|
|
392
|
-
|
|
480
|
+
logger.log("Decoded text:", decodedText);
|
|
393
481
|
}
|
|
394
482
|
}
|
|
395
483
|
]
|
|
@@ -397,6 +485,127 @@ var openaiPlugin = {
|
|
|
397
485
|
]
|
|
398
486
|
};
|
|
399
487
|
var index_default = openaiPlugin;
|
|
488
|
+
async function generateObject(runtime, params) {
|
|
489
|
+
const {
|
|
490
|
+
prompt,
|
|
491
|
+
schema,
|
|
492
|
+
output = "object",
|
|
493
|
+
enumValues = [],
|
|
494
|
+
modelType = ModelTypes.OBJECT_SMALL,
|
|
495
|
+
temperature = 0.7
|
|
496
|
+
} = params;
|
|
497
|
+
const modelName = modelType === ModelTypes.OBJECT_SMALL ? process.env.OPENAI_SMALL_MODEL ?? process.env.SMALL_MODEL ?? "gpt-4o-mini" : process.env.OPENAI_LARGE_MODEL ?? process.env.LARGE_MODEL ?? "gpt-4o";
|
|
498
|
+
const baseURL = process.env.OPENAI_BASE_URL ?? "https://api.openai.com/v1";
|
|
499
|
+
if (output === "enum" && enumValues.length) {
|
|
500
|
+
try {
|
|
501
|
+
const response = await fetch(`${baseURL}/chat/completions`, {
|
|
502
|
+
method: "POST",
|
|
503
|
+
headers: {
|
|
504
|
+
"Content-Type": "application/json",
|
|
505
|
+
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`
|
|
506
|
+
},
|
|
507
|
+
body: JSON.stringify({
|
|
508
|
+
model: modelName,
|
|
509
|
+
messages: [{ role: "user", content: prompt }],
|
|
510
|
+
temperature,
|
|
511
|
+
tools: [
|
|
512
|
+
{
|
|
513
|
+
type: "function",
|
|
514
|
+
function: {
|
|
515
|
+
name: "select_value",
|
|
516
|
+
description: "Select the most appropriate value from the provided options",
|
|
517
|
+
parameters: {
|
|
518
|
+
type: "object",
|
|
519
|
+
properties: {
|
|
520
|
+
value: {
|
|
521
|
+
type: "string",
|
|
522
|
+
enum: enumValues,
|
|
523
|
+
description: "The selected value"
|
|
524
|
+
}
|
|
525
|
+
},
|
|
526
|
+
required: ["value"]
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
],
|
|
531
|
+
tool_choice: { type: "function", function: { name: "select_value" } }
|
|
532
|
+
})
|
|
533
|
+
});
|
|
534
|
+
if (!response.ok) {
|
|
535
|
+
throw new Error(`API error: ${response.status}`);
|
|
536
|
+
}
|
|
537
|
+
const result = await response.json();
|
|
538
|
+
const toolCalls = result.choices?.[0]?.message?.tool_calls;
|
|
539
|
+
if (toolCalls && toolCalls.length > 0) {
|
|
540
|
+
try {
|
|
541
|
+
const functionArgs = JSON.parse(toolCalls[0].function.arguments);
|
|
542
|
+
return functionArgs.value;
|
|
543
|
+
} catch (err) {
|
|
544
|
+
logger.error("Failed to parse function arguments:", err);
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return null;
|
|
549
|
+
} catch (error) {
|
|
550
|
+
logger.error("Error generating enum value:", error);
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
try {
|
|
555
|
+
let functionSchema;
|
|
556
|
+
if (schema) {
|
|
557
|
+
functionSchema = schema;
|
|
558
|
+
} else {
|
|
559
|
+
functionSchema = {
|
|
560
|
+
type: output === "array" ? "array" : "object",
|
|
561
|
+
...output === "array" ? { items: { type: "object" } } : {}
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
const response = await fetch(`${baseURL}/chat/completions`, {
|
|
565
|
+
method: "POST",
|
|
566
|
+
headers: {
|
|
567
|
+
"Content-Type": "application/json",
|
|
568
|
+
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`
|
|
569
|
+
},
|
|
570
|
+
body: JSON.stringify({
|
|
571
|
+
model: modelName,
|
|
572
|
+
messages: [{ role: "user", content: prompt }],
|
|
573
|
+
temperature,
|
|
574
|
+
tools: [
|
|
575
|
+
{
|
|
576
|
+
type: "function",
|
|
577
|
+
function: {
|
|
578
|
+
name: "generate_structured_data",
|
|
579
|
+
description: "Generate structured data based on the prompt",
|
|
580
|
+
parameters: functionSchema
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
],
|
|
584
|
+
tool_choice: {
|
|
585
|
+
type: "function",
|
|
586
|
+
function: { name: "generate_structured_data" }
|
|
587
|
+
}
|
|
588
|
+
})
|
|
589
|
+
});
|
|
590
|
+
if (!response.ok) {
|
|
591
|
+
throw new Error(`API error: ${response.status}`);
|
|
592
|
+
}
|
|
593
|
+
const result = await response.json();
|
|
594
|
+
const toolCalls = result.choices?.[0]?.message?.tool_calls;
|
|
595
|
+
if (toolCalls && toolCalls.length > 0) {
|
|
596
|
+
try {
|
|
597
|
+
return JSON.parse(toolCalls[0].function.arguments);
|
|
598
|
+
} catch (err) {
|
|
599
|
+
logger.error("Failed to parse function arguments:", err);
|
|
600
|
+
return null;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return null;
|
|
604
|
+
} catch (error) {
|
|
605
|
+
logger.error("Error generating object:", error);
|
|
606
|
+
return null;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
400
609
|
export {
|
|
401
610
|
index_default as default,
|
|
402
611
|
openaiPlugin
|
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,QAAQ,IAAI,sBAAsB,QAAQ,IAAI,eAAe;AAClE,QAAM,WAAW,iBAAiB,SAA0B;AAC5D,SAAO,SAAS,OAAO,MAAM;AAC9B;AAEA,IAAM,eAAe,EAAE,OAAO;AAAA,EAC7B,gBAAgB,EAAE,OAAO,EAAE,IAAI,GAAG,4BAA4B;AAAA,EAC9D,iBAAiB,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,EAC3C,oBAAoB,EAAE,OAAO,EAAE,SAAS;AAAA,EACxC,oBAAoB,EAAE,OAAO,EAAE,SAAS;AAAA,EACxC,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,EACjC,aAAa,EA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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\tIAgentRuntime,\n\tImageDescriptionParams,\n\tModelType,\n\tObjectGenerationParams,\n\tPlugin,\n\tTextEmbeddingParams,\n} from \"@elizaos/core\";\nimport {\n\ttype DetokenizeTextParams,\n\ttype GenerateTextParams,\n\tModelTypes,\n\ttype TokenizeTextParams,\n\tlogger,\n} from \"@elizaos/core\";\nimport { generateText } from \"ai\";\nimport { type TiktokenModel, encodingForModel } from \"js-tiktoken\";\n// import { z } from \"zod\";\n\n/**\n * Asynchronously tokenizes the given text based on the specified model and prompt.\n *\n * @param {ModelType} 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: 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\n/**\n * Detokenize a sequence of tokens back into text using the specified model.\n *\n * @param {ModelType} 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: 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\n// const 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\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[ModelTypes.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[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\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[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 (\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[ModelTypes.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[ModelTypes.OBJECT_SMALL]: async (runtime, params) => {\n\t\t\treturn await generateObject(runtime, {\n\t\t\t\t...params,\n\t\t\t\tmodelType: ModelTypes.OBJECT_SMALL,\n\t\t\t});\n\t\t},\n\t\t[ModelTypes.OBJECT_LARGE]: async (runtime, params) => {\n\t\t\treturn await generateObject(runtime, {\n\t\t\t\t...params,\n\t\t\t\tmodelType: ModelTypes.OBJECT_LARGE,\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\tModelTypes.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(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\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(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\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(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\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\tModelTypes.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\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\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\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\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\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\tlogger.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\n/**\n * Generates a structured object from a prompt using OpenAI's function calling capabilities.\n *\n * @param runtime The agent runtime\n * @param params The generation parameters\n * @returns The generated object\n */\nasync function generateObject(\n\truntime: IAgentRuntime,\n\tparams: ObjectGenerationParams,\n) {\n\tconst {\n\t\tprompt,\n\t\tschema,\n\t\toutput = \"object\",\n\t\tenumValues = [],\n\t\tmodelType = ModelTypes.OBJECT_SMALL,\n\t\ttemperature = 0.7,\n\t} = params;\n\n\t// Determine which model to use\n\tconst modelName =\n\t\tmodelType === ModelTypes.OBJECT_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\n\tconst baseURL = process.env.OPENAI_BASE_URL ?? \"https://api.openai.com/v1\";\n\n\t// Handle enum types specifically\n\tif (output === \"enum\" && enumValues.length) {\n\t\ttry {\n\t\t\tconst response = await fetch(`${baseURL}/chat/completions`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\tAuthorization: `Bearer ${process.env.OPENAI_API_KEY}`,\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tmodel: modelName,\n\t\t\t\t\tmessages: [{ role: \"user\", content: prompt }],\n\t\t\t\t\ttemperature,\n\t\t\t\t\ttools: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"function\",\n\t\t\t\t\t\t\tfunction: {\n\t\t\t\t\t\t\t\tname: \"select_value\",\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\"Select the most appropriate value from the provided options\",\n\t\t\t\t\t\t\t\tparameters: {\n\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\tenum: enumValues,\n\t\t\t\t\t\t\t\t\t\t\tdescription: \"The selected value\",\n\t\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\trequired: [\"value\"],\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],\n\t\t\t\t\ttool_choice: { type: \"function\", function: { name: \"select_value\" } },\n\t\t\t\t}),\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`API error: ${response.status}`);\n\t\t\t}\n\n\t\t\tconst result: any = await response.json();\n\t\t\tconst toolCalls = result.choices?.[0]?.message?.tool_calls;\n\n\t\t\tif (toolCalls && toolCalls.length > 0) {\n\t\t\t\ttry {\n\t\t\t\t\tconst functionArgs = JSON.parse(toolCalls[0].function.arguments);\n\t\t\t\t\treturn functionArgs.value;\n\t\t\t\t} catch (err) {\n\t\t\t\t\tlogger.error(\"Failed to parse function arguments:\", err);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn null;\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Error generating enum value:\", error);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t// Handle regular object generation with schema\n\ttry {\n\t\t// Determine the appropriate JSON schema\n\t\tlet functionSchema: any;\n\n\t\tif (schema) {\n\t\t\t// Use provided schema\n\t\t\tfunctionSchema = schema;\n\t\t} else {\n\t\t\t// Default schema based on output type\n\t\t\tfunctionSchema = {\n\t\t\t\ttype: output === \"array\" ? \"array\" : \"object\",\n\t\t\t\t...(output === \"array\" ? { items: { type: \"object\" } } : {}),\n\t\t\t};\n\t\t}\n\n\t\t// Call the OpenAI API directly\n\t\tconst response = await fetch(`${baseURL}/chat/completions`, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\tAuthorization: `Bearer ${process.env.OPENAI_API_KEY}`,\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tmodel: modelName,\n\t\t\t\tmessages: [{ role: \"user\", content: prompt }],\n\t\t\t\ttemperature,\n\t\t\t\ttools: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"function\",\n\t\t\t\t\t\tfunction: {\n\t\t\t\t\t\t\tname: \"generate_structured_data\",\n\t\t\t\t\t\t\tdescription: \"Generate structured data based on the prompt\",\n\t\t\t\t\t\t\tparameters: functionSchema,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\ttool_choice: {\n\t\t\t\t\ttype: \"function\",\n\t\t\t\t\tfunction: { name: \"generate_structured_data\" },\n\t\t\t\t},\n\t\t\t}),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(`API error: ${response.status}`);\n\t\t}\n\n\t\tconst result: any = await response.json();\n\t\tconst toolCalls = result.choices?.[0]?.message?.tool_calls;\n\n\t\tif (toolCalls && toolCalls.length > 0) {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(toolCalls[0].function.arguments);\n\t\t\t} catch (err) {\n\t\t\t\tlogger.error(\"Failed to parse function arguments:\", err);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t} catch (error) {\n\t\tlogger.error(\"Error generating object:\", error);\n\t\treturn null;\n\t}\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;AAS7B;AAAA,EAGC;AAAA,EAEA;AAAA,OACM;AACP,SAAS,oBAAoB;AAC7B,SAA6B,wBAAwB;AAUrD,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;AASA,eAAe,eAAe,OAAkB,QAAkB;AACjE,QAAM,YACL,UAAU,WAAW,aACjB,QAAQ,IAAI,sBACd,QAAQ,IAAI,eACZ,gBACE,QAAQ,IAAI,sBAAsB,QAAQ,IAAI,eAAe;AA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,CAAC,GAAG,SAAS;AAEhD,QAAI,aAAa,UAAU,SAAS,GAAG;AACtC,UAAI;AACH,eAAO,KAAK,MAAM,UAAU,CAAC,EAAE,SAAS,SAAS;AAAA,MAClD,SAAS,KAAK;AACb,eAAO,MAAM,uCAAuC,GAAG;AACvD,eAAO;AAAA,MACR;AAAA,IACD;AAEA,WAAO;AAAA,EACR,SAAS,OAAO;AACf,WAAO,MAAM,4BAA4B,KAAK;AAC9C,WAAO;AAAA,EACR;AACD;","names":[]}
|
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.51",
|
|
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.51",
|
|
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": "9e19a944455d97dc37cd32c4e2157542b4d3a8c4"
|
|
53
51
|
}
|