From 15d4c99a78aab12dc03bdcf416663e5f7f3f1cad Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Tue, 20 Aug 2024 10:53:28 -0700 Subject: [PATCH] openai[minor]: Add JSON schema and strict WSO example to JSDoc (#6578) * openai[minor]: Add JSON schema and strict WSO example to JSDoc * chore: lint files --- libs/langchain-openai/src/chat_models.ts | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/libs/langchain-openai/src/chat_models.ts b/libs/langchain-openai/src/chat_models.ts index 381f05aaef77..0a93c9d1b138 100644 --- a/libs/langchain-openai/src/chat_models.ts +++ b/libs/langchain-openai/src/chat_models.ts @@ -787,6 +787,51 @@ export interface ChatOpenAIFields * * *
+ * + *
+ * JSON Schema Structured Output + * + * ```typescript + * const llmForJsonSchema = new ChatOpenAI({ + * model: "gpt-4o-2024-08-06", + * }).withStructuredOutput( + * z.object({ + * command: z.string().describe("The command to execute"), + * expectedOutput: z.string().describe("The expected output of the command"), + * options: z + * .array(z.string()) + * .describe("The options you can pass to the command"), + * }), + * { + * method: "jsonSchema", + * strict: true, // Optional when using the `jsonSchema` method + * } + * ); + * + * const jsonSchemaRes = await llmForJsonSchema.invoke( + * "What is the command to list files in a directory?" + * ); + * console.log(jsonSchemaRes); + * ``` + * + * ```txt + * { + * command: 'ls', + * expectedOutput: 'A list of files and subdirectories within the specified directory.', + * options: [ + * '-a: include directory entries whose names begin with a dot (.).', + * '-l: use a long listing format.', + * '-h: with -l, print sizes in human readable format (e.g., 1K, 234M, 2G).', + * '-t: sort by time, newest first.', + * '-r: reverse order while sorting.', + * '-S: sort by file size, largest first.', + * '-R: list subdirectories recursively.' + * ] + * } + * ``` + *
+ * + *
*/ export class ChatOpenAI< CallOptions extends ChatOpenAICallOptions = ChatOpenAICallOptions