@elizaos/plugin-openai 1.0.0-alpha.58 → 1.0.0-alpha.59
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 +78 -152
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { createOpenAI } from "@ai-sdk/openai";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
ModelType,
|
|
5
5
|
logger
|
|
6
6
|
} from "@elizaos/core";
|
|
7
|
-
import { generateText } from "ai";
|
|
7
|
+
import { generateObject, generateText } from "ai";
|
|
8
8
|
import { encodingForModel } from "js-tiktoken";
|
|
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
|
}
|
|
@@ -65,7 +66,7 @@ var openaiPlugin = {
|
|
|
65
66
|
}
|
|
66
67
|
},
|
|
67
68
|
models: {
|
|
68
|
-
[
|
|
69
|
+
[ModelType.TEXT_EMBEDDING]: async (runtime, params) => {
|
|
69
70
|
if (params === null) {
|
|
70
71
|
logger.debug("Creating test embedding for initialization");
|
|
71
72
|
const testVector = Array(1536).fill(0);
|
|
@@ -127,13 +128,13 @@ var openaiPlugin = {
|
|
|
127
128
|
return errorVector;
|
|
128
129
|
}
|
|
129
130
|
},
|
|
130
|
-
[
|
|
131
|
-
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);
|
|
132
133
|
},
|
|
133
|
-
[
|
|
134
|
-
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);
|
|
135
136
|
},
|
|
136
|
-
[
|
|
137
|
+
[ModelType.TEXT_SMALL]: async (runtime, { prompt, stopSequences = [] }) => {
|
|
137
138
|
const temperature = 0.7;
|
|
138
139
|
const frequency_penalty = 0.7;
|
|
139
140
|
const presence_penalty = 0.7;
|
|
@@ -158,7 +159,7 @@ var openaiPlugin = {
|
|
|
158
159
|
});
|
|
159
160
|
return openaiResponse;
|
|
160
161
|
},
|
|
161
|
-
[
|
|
162
|
+
[ModelType.TEXT_LARGE]: async (runtime, {
|
|
162
163
|
prompt,
|
|
163
164
|
stopSequences = [],
|
|
164
165
|
maxTokens = 8192,
|
|
@@ -184,7 +185,7 @@ var openaiPlugin = {
|
|
|
184
185
|
});
|
|
185
186
|
return openaiResponse;
|
|
186
187
|
},
|
|
187
|
-
[
|
|
188
|
+
[ModelType.IMAGE]: async (runtime, params) => {
|
|
188
189
|
const baseURL = runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
|
|
189
190
|
const response = await fetch(`${baseURL}/images/generations`, {
|
|
190
191
|
method: "POST",
|
|
@@ -205,7 +206,7 @@ var openaiPlugin = {
|
|
|
205
206
|
const typedData = data;
|
|
206
207
|
return typedData.data;
|
|
207
208
|
},
|
|
208
|
-
[
|
|
209
|
+
[ModelType.IMAGE_DESCRIPTION]: async (runtime, params) => {
|
|
209
210
|
let imageUrl;
|
|
210
211
|
let prompt;
|
|
211
212
|
if (typeof params === "string") {
|
|
@@ -274,7 +275,7 @@ var openaiPlugin = {
|
|
|
274
275
|
};
|
|
275
276
|
}
|
|
276
277
|
},
|
|
277
|
-
[
|
|
278
|
+
[ModelType.TRANSCRIPTION]: async (runtime, audioBuffer) => {
|
|
278
279
|
logger.log("audioBuffer", audioBuffer);
|
|
279
280
|
const baseURL = runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
|
|
280
281
|
const formData = new FormData();
|
|
@@ -295,17 +296,63 @@ var openaiPlugin = {
|
|
|
295
296
|
const data = await response.json();
|
|
296
297
|
return data.text;
|
|
297
298
|
},
|
|
298
|
-
[
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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
|
|
302
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
|
+
}
|
|
303
327
|
},
|
|
304
|
-
[
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
|
308
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
|
+
}
|
|
309
356
|
}
|
|
310
357
|
},
|
|
311
358
|
tests: [
|
|
@@ -335,7 +382,7 @@ var openaiPlugin = {
|
|
|
335
382
|
fn: async (runtime) => {
|
|
336
383
|
try {
|
|
337
384
|
const embedding = await runtime.useModel(
|
|
338
|
-
|
|
385
|
+
ModelType.TEXT_EMBEDDING,
|
|
339
386
|
{
|
|
340
387
|
text: "Hello, world!"
|
|
341
388
|
}
|
|
@@ -351,7 +398,7 @@ var openaiPlugin = {
|
|
|
351
398
|
name: "openai_test_text_large",
|
|
352
399
|
fn: async (runtime) => {
|
|
353
400
|
try {
|
|
354
|
-
const text = await runtime.useModel(
|
|
401
|
+
const text = await runtime.useModel(ModelType.TEXT_LARGE, {
|
|
355
402
|
prompt: "What is the nature of reality in 10 words?"
|
|
356
403
|
});
|
|
357
404
|
if (text.length === 0) {
|
|
@@ -368,7 +415,7 @@ var openaiPlugin = {
|
|
|
368
415
|
name: "openai_test_text_small",
|
|
369
416
|
fn: async (runtime) => {
|
|
370
417
|
try {
|
|
371
|
-
const text = await runtime.useModel(
|
|
418
|
+
const text = await runtime.useModel(ModelType.TEXT_SMALL, {
|
|
372
419
|
prompt: "What is the nature of reality in 10 words?"
|
|
373
420
|
});
|
|
374
421
|
if (text.length === 0) {
|
|
@@ -386,7 +433,7 @@ var openaiPlugin = {
|
|
|
386
433
|
fn: async (runtime) => {
|
|
387
434
|
logger.log("openai_test_image_generation");
|
|
388
435
|
try {
|
|
389
|
-
const image = await runtime.useModel(
|
|
436
|
+
const image = await runtime.useModel(ModelType.IMAGE, {
|
|
390
437
|
prompt: "A beautiful sunset over a calm ocean",
|
|
391
438
|
n: 1,
|
|
392
439
|
size: "1024x1024"
|
|
@@ -405,7 +452,7 @@ var openaiPlugin = {
|
|
|
405
452
|
logger.log("openai_test_image_description");
|
|
406
453
|
try {
|
|
407
454
|
const result = await runtime.useModel(
|
|
408
|
-
|
|
455
|
+
ModelType.IMAGE_DESCRIPTION,
|
|
409
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"
|
|
410
457
|
);
|
|
411
458
|
if (result && typeof result === "object" && "title" in result && "description" in result) {
|
|
@@ -434,7 +481,7 @@ var openaiPlugin = {
|
|
|
434
481
|
);
|
|
435
482
|
const arrayBuffer = await response.arrayBuffer();
|
|
436
483
|
const transcription = await runtime.useModel(
|
|
437
|
-
|
|
484
|
+
ModelType.TRANSCRIPTION,
|
|
438
485
|
Buffer.from(new Uint8Array(arrayBuffer))
|
|
439
486
|
);
|
|
440
487
|
logger.log("generated with test_transcription:", transcription);
|
|
@@ -449,7 +496,7 @@ var openaiPlugin = {
|
|
|
449
496
|
fn: async (runtime) => {
|
|
450
497
|
const prompt = "Hello tokenizer encode!";
|
|
451
498
|
const tokens = await runtime.useModel(
|
|
452
|
-
|
|
499
|
+
ModelType.TEXT_TOKENIZER_ENCODE,
|
|
453
500
|
{ prompt }
|
|
454
501
|
);
|
|
455
502
|
if (!Array.isArray(tokens) || tokens.length === 0) {
|
|
@@ -465,11 +512,11 @@ var openaiPlugin = {
|
|
|
465
512
|
fn: async (runtime) => {
|
|
466
513
|
const prompt = "Hello tokenizer decode!";
|
|
467
514
|
const tokens = await runtime.useModel(
|
|
468
|
-
|
|
515
|
+
ModelType.TEXT_TOKENIZER_ENCODE,
|
|
469
516
|
{ prompt }
|
|
470
517
|
);
|
|
471
518
|
const decodedText = await runtime.useModel(
|
|
472
|
-
|
|
519
|
+
ModelType.TEXT_TOKENIZER_DECODE,
|
|
473
520
|
{ tokens }
|
|
474
521
|
);
|
|
475
522
|
if (decodedText !== prompt) {
|
|
@@ -485,127 +532,6 @@ var openaiPlugin = {
|
|
|
485
532
|
]
|
|
486
533
|
};
|
|
487
534
|
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
|
-
}
|
|
609
535
|
export {
|
|
610
536
|
index_default as default,
|
|
611
537
|
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 {\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;AAClE,QAAM,WAAW,iBAAiB,SAA0B;AAC5D,SAAO,SAAS,OAAO,MAAM;AAC9B;AAeO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AAO,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":[]}
|
|
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\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"],"mappings":";AAAA,SAAS,oBAAoB;AAQ7B;AAAA,EAGC;AAAA,EAEA;AAAA,OACM;AACP,SAAS,gBAAgB,oBAAoB;AAC7C,SAA6B,wBAAwB;AACrD,SAAS,SAAS;AASlB,eAAe,aAAa,OAAsB,QAAgB;AACjE,QAAM,YACL,UAAU,UAAU,aAChB,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,OA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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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/plugin-openai",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.59",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@ai-sdk/openai": "^1.1.9",
|
|
26
26
|
"@ai-sdk/ui-utils": "1.1.9",
|
|
27
|
-
"@elizaos/core": "^1.0.0-alpha.
|
|
27
|
+
"@elizaos/core": "^1.0.0-alpha.59",
|
|
28
28
|
"ai": "^4.1.25",
|
|
29
29
|
"js-tiktoken": "^1.0.18",
|
|
30
30
|
"tsup": "8.4.0"
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "e450585943baaa522b53b236a7cb0268b72b3901"
|
|
51
51
|
}
|