@aigne/openai 0.16.0-beta.4 → 0.16.0-beta.6

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.16.0-beta.6](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.16.0-beta.5...openai-v0.16.0-beta.6) (2025-09-25)
4
+
5
+
6
+ ### Features
7
+
8
+ * **core:** add automatic JSON parsing and validation for structured outputs ([#548](https://github.com/AIGNE-io/aigne-framework/issues/548)) ([9077f93](https://github.com/AIGNE-io/aigne-framework/commit/9077f93856865915aaf5e8caa5638ef0b7f05b1e))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @aigne/core bumped to 1.61.0-beta.5
16
+ * devDependencies
17
+ * @aigne/test-utils bumped to 0.5.53-beta.5
18
+
19
+ ## [0.16.0-beta.5](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.16.0-beta.4...openai-v0.16.0-beta.5) (2025-09-25)
20
+
21
+
22
+ ### Dependencies
23
+
24
+ * The following workspace dependencies were updated
25
+ * dependencies
26
+ * @aigne/core bumped to 1.61.0-beta.4
27
+ * devDependencies
28
+ * @aigne/test-utils bumped to 0.5.53-beta.4
29
+
3
30
  ## [0.16.0-beta.4](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.16.0-beta.3...openai-v0.16.0-beta.4) (2025-09-24)
4
31
 
5
32
 
@@ -134,7 +134,6 @@ export declare class OpenAIChatModel extends ChatModel {
134
134
  * @returns The generated response
135
135
  */
136
136
  process(input: ChatModelInput, _options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
137
- private ajv;
138
137
  private _process;
139
138
  private getParallelToolCalls;
140
139
  protected getRunMessages(input: ChatModelInput): Promise<ChatCompletionMessageParam[]>;
@@ -9,7 +9,6 @@ const model_utils_js_1 = require("@aigne/core/utils/model-utils.js");
9
9
  const prompts_js_1 = require("@aigne/core/utils/prompts.js");
10
10
  const stream_utils_js_1 = require("@aigne/core/utils/stream-utils.js");
11
11
  const type_utils_js_1 = require("@aigne/core/utils/type-utils.js");
12
- const ajv_1 = require("ajv");
13
12
  const uuid_1 = require("uuid");
14
13
  const zod_1 = require("zod");
15
14
  const openai_js_1 = require("./openai.js");
@@ -106,7 +105,6 @@ class OpenAIChatModel extends core_1.ChatModel {
106
105
  process(input, _options) {
107
106
  return this._process(input);
108
107
  }
109
- ajv = new ajv_1.Ajv();
110
108
  async _process(input) {
111
109
  const messages = await this.getRunMessages(input);
112
110
  const model = input.modelOptions?.model || this.credential.model;
@@ -149,8 +147,11 @@ class OpenAIChatModel extends core_1.ChatModel {
149
147
  // Try to parse the text response as JSON
150
148
  // If it matches the json_schema, return it as json
151
149
  const json = (0, core_1.safeParseJSON)(result.text || "");
152
- if (this.ajv.validate(input.responseFormat.jsonSchema.schema, json)) {
153
- return { ...result, json, text: undefined };
150
+ const validated = this.validateJsonSchema(input.responseFormat.jsonSchema.schema, json, {
151
+ safe: true,
152
+ });
153
+ if (validated.success) {
154
+ return { ...result, json: validated.data, text: undefined };
154
155
  }
155
156
  logger_js_1.logger.warn(`${this.name}: Text response does not match JSON schema, trying to use tool to extract json `, {
156
157
  text: result.text,
@@ -134,7 +134,6 @@ export declare class OpenAIChatModel extends ChatModel {
134
134
  * @returns The generated response
135
135
  */
136
136
  process(input: ChatModelInput, _options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
137
- private ajv;
138
137
  private _process;
139
138
  private getParallelToolCalls;
140
139
  protected getRunMessages(input: ChatModelInput): Promise<ChatCompletionMessageParam[]>;
@@ -134,7 +134,6 @@ export declare class OpenAIChatModel extends ChatModel {
134
134
  * @returns The generated response
135
135
  */
136
136
  process(input: ChatModelInput, _options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
137
- private ajv;
138
137
  private _process;
139
138
  private getParallelToolCalls;
140
139
  protected getRunMessages(input: ChatModelInput): Promise<ChatCompletionMessageParam[]>;
@@ -4,7 +4,6 @@ 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 { Ajv } from "ajv";
8
7
  import { v7 } from "uuid";
9
8
  import { z } from "zod";
10
9
  import { CustomOpenAI } from "./openai.js";
@@ -101,7 +100,6 @@ export class OpenAIChatModel extends ChatModel {
101
100
  process(input, _options) {
102
101
  return this._process(input);
103
102
  }
104
- ajv = new Ajv();
105
103
  async _process(input) {
106
104
  const messages = await this.getRunMessages(input);
107
105
  const model = input.modelOptions?.model || this.credential.model;
@@ -144,8 +142,11 @@ export class OpenAIChatModel extends ChatModel {
144
142
  // Try to parse the text response as JSON
145
143
  // If it matches the json_schema, return it as json
146
144
  const json = safeParseJSON(result.text || "");
147
- if (this.ajv.validate(input.responseFormat.jsonSchema.schema, json)) {
148
- return { ...result, json, text: undefined };
145
+ const validated = this.validateJsonSchema(input.responseFormat.jsonSchema.schema, json, {
146
+ safe: true,
147
+ });
148
+ if (validated.success) {
149
+ return { ...result, json: validated.data, text: undefined };
149
150
  }
150
151
  logger.warn(`${this.name}: Text response does not match JSON schema, trying to use tool to extract json `, {
151
152
  text: result.text,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/openai",
3
- "version": "0.16.0-beta.4",
3
+ "version": "0.16.0-beta.6",
4
4
  "description": "AIGNE OpenAI SDK for integrating with OpenAI's GPT models and API services",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -35,11 +35,10 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "ajv": "^8.17.1",
39
38
  "openai": "^5.20.3",
40
39
  "uuid": "^13.0.0",
41
40
  "zod": "^3.25.67",
42
- "@aigne/core": "^1.61.0-beta.3",
41
+ "@aigne/core": "^1.61.0-beta.5",
43
42
  "@aigne/platform-helpers": "^0.6.3-beta"
44
43
  },
45
44
  "devDependencies": {
@@ -48,7 +47,7 @@
48
47
  "npm-run-all": "^4.1.5",
49
48
  "rimraf": "^6.0.1",
50
49
  "typescript": "^5.9.2",
51
- "@aigne/test-utils": "^0.5.53-beta.3"
50
+ "@aigne/test-utils": "^0.5.53-beta.5"
52
51
  },
53
52
  "scripts": {
54
53
  "lint": "tsc --noEmit",