-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
openai[minor]: Add support for json schema response format #6438
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
…to brace/openai-res-format-json-schema
…to brace/openai-res-format-json-schema
…to brace/openai-res-format-json-schema
Hello @bracesproul is there any example on how should this be used? |
Got it working: const model = new ChatOpenAI({
model: "gpt-4o-mini",
}).bind({
response_format: {
type: "json_schema",
json_schema: {
name: "schemaName",
schema: zodSchema,
},
},
});
const parser = StructuredOutputParser.fromZodSchema(zodSchema);
const typedResponse = await prompt.pipe(model).pipe(parser) |
Hi @bracesproul , nice to meet you. I'm currently working on LangChain.js with the Gmail Toolkit (specifically GmailCreateDraft), along with LangSmith and OpenAI. I noticed an issue with the function calling when using optional fields defined with Zod. Although fields like cc and bcc are marked as optional in the toolkit, it seems that the function is requiring all fields to be included. After investigating, I found that the zodToJsonSchema function automatically inserts some default values, which causes the resulting JSON schema to not align with the expected requirements. |
…-ai#6438) * openai[minor]: Add support for json schema response format * cr * lowkey I did it? * add tests and more implementation details * fix build yo * cr * fix build
port of https://github.com/langchain-ai/langchain/pull/25123/files
Closes #6477
Closes #6479
Requires a release of
@langchain/core
and bumping min core version of oai