@langchain/openai
Advanced tools
Comparing version
@@ -7,4 +7,3 @@ import { type ClientOptions, OpenAI as OpenAIClient } from "openai"; | ||
import { BaseChatModel, type BaseChatModelParams } from "@langchain/core/language_models/chat_models"; | ||
import type { BaseFunctionCallOptions, BaseLanguageModelInput } from "@langchain/core/language_models/base"; | ||
import { z } from "zod"; | ||
import type { BaseFunctionCallOptions, BaseLanguageModelInput, StructuredOutputMethodParams } from "@langchain/core/language_models/base"; | ||
import { Runnable } from "@langchain/core/runnables"; | ||
@@ -146,17 +145,7 @@ import type { AzureOpenAIInput, OpenAICallOptions, OpenAIChatInput, OpenAICoreRequestOptions, LegacyOpenAIInput } from "./types.js"; | ||
_combineLLMOutput(...llmOutputs: OpenAILLMOutput[]): OpenAILLMOutput; | ||
withStructuredOutput<RunInput = BaseLanguageModelInput, RunOutput extends z.ZodObject<any, any, any, any> = z.ZodObject<any, any, any, any>>({ schema, name, method, includeRaw, }: { | ||
schema: z.ZodEffects<RunOutput> | Record<string, any>; | ||
name: string; | ||
method?: "functionCalling" | "jsonMode"; | ||
includeRaw: true; | ||
}): Runnable<RunInput, { | ||
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>({ schema, name, method, includeRaw, }: StructuredOutputMethodParams<RunOutput, false>): Runnable<BaseLanguageModelInput, RunOutput>; | ||
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>({ schema, name, method, includeRaw, }: StructuredOutputMethodParams<RunOutput, true>): Runnable<BaseLanguageModelInput, { | ||
raw: BaseMessage; | ||
parsed: RunOutput; | ||
}>; | ||
withStructuredOutput<RunInput = BaseLanguageModelInput, RunOutput extends z.ZodObject<any, any, any, any> = z.ZodObject<any, any, any, any>>({ schema, name, method, includeRaw, }: { | ||
schema: z.ZodEffects<RunOutput> | Record<string, any>; | ||
name: string; | ||
method?: "functionCalling" | "jsonMode"; | ||
includeRaw?: false; | ||
}): Runnable<RunInput, RunOutput>; | ||
} |
@@ -717,14 +717,3 @@ import { OpenAI as OpenAIClient } from "openai"; | ||
} | ||
/** | ||
* Model wrapper that returns outputs formatted to match the given schema. | ||
* | ||
* @template {z.ZodObject<any, any, any, any>} RunOutput The output type for the Runnable, expected to be a Zod schema object for structured output validation. | ||
* | ||
* @param {z.ZodEffects<RunOutput>} schema The schema for the structured output. Either as a Zod schema or a valid JSON schema object. | ||
* @param {string} name The name of the function to call. | ||
* @param {"functionCalling" | "jsonMode"} method The method to use for getting the structured output. Defaults to "functionCalling". | ||
* @param {boolean | undefined} includeRaw Whether to include the raw output in the result. Defaults to false. | ||
* @returns {Runnable<RunInput, RunOutput> | Runnable<RunInput, { raw: BaseMessage; parsed: RunOutput }>} A new runnable that calls the LLM with structured output. | ||
*/ | ||
withStructuredOutput({ schema, name, method = "functionCalling", includeRaw = false, }) { | ||
withStructuredOutput({ schema, name, method, includeRaw, }) { | ||
let llm; | ||
@@ -739,2 +728,3 @@ let outputParser; | ||
else { | ||
const functionName = name ?? "extract"; | ||
// Is function calling | ||
@@ -754,7 +744,12 @@ if (isZodSchema(schema)) { | ||
], | ||
tool_choice: "auto", | ||
tool_choice: { | ||
type: "function", | ||
function: { | ||
name: functionName, | ||
}, | ||
}, | ||
}); | ||
outputParser = new JsonOutputKeyToolsParser({ | ||
returnSingle: true, | ||
keyName: name, | ||
keyName: functionName, | ||
}); | ||
@@ -774,7 +769,12 @@ } | ||
], | ||
tool_choice: "auto", | ||
tool_choice: { | ||
type: "function", | ||
function: { | ||
name, | ||
}, | ||
}, | ||
}); | ||
outputParser = new JsonOutputKeyToolsParser({ | ||
returnSingle: true, | ||
keyName: name, | ||
keyName: functionName, | ||
}); | ||
@@ -781,0 +781,0 @@ } |
{ | ||
"name": "@langchain/openai", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "OpenAI integrations for LangChain.js", | ||
@@ -42,3 +42,3 @@ "type": "module", | ||
"dependencies": { | ||
"@langchain/core": "~0.1.39", | ||
"@langchain/core": "~0.1.41", | ||
"js-tiktoken": "^1.0.7", | ||
@@ -45,0 +45,0 @@ "openai": "^4.26.0", |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
-100%270126
-0.51%6886
-0.16%Updated