From 988978a54812544f20b4b6a63964453aebc250fe Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 19 Nov 2025 19:20:03 +0100 Subject: [PATCH] Fix: unify Zod version across workspaces + migrate OpenAI API to responses.parse --- apps/server/src/ai/open-ai-service.ts | 20 +++++++++++--------- package.json | 3 +++ packages/common/package.json | 8 +++++++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/apps/server/src/ai/open-ai-service.ts b/apps/server/src/ai/open-ai-service.ts index 8558f95f..a18af441 100644 --- a/apps/server/src/ai/open-ai-service.ts +++ b/apps/server/src/ai/open-ai-service.ts @@ -1,5 +1,4 @@ import OpenAI from 'openai'; -import { zodResponseFormat } from 'openai/helpers/zod'; import { z } from 'zod'; let openAIClient: OpenAI | undefined; @@ -12,26 +11,29 @@ if (process.env.OPENAI_API_KEY && process.env.OPENAI_PROJECT_ID && process.env.O } const BookInsights = z.object({ - genres: z.string().array(), + genres: z.array(z.string()), summary: z.string(), }); export async function getBookInsights(bookTitle: string, bookAuthor: string) { - const completion = await openAIClient?.beta.chat.completions.parse({ - model: 'gpt-4o', - messages: [ + if (!openAIClient) return; + + const completion = await openAIClient.responses.parse({ + model: 'gpt-4o-mini', // oder: gpt-4o + input: [ { role: 'system', content: - 'You are an expert librarian. You know everything about every book. Respond with details about the book given the title and author', + 'You are an expert librarian. Respond with details about the book given title + author.', }, { role: 'user', - content: `What can you tell me about the book ${bookTitle} by ${bookAuthor}`, + content: `What can you tell me about the book "${bookTitle}" by ${bookAuthor}?`, }, ], - response_format: zodResponseFormat(BookInsights, 'book_insights'), + schema: BookInsights, }); - return completion?.choices[0].message.parsed; + return completion.output; } + diff --git a/package.json b/package.json index 3c69dde6..ed876cb3 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,9 @@ "engines": { "node": ">=22" }, + "resolutions": { + "zod": "3.23.8" + }, "workspaces": [ "apps/*", "packages/*" diff --git a/packages/common/package.json b/packages/common/package.json index e9527fa9..d354c6cb 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -6,5 +6,11 @@ "scripts": { "build": "tsc", "dev": "tsc --watch" - } + }, + "peerDependencies": { + "zod": "^3.23.0" + }, + "devDependencies": { + "zod": "^3.23.0" + } }