@aigne/openai 0.13.6 → 0.14.0
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.14.0](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.13.7...openai-v0.14.0) (2025-09-05)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add modalities support for chat model ([#454](https://github.com/AIGNE-io/aigne-framework/issues/454)) ([70d1bf6](https://github.com/AIGNE-io/aigne-framework/commit/70d1bf631f4e711235d89c6df8ee210a19179b30))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @aigne/core bumped to 1.58.0
|
|
16
|
+
* devDependencies
|
|
17
|
+
* @aigne/test-utils bumped to 0.5.44
|
|
18
|
+
|
|
19
|
+
## [0.13.7](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.13.6...openai-v0.13.7) (2025-09-01)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Dependencies
|
|
23
|
+
|
|
24
|
+
* The following workspace dependencies were updated
|
|
25
|
+
* dependencies
|
|
26
|
+
* @aigne/core bumped to 1.57.5
|
|
27
|
+
* devDependencies
|
|
28
|
+
* @aigne/test-utils bumped to 0.5.43
|
|
29
|
+
|
|
3
30
|
## [0.13.6](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.13.5...openai-v0.13.6) (2025-08-30)
|
|
4
31
|
|
|
5
32
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
|
|
1
|
+
import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
|
|
2
2
|
import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
|
|
3
3
|
import type { ClientOptions, OpenAI } from "openai";
|
|
4
4
|
import type { ChatCompletionMessageParam, ChatCompletionTool } from "openai/resources";
|
|
@@ -143,7 +143,7 @@ export declare class OpenAIChatModel extends ChatModel {
|
|
|
143
143
|
* @param input The input to process
|
|
144
144
|
* @returns The generated response
|
|
145
145
|
*/
|
|
146
|
-
process(input: ChatModelInput): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
|
|
146
|
+
process(input: ChatModelInput, _options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
|
|
147
147
|
private ajv;
|
|
148
148
|
private _process;
|
|
149
149
|
private getParallelToolCalls;
|
|
@@ -10,6 +10,7 @@ const model_utils_js_1 = require("@aigne/core/utils/model-utils.js");
|
|
|
10
10
|
const prompts_js_1 = require("@aigne/core/utils/prompts.js");
|
|
11
11
|
const stream_utils_js_1 = require("@aigne/core/utils/stream-utils.js");
|
|
12
12
|
const type_utils_js_1 = require("@aigne/core/utils/type-utils.js");
|
|
13
|
+
const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
|
|
13
14
|
const ajv_1 = require("ajv");
|
|
14
15
|
const uuid_1 = require("uuid");
|
|
15
16
|
const zod_1 = require("zod");
|
|
@@ -104,7 +105,7 @@ class OpenAIChatModel extends core_1.ChatModel {
|
|
|
104
105
|
* @param input The input to process
|
|
105
106
|
* @returns The generated response
|
|
106
107
|
*/
|
|
107
|
-
process(input) {
|
|
108
|
+
process(input, _options) {
|
|
108
109
|
return this._process(input);
|
|
109
110
|
}
|
|
110
111
|
ajv = new ajv_1.Ajv();
|
|
@@ -320,23 +321,33 @@ const mapRole = (0, core_1.createRoleMapper)(core_1.STANDARD_ROLE_MAP);
|
|
|
320
321
|
* @hidden
|
|
321
322
|
*/
|
|
322
323
|
async function contentsFromInputMessages(messages) {
|
|
323
|
-
return messages.map((i) => ({
|
|
324
|
+
return Promise.all(messages.map(async (i) => ({
|
|
324
325
|
role: mapRole(i.role),
|
|
325
326
|
content: typeof i.content === "string"
|
|
326
327
|
? i.content
|
|
327
|
-
: i.content
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
328
|
+
: i.content &&
|
|
329
|
+
(await Promise.all(i.content.map(async (c) => {
|
|
330
|
+
switch (c.type) {
|
|
331
|
+
case "text":
|
|
332
|
+
return { type: "text", text: c.text };
|
|
333
|
+
case "url":
|
|
334
|
+
return { type: "image_url", image_url: { url: c.url } };
|
|
335
|
+
case "file":
|
|
336
|
+
return {
|
|
337
|
+
type: "file",
|
|
338
|
+
file: { file_data: c.data, filename: c.filename },
|
|
339
|
+
};
|
|
340
|
+
case "local": {
|
|
341
|
+
return {
|
|
342
|
+
type: "file",
|
|
343
|
+
file: {
|
|
344
|
+
file_data: await index_js_1.nodejs.fs.readFile(c.path, "base64"),
|
|
345
|
+
filename: c.filename,
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}))).filter(type_utils_js_1.isNonNullable),
|
|
340
351
|
tool_calls: i.toolCalls?.map((i) => ({
|
|
341
352
|
...i,
|
|
342
353
|
function: {
|
|
@@ -346,7 +357,7 @@ async function contentsFromInputMessages(messages) {
|
|
|
346
357
|
})),
|
|
347
358
|
tool_call_id: i.toolCallId,
|
|
348
359
|
name: i.name,
|
|
349
|
-
}));
|
|
360
|
+
})));
|
|
350
361
|
}
|
|
351
362
|
/**
|
|
352
363
|
* @hidden
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
|
|
1
|
+
import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
|
|
2
2
|
import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
|
|
3
3
|
import type { ClientOptions, OpenAI } from "openai";
|
|
4
4
|
import type { ChatCompletionMessageParam, ChatCompletionTool } from "openai/resources";
|
|
@@ -143,7 +143,7 @@ export declare class OpenAIChatModel extends ChatModel {
|
|
|
143
143
|
* @param input The input to process
|
|
144
144
|
* @returns The generated response
|
|
145
145
|
*/
|
|
146
|
-
process(input: ChatModelInput): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
|
|
146
|
+
process(input: ChatModelInput, _options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
|
|
147
147
|
private ajv;
|
|
148
148
|
private _process;
|
|
149
149
|
private getParallelToolCalls;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
|
|
1
|
+
import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
|
|
2
2
|
import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
|
|
3
3
|
import type { ClientOptions, OpenAI } from "openai";
|
|
4
4
|
import type { ChatCompletionMessageParam, ChatCompletionTool } from "openai/resources";
|
|
@@ -143,7 +143,7 @@ export declare class OpenAIChatModel extends ChatModel {
|
|
|
143
143
|
* @param input The input to process
|
|
144
144
|
* @returns The generated response
|
|
145
145
|
*/
|
|
146
|
-
process(input: ChatModelInput): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
|
|
146
|
+
process(input: ChatModelInput, _options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
|
|
147
147
|
private ajv;
|
|
148
148
|
private _process;
|
|
149
149
|
private getParallelToolCalls;
|
|
@@ -4,6 +4,7 @@ import { mergeUsage } from "@aigne/core/utils/model-utils.js";
|
|
|
4
4
|
import { getJsonOutputPrompt } from "@aigne/core/utils/prompts.js";
|
|
5
5
|
import { agentResponseStreamToObject } from "@aigne/core/utils/stream-utils.js";
|
|
6
6
|
import { checkArguments, isNonNullable, } from "@aigne/core/utils/type-utils.js";
|
|
7
|
+
import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
7
8
|
import { Ajv } from "ajv";
|
|
8
9
|
import { v7 } from "uuid";
|
|
9
10
|
import { z } from "zod";
|
|
@@ -98,7 +99,7 @@ export class OpenAIChatModel extends ChatModel {
|
|
|
98
99
|
* @param input The input to process
|
|
99
100
|
* @returns The generated response
|
|
100
101
|
*/
|
|
101
|
-
process(input) {
|
|
102
|
+
process(input, _options) {
|
|
102
103
|
return this._process(input);
|
|
103
104
|
}
|
|
104
105
|
ajv = new Ajv();
|
|
@@ -313,23 +314,33 @@ const mapRole = createRoleMapper(STANDARD_ROLE_MAP);
|
|
|
313
314
|
* @hidden
|
|
314
315
|
*/
|
|
315
316
|
export async function contentsFromInputMessages(messages) {
|
|
316
|
-
return messages.map((i) => ({
|
|
317
|
+
return Promise.all(messages.map(async (i) => ({
|
|
317
318
|
role: mapRole(i.role),
|
|
318
319
|
content: typeof i.content === "string"
|
|
319
320
|
? i.content
|
|
320
|
-
: i.content
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
321
|
+
: i.content &&
|
|
322
|
+
(await Promise.all(i.content.map(async (c) => {
|
|
323
|
+
switch (c.type) {
|
|
324
|
+
case "text":
|
|
325
|
+
return { type: "text", text: c.text };
|
|
326
|
+
case "url":
|
|
327
|
+
return { type: "image_url", image_url: { url: c.url } };
|
|
328
|
+
case "file":
|
|
329
|
+
return {
|
|
330
|
+
type: "file",
|
|
331
|
+
file: { file_data: c.data, filename: c.filename },
|
|
332
|
+
};
|
|
333
|
+
case "local": {
|
|
334
|
+
return {
|
|
335
|
+
type: "file",
|
|
336
|
+
file: {
|
|
337
|
+
file_data: await nodejs.fs.readFile(c.path, "base64"),
|
|
338
|
+
filename: c.filename,
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}))).filter(isNonNullable),
|
|
333
344
|
tool_calls: i.toolCalls?.map((i) => ({
|
|
334
345
|
...i,
|
|
335
346
|
function: {
|
|
@@ -339,7 +350,7 @@ export async function contentsFromInputMessages(messages) {
|
|
|
339
350
|
})),
|
|
340
351
|
tool_call_id: i.toolCallId,
|
|
341
352
|
name: i.name,
|
|
342
|
-
}));
|
|
353
|
+
})));
|
|
343
354
|
}
|
|
344
355
|
/**
|
|
345
356
|
* @hidden
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/openai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "AIGNE OpenAI SDK for integrating with OpenAI's GPT models and API services",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"openai": "^5.8.3",
|
|
40
40
|
"uuid": "^11.1.0",
|
|
41
41
|
"zod": "^3.25.67",
|
|
42
|
-
"@aigne/
|
|
42
|
+
"@aigne/platform-helpers": "^0.6.2",
|
|
43
|
+
"@aigne/core": "^1.58.0"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@types/bun": "^1.2.18",
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
"npm-run-all": "^4.1.5",
|
|
48
49
|
"rimraf": "^6.0.1",
|
|
49
50
|
"typescript": "^5.8.3",
|
|
50
|
-
"@aigne/test-utils": "^0.5.
|
|
51
|
+
"@aigne/test-utils": "^0.5.44"
|
|
51
52
|
},
|
|
52
53
|
"scripts": {
|
|
53
54
|
"lint": "tsc --noEmit",
|