chore: Move zod to peer deps (#1837)

This commit is contained in:
Marcus Schiesser
2025-04-10 13:17:26 +02:00
committed by GitHub
parent 2ffdb274f2
commit 88b7046c68
6 changed files with 65 additions and 14 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@llamaindex/openai": patch
---
Make zod a peer dependency
+3 -3
View File
@@ -31,12 +31,12 @@
"test": "vitest"
},
"devDependencies": {
"bunchee": "6.4.0"
"bunchee": "6.4.0",
"zod": "^3.24.2"
},
"dependencies": {
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*",
"openai": "^4.90.0",
"zod": "^3.24.2"
"openai": "^4.90.0"
}
}
+2 -2
View File
@@ -36,7 +36,6 @@ import type {
ResponseFormatJSONObject,
ResponseFormatJSONSchema,
} from "openai/resources/index.js";
import { z } from "zod";
import {
AzureOpenAIWithUserAgent,
getAzureConfigFromEnv,
@@ -279,7 +278,8 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
//add response format for the structured output
if (responseFormat && this.metadata.structuredOutput) {
if (responseFormat instanceof z.ZodType)
// Check if it's a ZodType by looking for its parse and safeParse methods
if ("parse" in responseFormat && "safeParse" in responseFormat)
baseRequestParams.response_format = zodResponseFormat(
responseFormat,
"response_format",
@@ -0,0 +1,46 @@
import { describe, expect, it } from "vitest";
import { z } from "zod";
import { OpenAI } from "../src/llm";
const API_KEY = process.env.OPENAI_API_KEY;
describe("OpenAI Chat Tests", () => {
if (!API_KEY) {
describe.skip("OpenAI API key not found skipping tests");
return;
}
describe("responseFormat with Zod schema", () => {
it("should handle zod schema as responseFormat", async () => {
// Define a zod schema for the response format
const exampleSchema = z.object({
name: z.string(),
});
const llm = new OpenAI({
model: "gpt-4o-mini",
apiKey: API_KEY,
});
// Call the chat method with the zod schema as responseFormat
const response = await llm.chat({
messages: [
{
role: "user",
content: "Extract my name: Bernd",
},
],
responseFormat: exampleSchema,
});
// Verify the response
expect(response.message.content).toBeDefined();
// Parse the response content as JSON
const parsedContent = JSON.parse(response.message.content as string);
// Verify the structure matches our schema
expect(parsedContent).toHaveProperty("name");
});
});
});
@@ -11,7 +11,7 @@ describe("OpenAIResponses Integration Tests", () => {
}
const llm = new OpenAIResponses({
model: "gpt-4o",
model: "gpt-4o-mini",
apiKey: API_KEY,
});
@@ -97,7 +97,7 @@ describe("OpenAIResponses Unit Tests", () => {
// Testing utility functions
describe("processMessageContent", () => {
const llm = new OpenAIResponses({
model: "gpt-4o",
model: "gpt-4o-mini",
apiKey: "test",
});
@@ -185,7 +185,7 @@ describe("OpenAIResponses Unit Tests", () => {
describe("isResponseCreatedEvent", () => {
const llm = new OpenAIResponses({
model: "gpt-4o",
model: "gpt-4o-mini",
apiKey: "test",
});
@@ -204,7 +204,7 @@ describe("OpenAIResponses Unit Tests", () => {
describe("isFunctionCall", () => {
const llm = new OpenAIResponses({
model: "gpt-4o",
model: "gpt-4o-mini",
apiKey: "test",
});
+5 -5
View File
@@ -1342,13 +1342,13 @@ importers:
openai:
specifier: ^4.90.0
version: 4.90.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2)
zod:
specifier: ^3.24.2
version: 3.24.2
devDependencies:
bunchee:
specifier: 6.4.0
version: 6.4.0(typescript@5.7.3)
zod:
specifier: ^3.24.2
version: 3.24.2
packages/providers/perplexity:
dependencies:
@@ -20018,7 +20018,7 @@ snapshots:
transitivePeerDependencies:
- supports-color
eslint-module-utils@2.12.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.22.0(jiti@2.4.2)):
eslint-module-utils@2.12.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0)(eslint@9.22.0(jiti@2.4.2)):
dependencies:
debug: 3.2.7
optionalDependencies:
@@ -20069,7 +20069,7 @@ snapshots:
doctrine: 2.1.0
eslint: 9.22.0(jiti@2.4.2)
eslint-import-resolver-node: 0.3.9
eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.22.0(jiti@2.4.2))
eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0)(eslint@9.22.0(jiti@2.4.2))
hasown: 2.0.2
is-core-module: 2.16.1
is-glob: 4.0.3