@aigne/openai 0.15.3 → 0.16.0-beta
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,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.16.0-beta](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.15.4...openai-v0.16.0-beta) (2025-09-22)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* improve image model architecture and file handling ([#527](https://github.com/AIGNE-io/aigne-framework/issues/527)) ([4db50aa](https://github.com/AIGNE-io/aigne-framework/commit/4db50aa0387a1a0f045ca11aaa61613e36ca7597))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @aigne/core bumped to 1.61.0-beta
|
|
16
|
+
* @aigne/platform-helpers bumped to 0.6.3-beta
|
|
17
|
+
* devDependencies
|
|
18
|
+
* @aigne/test-utils bumped to 0.5.53-beta
|
|
19
|
+
|
|
20
|
+
## [0.15.4](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.15.3...openai-v0.15.4) (2025-09-18)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Dependencies
|
|
24
|
+
|
|
25
|
+
* The following workspace dependencies were updated
|
|
26
|
+
* dependencies
|
|
27
|
+
* @aigne/core bumped to 1.60.3
|
|
28
|
+
* devDependencies
|
|
29
|
+
* @aigne/test-utils bumped to 0.5.52
|
|
30
|
+
|
|
3
31
|
## [0.15.3](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.15.2...openai-v0.15.3) (2025-09-11)
|
|
4
32
|
|
|
5
33
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ImageModel, type ImageModelInput, type ImageModelOptions, type ImageModelOutput } from "@aigne/core";
|
|
1
|
+
import { type AgentInvokeOptions, ImageModel, type ImageModelInput, type ImageModelOptions, type ImageModelOutput } from "@aigne/core";
|
|
2
2
|
import { type Camelize } from "@aigne/core/utils/camelize.js";
|
|
3
3
|
import type OpenAI from "openai";
|
|
4
4
|
import type { ClientOptions } from "openai";
|
|
5
|
-
export interface OpenAIImageModelInput extends ImageModelInput, Camelize<Omit<OpenAI.ImageGenerateParams, "prompt" | "model" | "n" | "response_format">> {
|
|
5
|
+
export interface OpenAIImageModelInput extends ImageModelInput, Camelize<Omit<OpenAI.ImageGenerateParams | OpenAI.ImageEditParams, "prompt" | "model" | "n" | "response_format">> {
|
|
6
6
|
}
|
|
7
7
|
export interface OpenAIImageModelOutput extends ImageModelOutput {
|
|
8
8
|
}
|
|
@@ -51,5 +51,5 @@ export declare class OpenAIImageModel extends ImageModel<OpenAIImageModelInput,
|
|
|
51
51
|
* @param input The input to process
|
|
52
52
|
* @returns The generated response
|
|
53
53
|
*/
|
|
54
|
-
process(input: OpenAIImageModelInput): Promise<OpenAIImageModelOutput>;
|
|
54
|
+
process(input: OpenAIImageModelInput, options: AgentInvokeOptions): Promise<OpenAIImageModelOutput>;
|
|
55
55
|
}
|
|
@@ -7,6 +7,7 @@ const type_utils_js_1 = require("@aigne/core/utils/type-utils.js");
|
|
|
7
7
|
const zod_1 = require("zod");
|
|
8
8
|
const openai_js_1 = require("./openai.js");
|
|
9
9
|
const DEFAULT_MODEL = "dall-e-2";
|
|
10
|
+
const OUTPUT_MIME_TYPE = "image/png";
|
|
10
11
|
const openAIImageModelInputSchema = core_1.imageModelInputSchema.extend({});
|
|
11
12
|
const openAIImageModelOptionsSchema = zod_1.z.object({
|
|
12
13
|
apiKey: zod_1.z.string().optional(),
|
|
@@ -57,7 +58,7 @@ class OpenAIImageModel extends core_1.ImageModel {
|
|
|
57
58
|
* @param input The input to process
|
|
58
59
|
* @returns The generated response
|
|
59
60
|
*/
|
|
60
|
-
async process(input) {
|
|
61
|
+
async process(input, options) {
|
|
61
62
|
const model = input.model || this.credential.model;
|
|
62
63
|
const map = {
|
|
63
64
|
"dall-e-2": ["prompt", "size", "n"],
|
|
@@ -83,13 +84,21 @@ class OpenAIImageModel extends core_1.ImageModel {
|
|
|
83
84
|
response_format: responseFormat,
|
|
84
85
|
model,
|
|
85
86
|
};
|
|
86
|
-
const response =
|
|
87
|
+
const response = input.image?.length
|
|
88
|
+
? await this.client.images.edit({
|
|
89
|
+
...body,
|
|
90
|
+
image: await Promise.all(input.image.map((image) => this.transformFileOutput(core_1.FileOutputType.file, image, options).then((file) => new File([Buffer.from(file.data, "base64")], file.filename || "image.png", {
|
|
91
|
+
type: file.mimeType,
|
|
92
|
+
})))),
|
|
93
|
+
stream: false,
|
|
94
|
+
})
|
|
95
|
+
: await this.client.images.generate({ ...body, stream: false });
|
|
87
96
|
return {
|
|
88
97
|
images: (response.data ?? []).map((image) => {
|
|
89
98
|
if (image.url)
|
|
90
|
-
return { url: image.url };
|
|
99
|
+
return { type: "url", url: image.url, mimeType: OUTPUT_MIME_TYPE };
|
|
91
100
|
if (image.b64_json)
|
|
92
|
-
return {
|
|
101
|
+
return { type: "file", data: image.b64_json, mimeType: OUTPUT_MIME_TYPE };
|
|
93
102
|
throw new Error("Image response does not contain a valid URL or base64 data");
|
|
94
103
|
}),
|
|
95
104
|
usage: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ImageModel, type ImageModelInput, type ImageModelOptions, type ImageModelOutput } from "@aigne/core";
|
|
1
|
+
import { type AgentInvokeOptions, ImageModel, type ImageModelInput, type ImageModelOptions, type ImageModelOutput } from "@aigne/core";
|
|
2
2
|
import { type Camelize } from "@aigne/core/utils/camelize.js";
|
|
3
3
|
import type OpenAI from "openai";
|
|
4
4
|
import type { ClientOptions } from "openai";
|
|
5
|
-
export interface OpenAIImageModelInput extends ImageModelInput, Camelize<Omit<OpenAI.ImageGenerateParams, "prompt" | "model" | "n" | "response_format">> {
|
|
5
|
+
export interface OpenAIImageModelInput extends ImageModelInput, Camelize<Omit<OpenAI.ImageGenerateParams | OpenAI.ImageEditParams, "prompt" | "model" | "n" | "response_format">> {
|
|
6
6
|
}
|
|
7
7
|
export interface OpenAIImageModelOutput extends ImageModelOutput {
|
|
8
8
|
}
|
|
@@ -51,5 +51,5 @@ export declare class OpenAIImageModel extends ImageModel<OpenAIImageModelInput,
|
|
|
51
51
|
* @param input The input to process
|
|
52
52
|
* @returns The generated response
|
|
53
53
|
*/
|
|
54
|
-
process(input: OpenAIImageModelInput): Promise<OpenAIImageModelOutput>;
|
|
54
|
+
process(input: OpenAIImageModelInput, options: AgentInvokeOptions): Promise<OpenAIImageModelOutput>;
|
|
55
55
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ImageModel, type ImageModelInput, type ImageModelOptions, type ImageModelOutput } from "@aigne/core";
|
|
1
|
+
import { type AgentInvokeOptions, ImageModel, type ImageModelInput, type ImageModelOptions, type ImageModelOutput } from "@aigne/core";
|
|
2
2
|
import { type Camelize } from "@aigne/core/utils/camelize.js";
|
|
3
3
|
import type OpenAI from "openai";
|
|
4
4
|
import type { ClientOptions } from "openai";
|
|
5
|
-
export interface OpenAIImageModelInput extends ImageModelInput, Camelize<Omit<OpenAI.ImageGenerateParams, "prompt" | "model" | "n" | "response_format">> {
|
|
5
|
+
export interface OpenAIImageModelInput extends ImageModelInput, Camelize<Omit<OpenAI.ImageGenerateParams | OpenAI.ImageEditParams, "prompt" | "model" | "n" | "response_format">> {
|
|
6
6
|
}
|
|
7
7
|
export interface OpenAIImageModelOutput extends ImageModelOutput {
|
|
8
8
|
}
|
|
@@ -51,5 +51,5 @@ export declare class OpenAIImageModel extends ImageModel<OpenAIImageModelInput,
|
|
|
51
51
|
* @param input The input to process
|
|
52
52
|
* @returns The generated response
|
|
53
53
|
*/
|
|
54
|
-
process(input: OpenAIImageModelInput): Promise<OpenAIImageModelOutput>;
|
|
54
|
+
process(input: OpenAIImageModelInput, options: AgentInvokeOptions): Promise<OpenAIImageModelOutput>;
|
|
55
55
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ImageModel, imageModelInputSchema, } from "@aigne/core";
|
|
1
|
+
import { FileOutputType, ImageModel, imageModelInputSchema, } from "@aigne/core";
|
|
2
2
|
import { snakelize } from "@aigne/core/utils/camelize.js";
|
|
3
3
|
import { checkArguments, pick } from "@aigne/core/utils/type-utils.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { CustomOpenAI } from "./openai.js";
|
|
6
6
|
const DEFAULT_MODEL = "dall-e-2";
|
|
7
|
+
const OUTPUT_MIME_TYPE = "image/png";
|
|
7
8
|
const openAIImageModelInputSchema = imageModelInputSchema.extend({});
|
|
8
9
|
const openAIImageModelOptionsSchema = z.object({
|
|
9
10
|
apiKey: z.string().optional(),
|
|
@@ -54,7 +55,7 @@ export class OpenAIImageModel extends ImageModel {
|
|
|
54
55
|
* @param input The input to process
|
|
55
56
|
* @returns The generated response
|
|
56
57
|
*/
|
|
57
|
-
async process(input) {
|
|
58
|
+
async process(input, options) {
|
|
58
59
|
const model = input.model || this.credential.model;
|
|
59
60
|
const map = {
|
|
60
61
|
"dall-e-2": ["prompt", "size", "n"],
|
|
@@ -80,13 +81,21 @@ export class OpenAIImageModel extends ImageModel {
|
|
|
80
81
|
response_format: responseFormat,
|
|
81
82
|
model,
|
|
82
83
|
};
|
|
83
|
-
const response =
|
|
84
|
+
const response = input.image?.length
|
|
85
|
+
? await this.client.images.edit({
|
|
86
|
+
...body,
|
|
87
|
+
image: await Promise.all(input.image.map((image) => this.transformFileOutput(FileOutputType.file, image, options).then((file) => new File([Buffer.from(file.data, "base64")], file.filename || "image.png", {
|
|
88
|
+
type: file.mimeType,
|
|
89
|
+
})))),
|
|
90
|
+
stream: false,
|
|
91
|
+
})
|
|
92
|
+
: await this.client.images.generate({ ...body, stream: false });
|
|
84
93
|
return {
|
|
85
94
|
images: (response.data ?? []).map((image) => {
|
|
86
95
|
if (image.url)
|
|
87
|
-
return { url: image.url };
|
|
96
|
+
return { type: "url", url: image.url, mimeType: OUTPUT_MIME_TYPE };
|
|
88
97
|
if (image.b64_json)
|
|
89
|
-
return {
|
|
98
|
+
return { type: "file", data: image.b64_json, mimeType: OUTPUT_MIME_TYPE };
|
|
90
99
|
throw new Error("Image response does not contain a valid URL or base64 data");
|
|
91
100
|
}),
|
|
92
101
|
usage: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/openai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0-beta",
|
|
4
4
|
"description": "AIGNE OpenAI SDK for integrating with OpenAI's GPT models and API services",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"ajv": "^8.17.1",
|
|
39
|
-
"openai": "^5.
|
|
40
|
-
"uuid": "^
|
|
39
|
+
"openai": "^5.20.3",
|
|
40
|
+
"uuid": "^13.0.0",
|
|
41
41
|
"zod": "^3.25.67",
|
|
42
|
-
"@aigne/platform-helpers": "^0.6.
|
|
43
|
-
"@aigne/core": "^1.
|
|
42
|
+
"@aigne/platform-helpers": "^0.6.3-beta",
|
|
43
|
+
"@aigne/core": "^1.61.0-beta"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/bun": "^1.2.
|
|
47
|
-
"@types/node": "^24.
|
|
46
|
+
"@types/bun": "^1.2.22",
|
|
47
|
+
"@types/node": "^24.5.1",
|
|
48
48
|
"npm-run-all": "^4.1.5",
|
|
49
49
|
"rimraf": "^6.0.1",
|
|
50
|
-
"typescript": "^5.
|
|
51
|
-
"@aigne/test-utils": "^0.5.
|
|
50
|
+
"typescript": "^5.9.2",
|
|
51
|
+
"@aigne/test-utils": "^0.5.53-beta"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"lint": "tsc --noEmit",
|