@langchain/openai 1.2.0-dev-1765432861398 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/dist/chat_models/base.cjs +62 -0
- package/dist/chat_models/base.cjs.map +1 -1
- package/dist/chat_models/base.d.cts +53 -3
- package/dist/chat_models/base.d.cts.map +1 -1
- package/dist/chat_models/base.d.ts +53 -3
- package/dist/chat_models/base.d.ts.map +1 -1
- package/dist/chat_models/base.js +62 -0
- package/dist/chat_models/base.js.map +1 -1
- package/dist/chat_models/completions.cjs +1 -0
- package/dist/chat_models/completions.cjs.map +1 -1
- package/dist/chat_models/completions.js +1 -0
- package/dist/chat_models/completions.js.map +1 -1
- package/dist/chat_models/index.cjs +2 -1
- package/dist/chat_models/index.cjs.map +1 -1
- package/dist/chat_models/index.d.cts +1 -1
- package/dist/chat_models/index.d.cts.map +1 -1
- package/dist/chat_models/index.d.ts +1 -1
- package/dist/chat_models/index.d.ts.map +1 -1
- package/dist/chat_models/index.js +2 -1
- package/dist/chat_models/index.js.map +1 -1
- package/dist/chat_models/responses.cjs +2 -1
- package/dist/chat_models/responses.cjs.map +1 -1
- package/dist/chat_models/responses.js +2 -1
- package/dist/chat_models/responses.js.map +1 -1
- package/dist/converters/completions.cjs +3 -8
- package/dist/converters/completions.cjs.map +1 -1
- package/dist/converters/completions.js +3 -8
- package/dist/converters/completions.js.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/types.d.cts +6 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/misc.cjs +4 -0
- package/dist/utils/misc.cjs.map +1 -1
- package/dist/utils/misc.d.cts.map +1 -1
- package/dist/utils/misc.d.ts.map +1 -1
- package/dist/utils/misc.js +4 -1
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/output.cjs +2 -1
- package/dist/utils/output.cjs.map +1 -1
- package/dist/utils/output.js +3 -2
- package/dist/utils/output.js.map +1 -1
- package/package.json +5 -5
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":["OpenAI","OpenAIClient","ClientOptions","ResponseFormatText","ResponseFormatJSONObject","ResponseFormatJSONSchema","ResponseFormatTextPython","ResponseFormatTextGrammar","TiktokenModel","BaseLanguageModelCallOptions","InteropZodObject","OpenAIChatModelId","ChatModel","NonNullable","OpenAIVerbosityParam","OpenAIApiKey","OpenAIBaseInput","Record","OpenAICoreRequestOptions","RequestOptions","OpenAICallOptions","OpenAIInput","OpenAIChatInput","Chat","ChatCompletionMessageParam","ChatCompletionModality","Array","ChatCompletionAudioParam","Reasoning","Responses","ResponseCreateParams","AzureOpenAIInput","Promise","AzureOpenAIChatInput","ChatOpenAIResponseFormatJSONSchema","Omit","ChatOpenAIReasoningSummary","ResponseReasoningItem","Summary","ChatOpenAIResponseFormat","ResponseFormatConfiguration"],"sources":["../src/types.d.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient, ClientOptions } from \"openai\";\nimport type { ResponseFormatText, ResponseFormatJSONObject, ResponseFormatJSONSchema, ResponseFormatTextPython, ResponseFormatTextGrammar } from \"openai/resources/shared\";\nimport { TiktokenModel } from \"js-tiktoken/lite\";\nimport type { BaseLanguageModelCallOptions } from \"@langchain/core/language_models/base\";\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\nexport type { TiktokenModel };\n/**\n * @see https://platform.openai.com/docs/models\n */\nexport type OpenAIChatModelId = OpenAIClient.ChatModel | (string & NonNullable<unknown>);\nexport type OpenAIVerbosityParam = \"low\" | \"medium\" | \"high\" | null;\nexport type OpenAIApiKey = ClientOptions[\"apiKey\"];\nexport declare interface OpenAIBaseInput {\n /** Sampling temperature to use */\n temperature: number;\n /**\n * Maximum number of tokens to generate in the completion. -1 returns as many\n * tokens as possible given the prompt and the model's maximum context size.\n */\n maxTokens?: number;\n /**\n * Maximum number of tokens to generate in the completion. -1 returns as many\n * tokens as possible given the prompt and the model's maximum context size.\n * Alias for `maxTokens` for reasoning models.\n */\n maxCompletionTokens?: number;\n /** Total probability mass of tokens to consider at each step */\n topP: number;\n /** Penalizes repeated tokens according to frequency */\n frequencyPenalty: number;\n /** Penalizes repeated tokens */\n presencePenalty: number;\n /** Number of completions to generate for each prompt */\n n: number;\n /** Dictionary used to adjust the probability of specific tokens being generated */\n logitBias?: Record<string, number>;\n /** Unique string identifier representing your end-user, which can help OpenAI to monitor and detect abuse. */\n user?: string;\n /** Whether to stream the results or not. Enabling disables tokenUsage reporting */\n streaming: boolean;\n /**\n * Whether or not to include token usage data in streamed chunks.\n * @default true\n */\n streamUsage?: boolean;\n /**\n * Model name to use\n * Alias for `model`\n * @deprecated Use \"model\" instead.\n */\n modelName: string;\n /** Model name to use */\n model: OpenAIChatModelId;\n /** Holds any additional parameters that are valid to pass to {@link\n * https://platform.openai.com/docs/api-reference/completions/create |\n * `openai.createCompletion`} that are not explicitly specified on this class.\n */\n modelKwargs?: Record<string, any>;\n /**\n * List of stop words to use when generating\n * Alias for `stopSequences`\n */\n stop?: string[];\n /** List of stop words to use when generating */\n stopSequences?: string[];\n /**\n * Timeout to use when making requests to OpenAI.\n */\n timeout?: number;\n /**\n * API key to use when making requests to OpenAI. Defaults to the value of\n * `OPENAI_API_KEY` environment variable.\n * Alias for `apiKey`\n */\n openAIApiKey?: OpenAIApiKey;\n /**\n * API key to use when making requests to OpenAI. Defaults to the value of\n * `OPENAI_API_KEY` environment variable.\n */\n apiKey?: OpenAIApiKey;\n /**\n * The verbosity of the model's response.\n */\n verbosity?: OpenAIVerbosityParam;\n}\nexport type OpenAICoreRequestOptions = OpenAIClient.RequestOptions;\nexport interface OpenAICallOptions extends BaseLanguageModelCallOptions {\n /**\n * Additional options to pass to the underlying axios request.\n */\n options?: OpenAICoreRequestOptions;\n}\n/**\n * Input to OpenAI class.\n */\nexport declare interface OpenAIInput extends OpenAIBaseInput {\n /** Generates `bestOf` completions server side and returns the \"best\" */\n bestOf?: number;\n /** Batch size to use when passing multiple documents to generate */\n batchSize: number;\n}\nexport interface OpenAIChatInput extends OpenAIBaseInput {\n /**\n * Whether to return log probabilities of the output tokens or not.\n * If true, returns the log probabilities of each output token returned in the content of message.\n */\n logprobs?: boolean;\n /**\n * An integer between 0 and 5 specifying the number of most likely tokens to return at each token position,\n * each with an associated log probability. logprobs must be set to true if this parameter is used.\n */\n topLogprobs?: number;\n /** ChatGPT messages to pass as a prefix to the prompt */\n prefixMessages?: OpenAIClient.Chat.ChatCompletionMessageParam[];\n /**\n * Whether to include the raw OpenAI response in the output message's \"additional_kwargs\" field.\n * Currently in experimental beta.\n */\n __includeRawResponse?: boolean;\n /**\n * Whether the model supports the `strict` argument when passing in tools.\n * If `undefined` the `strict` argument will not be passed to OpenAI.\n */\n supportsStrictToolCalling?: boolean;\n /**\n * Output types that you would like the model to generate for this request. Most\n * models are capable of generating text, which is the default:\n *\n * `[\"text\"]`\n *\n * The `gpt-4o-audio-preview` model can also be used to\n * [generate audio](https://platform.openai.com/docs/guides/audio). To request that\n * this model generate both text and audio responses, you can use:\n *\n * `[\"text\", \"audio\"]`\n */\n modalities?: Array<OpenAIClient.Chat.ChatCompletionModality>;\n /**\n * Parameters for audio output. Required when audio output is requested with\n * `modalities: [\"audio\"]`.\n * [Learn more](https://platform.openai.com/docs/guides/audio).\n */\n audio?: OpenAIClient.Chat.ChatCompletionAudioParam;\n /**\n * Options for reasoning models.\n *\n * Note that some options, like reasoning summaries, are only available when using the responses\n * API. This option is ignored when not using a reasoning model.\n */\n reasoning?: OpenAIClient.Reasoning;\n /**\n * Should be set to `true` in tenancies with Zero Data Retention\n * @see https://platform.openai.com/docs/guides/your-data\n *\n * @default false\n */\n zdrEnabled?: boolean;\n /**\n * Service tier to use for this request. Can be \"auto\", \"default\", or \"flex\" or \"priority\".\n * Specifies the service tier for prioritization and latency optimization.\n */\n service_tier?: OpenAIClient.Responses.ResponseCreateParams[\"service_tier\"];\n /**\n * Used by OpenAI to cache responses for similar requests to optimize your cache\n * hit rates. Replaces the `user` field.\n * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).\n */\n promptCacheKey?: string;\n}\nexport interface AzureOpenAIInput {\n /**\n * API version to use when making requests to Azure OpenAI.\n */\n azureOpenAIApiVersion?: string;\n /**\n * API key to use when making requests to Azure OpenAI.\n */\n azureOpenAIApiKey?: string;\n /**\n * Azure OpenAI API instance name to use when making requests to Azure OpenAI.\n * this is the name of the instance you created in the Azure portal.\n * e.g. \"my-openai-instance\"\n * this will be used in the endpoint URL: https://my-openai-instance.openai.azure.com/openai/deployments/{DeploymentName}/\n */\n azureOpenAIApiInstanceName?: string;\n /**\n * Azure OpenAI API deployment name to use for completions when making requests to Azure OpenAI.\n * This is the name of the deployment you created in the Azure portal.\n * e.g. \"my-openai-deployment\"\n * this will be used in the endpoint URL: https://{InstanceName}.openai.azure.com/openai/deployments/my-openai-deployment/\n */\n azureOpenAIApiDeploymentName?: string;\n /**\n * Azure OpenAI API deployment name to use for embedding when making requests to Azure OpenAI.\n * This is the name of the deployment you created in the Azure portal.\n * This will fallback to azureOpenAIApiDeploymentName if not provided.\n * e.g. \"my-openai-deployment\"\n * this will be used in the endpoint URL: https://{InstanceName}.openai.azure.com/openai/deployments/my-openai-deployment/\n */\n azureOpenAIApiEmbeddingsDeploymentName?: string;\n /**\n * Azure OpenAI API deployment name to use for completions when making requests to Azure OpenAI.\n * Completions are only available for gpt-3.5-turbo and text-davinci-003 deployments.\n * This is the name of the deployment you created in the Azure portal.\n * This will fallback to azureOpenAIApiDeploymentName if not provided.\n * e.g. \"my-openai-deployment\"\n * this will be used in the endpoint URL: https://{InstanceName}.openai.azure.com/openai/deployments/my-openai-deployment/\n */\n azureOpenAIApiCompletionsDeploymentName?: string;\n /**\n * Custom base url for Azure OpenAI API. This is useful in case you have a deployment in another region.\n * e.g. setting this value to \"https://westeurope.api.cognitive.microsoft.com/openai/deployments\"\n * will be result in the endpoint URL: https://westeurope.api.cognitive.microsoft.com/openai/deployments/{DeploymentName}/\n */\n azureOpenAIBasePath?: string;\n /**\n * Custom endpoint for Azure OpenAI API. This is useful in case you have a deployment in another region.\n * e.g. setting this value to \"https://westeurope.api.cognitive.microsoft.com/\"\n * will be result in the endpoint URL: https://westeurope.api.cognitive.microsoft.com/openai/deployments/{DeploymentName}/\n */\n azureOpenAIEndpoint?: string;\n /**\n * A function that returns an access token for Microsoft Entra (formerly known as Azure Active Directory),\n * which will be invoked on every request.\n */\n azureADTokenProvider?: () => Promise<string>;\n}\nexport interface AzureOpenAIChatInput extends OpenAIChatInput, AzureOpenAIInput {\n openAIApiVersion?: string;\n openAIBasePath?: string;\n deploymentName?: string;\n}\ntype ChatOpenAIResponseFormatJSONSchema = Omit<ResponseFormatJSONSchema, \"json_schema\"> & {\n json_schema: Omit<ResponseFormatJSONSchema[\"json_schema\"], \"schema\"> & {\n /**\n * The schema for the response format, described as a JSON Schema object\n * or a Zod object.\n */\n schema: Record<string, any> | InteropZodObject;\n };\n};\n/**\n * The summary of a model's reasoning step.\n */\nexport type ChatOpenAIReasoningSummary = Omit<OpenAIClient.Responses.ResponseReasoningItem, \"summary\"> & {\n /**\n * The summary of the reasoning step. The index field will be populated if the response was\n * streamed. This allows LangChain to recompose the reasoning summary output correctly when the\n * AIMessage is used as an input for future generation requests.\n */\n summary: Array<OpenAIClient.Responses.ResponseReasoningItem.Summary & {\n index?: number;\n }>;\n};\nexport type ChatOpenAIResponseFormat = ResponseFormatText | ResponseFormatJSONObject | ResponseFormatTextGrammar | ResponseFormatTextPython | ChatOpenAIResponseFormatJSONSchema;\nexport type ResponseFormatConfiguration = ResponseFormatText | ResponseFormatJSONObject | ResponseFormatJSONSchema;\n//# sourceMappingURL=types.d.ts.map"],"mappings":";;;;;;;;;AASA;AACA;AACYe,KAFAJ,iBAAAA,GAAoBV,QAAAA,CAAaW,SAEL,GAAA,CAAA,MAAA,GAF2BC,WAE3B,CAAA,OAAA,CAAA,CAAA;AACfG,KAFbF,oBAAAA,GAE4B,KAAA,GAAA,QAAA,GAAA,MAAA,GAAA,IAAA;AAuBxBG,KAxBJF,YAAAA,GAAeb,aAwBXe,CAAAA,QAAAA,CAAAA;AAiBLN,kBAxCcK,eAAAA,CAwCdL;EAKOM;EAiBCF,WAAAA,EAAAA,MAAAA;EAKNA;;AAIuB;AAEpC;EACiBK,SAAAA,CAAAA,EAAAA,MAAAA;EASQC;AAMzB;;;;EAyCYpB,mBAAkB0B,CAAAA,EAAAA,MAAAA;EAOd1B;EAYGA,IAAAA,EAAa4B,MAAAA;EA5DSb;EAAe,gBAAA,EAAA,MAAA;EAoEvCe;EA0DAE,eAAAA,EAAAA,MAAoB;EAKhCC;EAA0C7B,CAAAA,EAAAA,MAAAA;EAAL8B;EACpB9B,SAAAA,CAAAA,EAtMNY,MAsMMZ,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EAAL8B;EAKDlB,IAAAA,CAAAA,EAAAA,MAAAA;EAAsBP;EAAgB,SAAA,EAAA,OAAA;EAM1C0B;;;;EAMCV,WAAAA,CAAAA,EAAAA,OAAAA;EAAK;AAIlB;;;;EAAmHpB,SAAAA,EAAAA,MAAAA;EAA2B4B;EAAkC,KAAA,EA1MrKvB,iBA0MqK;EACpK6B;;;;EAAsG,WAAA,CAAA,EAtMhGvB,MAsMgG,CAAA,MAAA,EAAA,GAAA,CAAA;;;;;;;;;;;;;;;;;iBArL/FF;;;;;WAKNA;;;;cAIGD;;KAEJI,wBAAAA,GAA2BjB,QAAAA,CAAakB;UACnCC,iBAAAA,SAA0BX;;;;YAI7BS;;;;;kBAKWG,WAAAA,SAAoBL;;;;;;UAM5BM,eAAAA,SAAwBN;;;;;;;;;;;;mBAYpBf,QAAAA,CAAasB,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;eAuBtBE,MAAMzB,QAAAA,CAAasB,IAAAA,CAAKE;;;;;;UAM7BxB,QAAAA,CAAasB,IAAAA,CAAKI;;;;;;;cAOd1B,QAAAA,CAAa2B;;;;;;;;;;;;iBAYV3B,QAAAA,CAAa4B,SAAAA,CAAUC;;;;;;;;UAQzBC,gBAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAwDgBC;;UAEhBC,oBAAAA,SAA6BX,iBAAiBS;;;;;KAK1DG,kCAAAA,GAAqCC,KAAK9B;eAC9B8B,KAAK9B;;;;;YAKNY,sBAAsBP;;;;;;KAM1B0B,0BAAAA,GAA6BD,KAAKlC,QAAAA,CAAa4B,SAAAA,CAAUQ;;;;;;WAMxDX,MAAMzB,QAAAA,CAAa4B,SAAAA,CAAUQ,qBAAAA,CAAsBC;;;;KAIpDC,wBAAAA,GAA2BpC,qBAAqBC,2BAA2BG,4BAA4BD,2BAA2B4B;KAClIM,2BAAAA,GAA8BrC,qBAAqBC,2BAA2BC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":["OpenAI","OpenAIClient","ClientOptions","ResponseFormatText","ResponseFormatJSONObject","ResponseFormatJSONSchema","ResponseFormatTextPython","ResponseFormatTextGrammar","TiktokenModel","BaseLanguageModelCallOptions","InteropZodObject","OpenAIChatModelId","ChatModel","NonNullable","OpenAIVerbosityParam","OpenAICacheRetentionParam","OpenAIApiKey","OpenAIBaseInput","Record","OpenAICoreRequestOptions","RequestOptions","OpenAICallOptions","OpenAIInput","OpenAIChatInput","Chat","ChatCompletionMessageParam","ChatCompletionModality","Array","ChatCompletionAudioParam","Reasoning","Responses","ResponseCreateParams","AzureOpenAIInput","Promise","AzureOpenAIChatInput","ChatOpenAIResponseFormatJSONSchema","Omit","ChatOpenAIReasoningSummary","ResponseReasoningItem","Summary","ChatOpenAIResponseFormat","ResponseFormatConfiguration"],"sources":["../src/types.d.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient, ClientOptions } from \"openai\";\nimport type { ResponseFormatText, ResponseFormatJSONObject, ResponseFormatJSONSchema, ResponseFormatTextPython, ResponseFormatTextGrammar } from \"openai/resources/shared\";\nimport { TiktokenModel } from \"js-tiktoken/lite\";\nimport type { BaseLanguageModelCallOptions } from \"@langchain/core/language_models/base\";\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\nexport type { TiktokenModel };\n/**\n * @see https://platform.openai.com/docs/models\n */\nexport type OpenAIChatModelId = OpenAIClient.ChatModel | (string & NonNullable<unknown>);\nexport type OpenAIVerbosityParam = \"low\" | \"medium\" | \"high\" | null;\nexport type OpenAICacheRetentionParam = \"in-memory\" | \"24h\" | null;\nexport type OpenAIApiKey = ClientOptions[\"apiKey\"];\nexport declare interface OpenAIBaseInput {\n /** Sampling temperature to use */\n temperature: number;\n /**\n * Maximum number of tokens to generate in the completion. -1 returns as many\n * tokens as possible given the prompt and the model's maximum context size.\n */\n maxTokens?: number;\n /**\n * Maximum number of tokens to generate in the completion. -1 returns as many\n * tokens as possible given the prompt and the model's maximum context size.\n * Alias for `maxTokens` for reasoning models.\n */\n maxCompletionTokens?: number;\n /** Total probability mass of tokens to consider at each step */\n topP: number;\n /** Penalizes repeated tokens according to frequency */\n frequencyPenalty: number;\n /** Penalizes repeated tokens */\n presencePenalty: number;\n /** Number of completions to generate for each prompt */\n n: number;\n /** Dictionary used to adjust the probability of specific tokens being generated */\n logitBias?: Record<string, number>;\n /** Unique string identifier representing your end-user, which can help OpenAI to monitor and detect abuse. */\n user?: string;\n /** Whether to stream the results or not. Enabling disables tokenUsage reporting */\n streaming: boolean;\n /**\n * Whether or not to include token usage data in streamed chunks.\n * @default true\n */\n streamUsage?: boolean;\n /**\n * Model name to use\n * Alias for `model`\n * @deprecated Use \"model\" instead.\n */\n modelName: string;\n /** Model name to use */\n model: OpenAIChatModelId;\n /** Holds any additional parameters that are valid to pass to {@link\n * https://platform.openai.com/docs/api-reference/completions/create |\n * `openai.createCompletion`} that are not explicitly specified on this class.\n */\n modelKwargs?: Record<string, any>;\n /**\n * List of stop words to use when generating\n * Alias for `stopSequences`\n */\n stop?: string[];\n /** List of stop words to use when generating */\n stopSequences?: string[];\n /**\n * Timeout to use when making requests to OpenAI.\n */\n timeout?: number;\n /**\n * API key to use when making requests to OpenAI. Defaults to the value of\n * `OPENAI_API_KEY` environment variable.\n * Alias for `apiKey`\n */\n openAIApiKey?: OpenAIApiKey;\n /**\n * API key to use when making requests to OpenAI. Defaults to the value of\n * `OPENAI_API_KEY` environment variable.\n */\n apiKey?: OpenAIApiKey;\n /**\n * The verbosity of the model's response.\n */\n verbosity?: OpenAIVerbosityParam;\n}\nexport type OpenAICoreRequestOptions = OpenAIClient.RequestOptions;\nexport interface OpenAICallOptions extends BaseLanguageModelCallOptions {\n /**\n * Additional options to pass to the underlying axios request.\n */\n options?: OpenAICoreRequestOptions;\n}\n/**\n * Input to OpenAI class.\n */\nexport declare interface OpenAIInput extends OpenAIBaseInput {\n /** Generates `bestOf` completions server side and returns the \"best\" */\n bestOf?: number;\n /** Batch size to use when passing multiple documents to generate */\n batchSize: number;\n}\nexport interface OpenAIChatInput extends OpenAIBaseInput {\n /**\n * Whether to return log probabilities of the output tokens or not.\n * If true, returns the log probabilities of each output token returned in the content of message.\n */\n logprobs?: boolean;\n /**\n * An integer between 0 and 5 specifying the number of most likely tokens to return at each token position,\n * each with an associated log probability. logprobs must be set to true if this parameter is used.\n */\n topLogprobs?: number;\n /** ChatGPT messages to pass as a prefix to the prompt */\n prefixMessages?: OpenAIClient.Chat.ChatCompletionMessageParam[];\n /**\n * Whether to include the raw OpenAI response in the output message's \"additional_kwargs\" field.\n * Currently in experimental beta.\n */\n __includeRawResponse?: boolean;\n /**\n * Whether the model supports the `strict` argument when passing in tools.\n * If `undefined` the `strict` argument will not be passed to OpenAI.\n */\n supportsStrictToolCalling?: boolean;\n /**\n * Output types that you would like the model to generate for this request. Most\n * models are capable of generating text, which is the default:\n *\n * `[\"text\"]`\n *\n * The `gpt-4o-audio-preview` model can also be used to\n * [generate audio](https://platform.openai.com/docs/guides/audio). To request that\n * this model generate both text and audio responses, you can use:\n *\n * `[\"text\", \"audio\"]`\n */\n modalities?: Array<OpenAIClient.Chat.ChatCompletionModality>;\n /**\n * Parameters for audio output. Required when audio output is requested with\n * `modalities: [\"audio\"]`.\n * [Learn more](https://platform.openai.com/docs/guides/audio).\n */\n audio?: OpenAIClient.Chat.ChatCompletionAudioParam;\n /**\n * Options for reasoning models.\n *\n * Note that some options, like reasoning summaries, are only available when using the responses\n * API. This option is ignored when not using a reasoning model.\n */\n reasoning?: OpenAIClient.Reasoning;\n /**\n * Should be set to `true` in tenancies with Zero Data Retention\n * @see https://platform.openai.com/docs/guides/your-data\n *\n * @default false\n */\n zdrEnabled?: boolean;\n /**\n * Service tier to use for this request. Can be \"auto\", \"default\", or \"flex\" or \"priority\".\n * Specifies the service tier for prioritization and latency optimization.\n */\n service_tier?: OpenAIClient.Responses.ResponseCreateParams[\"service_tier\"];\n /**\n * Used by OpenAI to cache responses for similar requests to optimize your cache\n * hit rates. Replaces the `user` field.\n * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).\n */\n promptCacheKey?: string;\n /**\n * Used by OpenAI to set cache retention time\n */\n promptCacheRetention?: OpenAICacheRetentionParam;\n}\nexport interface AzureOpenAIInput {\n /**\n * API version to use when making requests to Azure OpenAI.\n */\n azureOpenAIApiVersion?: string;\n /**\n * API key to use when making requests to Azure OpenAI.\n */\n azureOpenAIApiKey?: string;\n /**\n * Azure OpenAI API instance name to use when making requests to Azure OpenAI.\n * this is the name of the instance you created in the Azure portal.\n * e.g. \"my-openai-instance\"\n * this will be used in the endpoint URL: https://my-openai-instance.openai.azure.com/openai/deployments/{DeploymentName}/\n */\n azureOpenAIApiInstanceName?: string;\n /**\n * Azure OpenAI API deployment name to use for completions when making requests to Azure OpenAI.\n * This is the name of the deployment you created in the Azure portal.\n * e.g. \"my-openai-deployment\"\n * this will be used in the endpoint URL: https://{InstanceName}.openai.azure.com/openai/deployments/my-openai-deployment/\n */\n azureOpenAIApiDeploymentName?: string;\n /**\n * Azure OpenAI API deployment name to use for embedding when making requests to Azure OpenAI.\n * This is the name of the deployment you created in the Azure portal.\n * This will fallback to azureOpenAIApiDeploymentName if not provided.\n * e.g. \"my-openai-deployment\"\n * this will be used in the endpoint URL: https://{InstanceName}.openai.azure.com/openai/deployments/my-openai-deployment/\n */\n azureOpenAIApiEmbeddingsDeploymentName?: string;\n /**\n * Azure OpenAI API deployment name to use for completions when making requests to Azure OpenAI.\n * Completions are only available for gpt-3.5-turbo and text-davinci-003 deployments.\n * This is the name of the deployment you created in the Azure portal.\n * This will fallback to azureOpenAIApiDeploymentName if not provided.\n * e.g. \"my-openai-deployment\"\n * this will be used in the endpoint URL: https://{InstanceName}.openai.azure.com/openai/deployments/my-openai-deployment/\n */\n azureOpenAIApiCompletionsDeploymentName?: string;\n /**\n * Custom base url for Azure OpenAI API. This is useful in case you have a deployment in another region.\n * e.g. setting this value to \"https://westeurope.api.cognitive.microsoft.com/openai/deployments\"\n * will be result in the endpoint URL: https://westeurope.api.cognitive.microsoft.com/openai/deployments/{DeploymentName}/\n */\n azureOpenAIBasePath?: string;\n /**\n * Custom endpoint for Azure OpenAI API. This is useful in case you have a deployment in another region.\n * e.g. setting this value to \"https://westeurope.api.cognitive.microsoft.com/\"\n * will be result in the endpoint URL: https://westeurope.api.cognitive.microsoft.com/openai/deployments/{DeploymentName}/\n */\n azureOpenAIEndpoint?: string;\n /**\n * A function that returns an access token for Microsoft Entra (formerly known as Azure Active Directory),\n * which will be invoked on every request.\n */\n azureADTokenProvider?: () => Promise<string>;\n}\nexport interface AzureOpenAIChatInput extends OpenAIChatInput, AzureOpenAIInput {\n openAIApiVersion?: string;\n openAIBasePath?: string;\n deploymentName?: string;\n}\ntype ChatOpenAIResponseFormatJSONSchema = Omit<ResponseFormatJSONSchema, \"json_schema\"> & {\n json_schema: Omit<ResponseFormatJSONSchema[\"json_schema\"], \"schema\"> & {\n /**\n * The schema for the response format, described as a JSON Schema object\n * or a Zod object.\n */\n schema: Record<string, any> | InteropZodObject;\n };\n};\n/**\n * The summary of a model's reasoning step.\n */\nexport type ChatOpenAIReasoningSummary = Omit<OpenAIClient.Responses.ResponseReasoningItem, \"summary\"> & {\n /**\n * The summary of the reasoning step. The index field will be populated if the response was\n * streamed. This allows LangChain to recompose the reasoning summary output correctly when the\n * AIMessage is used as an input for future generation requests.\n */\n summary: Array<OpenAIClient.Responses.ResponseReasoningItem.Summary & {\n index?: number;\n }>;\n};\nexport type ChatOpenAIResponseFormat = ResponseFormatText | ResponseFormatJSONObject | ResponseFormatTextGrammar | ResponseFormatTextPython | ChatOpenAIResponseFormatJSONSchema;\nexport type ResponseFormatConfiguration = ResponseFormatText | ResponseFormatJSONObject | ResponseFormatJSONSchema;\n//# sourceMappingURL=types.d.ts.map"],"mappings":";;;;;;;;;AASA;AACA;AACYe,KAFAJ,iBAAAA,GAAoBV,QAAAA,CAAaW,SAER,GAAA,CAAA,MAAA,GAF8BC,WAE9B,CAAA,OAAA,CAAA,CAAA;AACzBG,KAFAF,oBAAAA,GAEeZ,KAAAA,GAAAA,QAAa,GAAA,MAAA,GAAA,IAAA;AACfe,KAFbF,yBAAAA,GAE4B,WAAA,GAAA,KAAA,GAAA,IAAA;AAuBxBG,KAxBJF,YAAAA,GAAed,aAwBXgB,CAAAA,QAAAA,CAAAA;AAiBLP,kBAxCcM,eAAAA,CAwCdN;EAKOO;EAiBCF,WAAAA,EAAAA,MAAAA;EAKNA;;AAIuB;AAEpC;EACiBK,SAAAA,CAAAA,EAAAA,MAAAA;EASQC;AAMzB;;;;EAyCYrB,mBAAkB2B,CAAAA,EAAAA,MAAAA;EAOd3B;EAYGA,IAAAA,EAAa6B,MAAAA;EAULf;EAtEcE,gBAAAA,EAAAA,MAAAA;EAAe;EAwEvCe,eAAAA,EAAAA,MAAgB;EA0DhBE;EAKZC,CAAAA,EAAAA,MAAAA;EAA0C9B;EAAL+B,SAAAA,CAAAA,EAzM1BlB,MAyM0BkB,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EACpB/B;EAAL+B,IAAAA,CAAAA,EAAAA,MAAAA;EAKDlB;EAAsBR,SAAAA,EAAAA,OAAAA;EAAgB;AAMtD;;;EAMmBT,WAAa6B,CAAAA,EAAAA,OAAUQ;EAA7BX;AAAK;AAIlB;;;EAAuFpB,SAAAA,EAAAA,MAAAA;EAA4BD;EAA2B6B,KAAAA,EA9MnIxB,iBA8MmIwB;EAAkC;AAChL;;;EAA0F9B,WAAAA,CAAAA,EA1MxEa,MA0MwEb,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA;EAAwB;;;;;;;;;;;;;;;;iBAzL/FW;;;;;WAKNA;;;;cAIGF;;KAEJK,wBAAAA,GAA2BlB,QAAAA,CAAamB;UACnCC,iBAAAA,SAA0BZ;;;;YAI7BU;;;;;kBAKWG,WAAAA,SAAoBL;;;;;;UAM5BM,eAAAA,SAAwBN;;;;;;;;;;;;mBAYpBhB,QAAAA,CAAauB,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;eAuBtBE,MAAM1B,QAAAA,CAAauB,IAAAA,CAAKE;;;;;;UAM7BzB,QAAAA,CAAauB,IAAAA,CAAKI;;;;;;;cAOd3B,QAAAA,CAAa4B;;;;;;;;;;;;iBAYV5B,QAAAA,CAAa6B,SAAAA,CAAUC;;;;;;;;;;yBAUfhB;;UAEViB,gBAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAwDgBC;;UAEhBC,oBAAAA,SAA6BX,iBAAiBS;;;;;KAK1DG,kCAAAA,GAAqCC,KAAK/B;eAC9B+B,KAAK/B;;;;;YAKNa,sBAAsBR;;;;;;KAM1B2B,0BAAAA,GAA6BD,KAAKnC,QAAAA,CAAa6B,SAAAA,CAAUQ;;;;;;WAMxDX,MAAM1B,QAAAA,CAAa6B,SAAAA,CAAUQ,qBAAAA,CAAsBC;;;;KAIpDC,wBAAAA,GAA2BrC,qBAAqBC,2BAA2BG,4BAA4BD,2BAA2B6B;KAClIM,2BAAAA,GAA8BtC,qBAAqBC,2BAA2BC"}
|
package/dist/utils/misc.cjs
CHANGED
|
@@ -32,8 +32,12 @@ function messageToOpenAIRole(message) {
|
|
|
32
32
|
default: throw new Error(`Unknown message type: ${type}`);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
function _modelPrefersResponsesAPI(model) {
|
|
36
|
+
return model.includes("gpt-5.2-pro");
|
|
37
|
+
}
|
|
35
38
|
|
|
36
39
|
//#endregion
|
|
40
|
+
exports._modelPrefersResponsesAPI = _modelPrefersResponsesAPI;
|
|
37
41
|
exports.getRequiredFilenameFromMetadata = getRequiredFilenameFromMetadata;
|
|
38
42
|
exports.iife = iife;
|
|
39
43
|
exports.isReasoningModel = isReasoningModel;
|
package/dist/utils/misc.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.cjs","names":["fn: () => T","model?: string","message: ChatMessage","block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock","message: BaseMessage","ChatMessage"],"sources":["../../src/utils/misc.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport {\n BaseMessage,\n ChatMessage,\n ContentBlock,\n Data,\n} from \"@langchain/core/messages\";\n\nexport const iife = <T>(fn: () => T) => fn();\n\nexport function isReasoningModel(model?: string) {\n if (!model) return false;\n if (/^o\\d/.test(model ?? \"\")) return true;\n if (model.startsWith(\"gpt-5\") && !model.startsWith(\"gpt-5-chat\")) return true;\n return false;\n}\n\nexport function extractGenericMessageCustomRole(message: ChatMessage) {\n if (\n message.role !== \"system\" &&\n message.role !== \"developer\" &&\n message.role !== \"assistant\" &&\n message.role !== \"user\" &&\n message.role !== \"function\" &&\n message.role !== \"tool\"\n ) {\n console.warn(`Unknown message role: ${message.role}`);\n }\n\n return message.role as OpenAIClient.ChatCompletionRole;\n}\n\nexport function getRequiredFilenameFromMetadata(\n block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock\n): string {\n const filename = (block.metadata?.filename ??\n block.metadata?.name ??\n block.metadata?.title) as string;\n\n if (!filename) {\n throw new Error(\n \"a filename or name or title is needed via meta-data for OpenAI when working with multimodal blocks\"\n );\n }\n\n return filename;\n}\nexport function messageToOpenAIRole(\n message: BaseMessage\n): OpenAIClient.ChatCompletionRole {\n const type = message._getType();\n switch (type) {\n case \"system\":\n return \"system\";\n case \"ai\":\n return \"assistant\";\n case \"human\":\n return \"user\";\n case \"function\":\n return \"function\";\n case \"tool\":\n return \"tool\";\n case \"generic\": {\n if (!ChatMessage.isInstance(message))\n throw new Error(\"Invalid generic chat message\");\n return extractGenericMessageCustomRole(message);\n }\n default:\n throw new Error(`Unknown message type: ${type}`);\n }\n}\n"],"mappings":";;;;AAQA,MAAa,OAAO,CAAIA,OAAgB,IAAI;AAE5C,SAAgB,iBAAiBC,OAAgB;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,OAAO,KAAK,SAAS,GAAG,CAAE,QAAO;AACrC,KAAI,MAAM,WAAW,QAAQ,IAAI,CAAC,MAAM,WAAW,aAAa,CAAE,QAAO;AACzE,QAAO;AACR;AAED,SAAgB,gCAAgCC,SAAsB;AACpE,KACE,QAAQ,SAAS,YACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,UACjB,QAAQ,SAAS,cACjB,QAAQ,SAAS,QAEjB,QAAQ,KAAK,CAAC,sBAAsB,EAAE,QAAQ,MAAM,CAAC;AAGvD,QAAO,QAAQ;AAChB;AAED,SAAgB,gCACdC,OAIQ;CACR,MAAM,WAAY,MAAM,UAAU,YAChC,MAAM,UAAU,QAChB,MAAM,UAAU;AAElB,KAAI,CAAC,SACH,OAAM,IAAI,MACR;AAIJ,QAAO;AACR;AACD,SAAgB,oBACdC,SACiC;CACjC,MAAM,OAAO,QAAQ,UAAU;AAC/B,SAAQ,MAAR;EACE,KAAK,SACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,QACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK;AACH,OAAI,CAACC,sCAAY,WAAW,QAAQ,CAClC,OAAM,IAAI,MAAM;AAClB,UAAO,gCAAgC,QAAQ;EAEjD,QACE,OAAM,IAAI,MAAM,CAAC,sBAAsB,EAAE,MAAM;CAClD;AACF"}
|
|
1
|
+
{"version":3,"file":"misc.cjs","names":["fn: () => T","model?: string","message: ChatMessage","block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock","message: BaseMessage","ChatMessage","model: string"],"sources":["../../src/utils/misc.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport {\n BaseMessage,\n ChatMessage,\n ContentBlock,\n Data,\n} from \"@langchain/core/messages\";\n\nexport const iife = <T>(fn: () => T) => fn();\n\nexport function isReasoningModel(model?: string) {\n if (!model) return false;\n if (/^o\\d/.test(model ?? \"\")) return true;\n if (model.startsWith(\"gpt-5\") && !model.startsWith(\"gpt-5-chat\")) return true;\n return false;\n}\n\nexport function extractGenericMessageCustomRole(message: ChatMessage) {\n if (\n message.role !== \"system\" &&\n message.role !== \"developer\" &&\n message.role !== \"assistant\" &&\n message.role !== \"user\" &&\n message.role !== \"function\" &&\n message.role !== \"tool\"\n ) {\n console.warn(`Unknown message role: ${message.role}`);\n }\n\n return message.role as OpenAIClient.ChatCompletionRole;\n}\n\nexport function getRequiredFilenameFromMetadata(\n block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock\n): string {\n const filename = (block.metadata?.filename ??\n block.metadata?.name ??\n block.metadata?.title) as string;\n\n if (!filename) {\n throw new Error(\n \"a filename or name or title is needed via meta-data for OpenAI when working with multimodal blocks\"\n );\n }\n\n return filename;\n}\nexport function messageToOpenAIRole(\n message: BaseMessage\n): OpenAIClient.ChatCompletionRole {\n const type = message._getType();\n switch (type) {\n case \"system\":\n return \"system\";\n case \"ai\":\n return \"assistant\";\n case \"human\":\n return \"user\";\n case \"function\":\n return \"function\";\n case \"tool\":\n return \"tool\";\n case \"generic\": {\n if (!ChatMessage.isInstance(message))\n throw new Error(\"Invalid generic chat message\");\n return extractGenericMessageCustomRole(message);\n }\n default:\n throw new Error(`Unknown message type: ${type}`);\n }\n}\n\nexport function _modelPrefersResponsesAPI(model: string): boolean {\n return model.includes(\"gpt-5.2-pro\");\n}\n"],"mappings":";;;;AAQA,MAAa,OAAO,CAAIA,OAAgB,IAAI;AAE5C,SAAgB,iBAAiBC,OAAgB;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,OAAO,KAAK,SAAS,GAAG,CAAE,QAAO;AACrC,KAAI,MAAM,WAAW,QAAQ,IAAI,CAAC,MAAM,WAAW,aAAa,CAAE,QAAO;AACzE,QAAO;AACR;AAED,SAAgB,gCAAgCC,SAAsB;AACpE,KACE,QAAQ,SAAS,YACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,UACjB,QAAQ,SAAS,cACjB,QAAQ,SAAS,QAEjB,QAAQ,KAAK,CAAC,sBAAsB,EAAE,QAAQ,MAAM,CAAC;AAGvD,QAAO,QAAQ;AAChB;AAED,SAAgB,gCACdC,OAIQ;CACR,MAAM,WAAY,MAAM,UAAU,YAChC,MAAM,UAAU,QAChB,MAAM,UAAU;AAElB,KAAI,CAAC,SACH,OAAM,IAAI,MACR;AAIJ,QAAO;AACR;AACD,SAAgB,oBACdC,SACiC;CACjC,MAAM,OAAO,QAAQ,UAAU;AAC/B,SAAQ,MAAR;EACE,KAAK,SACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,QACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK;AACH,OAAI,CAACC,sCAAY,WAAW,QAAQ,CAClC,OAAM,IAAI,MAAM;AAClB,UAAO,gCAAgC,QAAQ;EAEjD,QACE,OAAM,IAAI,MAAM,CAAC,sBAAsB,EAAE,MAAM;CAClD;AACF;AAED,SAAgB,0BAA0BC,OAAwB;AAChE,QAAO,MAAM,SAAS,cAAc;AACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.d.cts","names":["OpenAI","OpenAIClient","BaseMessage","ChatMessage","ContentBlock","Data","iife","T","isReasoningModel","extractGenericMessageCustomRole","ChatCompletionRole","getRequiredFilenameFromMetadata","Multimodal","File","Video","StandardFileBlock","messageToOpenAIRole"],"sources":["../../src/utils/misc.d.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport { BaseMessage, ChatMessage, ContentBlock, Data } from \"@langchain/core/messages\";\nexport declare const iife: <T>(fn: () => T) => T;\nexport declare function isReasoningModel(model?: string): boolean;\nexport declare function extractGenericMessageCustomRole(message: ChatMessage): OpenAIClient.ChatCompletionRole;\nexport declare function getRequiredFilenameFromMetadata(block: ContentBlock.Multimodal.File | ContentBlock.Multimodal.Video | Data.StandardFileBlock): string;\nexport declare function messageToOpenAIRole(message: BaseMessage): OpenAIClient.ChatCompletionRole;\n//# sourceMappingURL=misc.d.ts.map"],"mappings":";;;;;iBAMwBgB,mBAAAA,UAA6Bd,cAAcD,QAAAA,CAAaS"}
|
|
1
|
+
{"version":3,"file":"misc.d.cts","names":["OpenAI","OpenAIClient","BaseMessage","ChatMessage","ContentBlock","Data","iife","T","isReasoningModel","extractGenericMessageCustomRole","ChatCompletionRole","getRequiredFilenameFromMetadata","Multimodal","File","Video","StandardFileBlock","messageToOpenAIRole","_modelPrefersResponsesAPI"],"sources":["../../src/utils/misc.d.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport { BaseMessage, ChatMessage, ContentBlock, Data } from \"@langchain/core/messages\";\nexport declare const iife: <T>(fn: () => T) => T;\nexport declare function isReasoningModel(model?: string): boolean;\nexport declare function extractGenericMessageCustomRole(message: ChatMessage): OpenAIClient.ChatCompletionRole;\nexport declare function getRequiredFilenameFromMetadata(block: ContentBlock.Multimodal.File | ContentBlock.Multimodal.Video | Data.StandardFileBlock): string;\nexport declare function messageToOpenAIRole(message: BaseMessage): OpenAIClient.ChatCompletionRole;\nexport declare function _modelPrefersResponsesAPI(model: string): boolean;\n//# sourceMappingURL=misc.d.ts.map"],"mappings":";;;;;iBAMwBgB,mBAAAA,UAA6Bd,cAAcD,QAAAA,CAAaS"}
|
package/dist/utils/misc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.d.ts","names":["OpenAI","OpenAIClient","BaseMessage","ChatMessage","ContentBlock","Data","iife","T","isReasoningModel","extractGenericMessageCustomRole","ChatCompletionRole","getRequiredFilenameFromMetadata","Multimodal","File","Video","StandardFileBlock","messageToOpenAIRole"],"sources":["../../src/utils/misc.d.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport { BaseMessage, ChatMessage, ContentBlock, Data } from \"@langchain/core/messages\";\nexport declare const iife: <T>(fn: () => T) => T;\nexport declare function isReasoningModel(model?: string): boolean;\nexport declare function extractGenericMessageCustomRole(message: ChatMessage): OpenAIClient.ChatCompletionRole;\nexport declare function getRequiredFilenameFromMetadata(block: ContentBlock.Multimodal.File | ContentBlock.Multimodal.Video | Data.StandardFileBlock): string;\nexport declare function messageToOpenAIRole(message: BaseMessage): OpenAIClient.ChatCompletionRole;\n//# sourceMappingURL=misc.d.ts.map"],"mappings":";;;;;iBAMwBgB,mBAAAA,UAA6Bd,cAAcD,QAAAA,CAAaS"}
|
|
1
|
+
{"version":3,"file":"misc.d.ts","names":["OpenAI","OpenAIClient","BaseMessage","ChatMessage","ContentBlock","Data","iife","T","isReasoningModel","extractGenericMessageCustomRole","ChatCompletionRole","getRequiredFilenameFromMetadata","Multimodal","File","Video","StandardFileBlock","messageToOpenAIRole","_modelPrefersResponsesAPI"],"sources":["../../src/utils/misc.d.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport { BaseMessage, ChatMessage, ContentBlock, Data } from \"@langchain/core/messages\";\nexport declare const iife: <T>(fn: () => T) => T;\nexport declare function isReasoningModel(model?: string): boolean;\nexport declare function extractGenericMessageCustomRole(message: ChatMessage): OpenAIClient.ChatCompletionRole;\nexport declare function getRequiredFilenameFromMetadata(block: ContentBlock.Multimodal.File | ContentBlock.Multimodal.Video | Data.StandardFileBlock): string;\nexport declare function messageToOpenAIRole(message: BaseMessage): OpenAIClient.ChatCompletionRole;\nexport declare function _modelPrefersResponsesAPI(model: string): boolean;\n//# sourceMappingURL=misc.d.ts.map"],"mappings":";;;;;iBAMwBgB,mBAAAA,UAA6Bd,cAAcD,QAAAA,CAAaS"}
|
package/dist/utils/misc.js
CHANGED
|
@@ -31,7 +31,10 @@ function messageToOpenAIRole(message) {
|
|
|
31
31
|
default: throw new Error(`Unknown message type: ${type}`);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
function _modelPrefersResponsesAPI(model) {
|
|
35
|
+
return model.includes("gpt-5.2-pro");
|
|
36
|
+
}
|
|
34
37
|
|
|
35
38
|
//#endregion
|
|
36
|
-
export { getRequiredFilenameFromMetadata, iife$1 as iife, isReasoningModel, messageToOpenAIRole };
|
|
39
|
+
export { _modelPrefersResponsesAPI, getRequiredFilenameFromMetadata, iife$1 as iife, isReasoningModel, messageToOpenAIRole };
|
|
37
40
|
//# sourceMappingURL=misc.js.map
|
package/dist/utils/misc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","names":["iife","fn: () => T","model?: string","message: ChatMessage","block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock","message: BaseMessage"],"sources":["../../src/utils/misc.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport {\n BaseMessage,\n ChatMessage,\n ContentBlock,\n Data,\n} from \"@langchain/core/messages\";\n\nexport const iife = <T>(fn: () => T) => fn();\n\nexport function isReasoningModel(model?: string) {\n if (!model) return false;\n if (/^o\\d/.test(model ?? \"\")) return true;\n if (model.startsWith(\"gpt-5\") && !model.startsWith(\"gpt-5-chat\")) return true;\n return false;\n}\n\nexport function extractGenericMessageCustomRole(message: ChatMessage) {\n if (\n message.role !== \"system\" &&\n message.role !== \"developer\" &&\n message.role !== \"assistant\" &&\n message.role !== \"user\" &&\n message.role !== \"function\" &&\n message.role !== \"tool\"\n ) {\n console.warn(`Unknown message role: ${message.role}`);\n }\n\n return message.role as OpenAIClient.ChatCompletionRole;\n}\n\nexport function getRequiredFilenameFromMetadata(\n block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock\n): string {\n const filename = (block.metadata?.filename ??\n block.metadata?.name ??\n block.metadata?.title) as string;\n\n if (!filename) {\n throw new Error(\n \"a filename or name or title is needed via meta-data for OpenAI when working with multimodal blocks\"\n );\n }\n\n return filename;\n}\nexport function messageToOpenAIRole(\n message: BaseMessage\n): OpenAIClient.ChatCompletionRole {\n const type = message._getType();\n switch (type) {\n case \"system\":\n return \"system\";\n case \"ai\":\n return \"assistant\";\n case \"human\":\n return \"user\";\n case \"function\":\n return \"function\";\n case \"tool\":\n return \"tool\";\n case \"generic\": {\n if (!ChatMessage.isInstance(message))\n throw new Error(\"Invalid generic chat message\");\n return extractGenericMessageCustomRole(message);\n }\n default:\n throw new Error(`Unknown message type: ${type}`);\n }\n}\n"],"mappings":";;;AAQA,MAAaA,SAAO,CAAIC,OAAgB,IAAI;AAE5C,SAAgB,iBAAiBC,OAAgB;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,OAAO,KAAK,SAAS,GAAG,CAAE,QAAO;AACrC,KAAI,MAAM,WAAW,QAAQ,IAAI,CAAC,MAAM,WAAW,aAAa,CAAE,QAAO;AACzE,QAAO;AACR;AAED,SAAgB,gCAAgCC,SAAsB;AACpE,KACE,QAAQ,SAAS,YACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,UACjB,QAAQ,SAAS,cACjB,QAAQ,SAAS,QAEjB,QAAQ,KAAK,CAAC,sBAAsB,EAAE,QAAQ,MAAM,CAAC;AAGvD,QAAO,QAAQ;AAChB;AAED,SAAgB,gCACdC,OAIQ;CACR,MAAM,WAAY,MAAM,UAAU,YAChC,MAAM,UAAU,QAChB,MAAM,UAAU;AAElB,KAAI,CAAC,SACH,OAAM,IAAI,MACR;AAIJ,QAAO;AACR;AACD,SAAgB,oBACdC,SACiC;CACjC,MAAM,OAAO,QAAQ,UAAU;AAC/B,SAAQ,MAAR;EACE,KAAK,SACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,QACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK;AACH,OAAI,CAAC,YAAY,WAAW,QAAQ,CAClC,OAAM,IAAI,MAAM;AAClB,UAAO,gCAAgC,QAAQ;EAEjD,QACE,OAAM,IAAI,MAAM,CAAC,sBAAsB,EAAE,MAAM;CAClD;AACF"}
|
|
1
|
+
{"version":3,"file":"misc.js","names":["iife","fn: () => T","model?: string","message: ChatMessage","block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock","message: BaseMessage","model: string"],"sources":["../../src/utils/misc.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport {\n BaseMessage,\n ChatMessage,\n ContentBlock,\n Data,\n} from \"@langchain/core/messages\";\n\nexport const iife = <T>(fn: () => T) => fn();\n\nexport function isReasoningModel(model?: string) {\n if (!model) return false;\n if (/^o\\d/.test(model ?? \"\")) return true;\n if (model.startsWith(\"gpt-5\") && !model.startsWith(\"gpt-5-chat\")) return true;\n return false;\n}\n\nexport function extractGenericMessageCustomRole(message: ChatMessage) {\n if (\n message.role !== \"system\" &&\n message.role !== \"developer\" &&\n message.role !== \"assistant\" &&\n message.role !== \"user\" &&\n message.role !== \"function\" &&\n message.role !== \"tool\"\n ) {\n console.warn(`Unknown message role: ${message.role}`);\n }\n\n return message.role as OpenAIClient.ChatCompletionRole;\n}\n\nexport function getRequiredFilenameFromMetadata(\n block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock\n): string {\n const filename = (block.metadata?.filename ??\n block.metadata?.name ??\n block.metadata?.title) as string;\n\n if (!filename) {\n throw new Error(\n \"a filename or name or title is needed via meta-data for OpenAI when working with multimodal blocks\"\n );\n }\n\n return filename;\n}\nexport function messageToOpenAIRole(\n message: BaseMessage\n): OpenAIClient.ChatCompletionRole {\n const type = message._getType();\n switch (type) {\n case \"system\":\n return \"system\";\n case \"ai\":\n return \"assistant\";\n case \"human\":\n return \"user\";\n case \"function\":\n return \"function\";\n case \"tool\":\n return \"tool\";\n case \"generic\": {\n if (!ChatMessage.isInstance(message))\n throw new Error(\"Invalid generic chat message\");\n return extractGenericMessageCustomRole(message);\n }\n default:\n throw new Error(`Unknown message type: ${type}`);\n }\n}\n\nexport function _modelPrefersResponsesAPI(model: string): boolean {\n return model.includes(\"gpt-5.2-pro\");\n}\n"],"mappings":";;;AAQA,MAAaA,SAAO,CAAIC,OAAgB,IAAI;AAE5C,SAAgB,iBAAiBC,OAAgB;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,OAAO,KAAK,SAAS,GAAG,CAAE,QAAO;AACrC,KAAI,MAAM,WAAW,QAAQ,IAAI,CAAC,MAAM,WAAW,aAAa,CAAE,QAAO;AACzE,QAAO;AACR;AAED,SAAgB,gCAAgCC,SAAsB;AACpE,KACE,QAAQ,SAAS,YACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,UACjB,QAAQ,SAAS,cACjB,QAAQ,SAAS,QAEjB,QAAQ,KAAK,CAAC,sBAAsB,EAAE,QAAQ,MAAM,CAAC;AAGvD,QAAO,QAAQ;AAChB;AAED,SAAgB,gCACdC,OAIQ;CACR,MAAM,WAAY,MAAM,UAAU,YAChC,MAAM,UAAU,QAChB,MAAM,UAAU;AAElB,KAAI,CAAC,SACH,OAAM,IAAI,MACR;AAIJ,QAAO;AACR;AACD,SAAgB,oBACdC,SACiC;CACjC,MAAM,OAAO,QAAQ,UAAU;AAC/B,SAAQ,MAAR;EACE,KAAK,SACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,QACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK;AACH,OAAI,CAAC,YAAY,WAAW,QAAQ,CAClC,OAAM,IAAI,MAAM;AAClB,UAAO,gCAAgC,QAAQ;EAEjD,QACE,OAAM,IAAI,MAAM,CAAC,sBAAsB,EAAE,MAAM;CAClD;AACF;AAED,SAAgB,0BAA0BC,OAAwB;AAChE,QAAO,MAAM,SAAS,cAAc;AACrC"}
|
package/dist/utils/output.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const __langchain_core_utils_types = require_rolldown_runtime.__toESM(require("@langchain/core/utils/types"));
|
|
3
|
+
const __langchain_core_utils_json_schema = require_rolldown_runtime.__toESM(require("@langchain/core/utils/json_schema"));
|
|
3
4
|
const zod_v4_core = require_rolldown_runtime.__toESM(require("zod/v4/core"));
|
|
4
5
|
const openai_helpers_zod = require_rolldown_runtime.__toESM(require("openai/helpers/zod"));
|
|
5
6
|
|
|
@@ -56,7 +57,7 @@ function interopZodResponseFormat(zodSchema, name, props) {
|
|
|
56
57
|
...props,
|
|
57
58
|
name,
|
|
58
59
|
strict: true,
|
|
59
|
-
schema: (0,
|
|
60
|
+
schema: (0, __langchain_core_utils_json_schema.toJsonSchema)(zodSchema, {
|
|
60
61
|
cycles: "ref",
|
|
61
62
|
reused: "ref",
|
|
62
63
|
override(ctx) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.cjs","names":["model: string","method: unknown","response_format: ResponseFormatJSONSchema","parser: (content: string) => ParsedT","zodSchema: InteropZodType","name: string","props: Omit<ResponseFormatJSONSchema.JSONSchema, \"schema\" | \"strict\" | \"name\">","content: string","messages: unknown"],"sources":["../../src/utils/output.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport {\n InteropZodType,\n isZodSchemaV3,\n isZodSchemaV4,\n} from \"@langchain/core/utils/types\";\nimport {
|
|
1
|
+
{"version":3,"file":"output.cjs","names":["model: string","method: unknown","response_format: ResponseFormatJSONSchema","parser: (content: string) => ParsedT","zodSchema: InteropZodType","name: string","props: Omit<ResponseFormatJSONSchema.JSONSchema, \"schema\" | \"strict\" | \"name\">","content: string","messages: unknown"],"sources":["../../src/utils/output.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport {\n InteropZodType,\n isZodSchemaV3,\n isZodSchemaV4,\n} from \"@langchain/core/utils/types\";\nimport { parse as parseV4 } from \"zod/v4/core\";\nimport { ResponseFormatJSONSchema } from \"openai/resources\";\nimport { zodResponseFormat } from \"openai/helpers/zod\";\nimport { ContentBlock, UsageMetadata } from \"@langchain/core/messages\";\nimport { toJsonSchema } from \"@langchain/core/utils/json_schema\";\n\nconst SUPPORTED_METHODS = [\n \"jsonSchema\",\n \"functionCalling\",\n \"jsonMode\",\n] as const;\ntype SupportedMethod = (typeof SUPPORTED_METHODS)[number];\n\n/**\n * Get the structured output method for a given model. By default, it uses\n * `jsonSchema` if the model supports it, otherwise it uses `functionCalling`.\n *\n * @throws if the method is invalid, e.g. is not a string or invalid method is provided.\n * @param model - The model name.\n * @param config - The structured output method options.\n * @returns The structured output method.\n */\nexport function getStructuredOutputMethod(\n model: string,\n method: unknown\n): SupportedMethod {\n /**\n * If a method is provided, validate it.\n */\n if (\n typeof method !== \"undefined\" &&\n !SUPPORTED_METHODS.includes(method as SupportedMethod)\n ) {\n throw new Error(\n `Invalid method: ${method}. Supported methods are: ${SUPPORTED_METHODS.join(\n \", \"\n )}`\n );\n }\n\n const hasSupportForJsonSchema =\n !model.startsWith(\"gpt-3\") &&\n !model.startsWith(\"gpt-4-\") &&\n model !== \"gpt-4\";\n\n /**\n * If the model supports JSON Schema, use it by default.\n */\n if (hasSupportForJsonSchema && !method) {\n return \"jsonSchema\";\n }\n\n if (!hasSupportForJsonSchema && method === \"jsonSchema\") {\n throw new Error(\n `JSON Schema is not supported for model \"${model}\". Please use a different method, e.g. \"functionCalling\" or \"jsonMode\".`\n );\n }\n\n /**\n * If the model does not support JSON Schema, use function calling by default.\n */\n return (method as SupportedMethod) ?? \"functionCalling\";\n}\n\n// inlined from openai/lib/parser.ts\nfunction makeParseableResponseFormat<ParsedT>(\n response_format: ResponseFormatJSONSchema,\n parser: (content: string) => ParsedT\n) {\n const obj = { ...response_format };\n\n Object.defineProperties(obj, {\n $brand: {\n value: \"auto-parseable-response-format\",\n enumerable: false,\n },\n $parseRaw: {\n value: parser,\n enumerable: false,\n },\n });\n\n return obj;\n}\n\nexport function interopZodResponseFormat(\n zodSchema: InteropZodType,\n name: string,\n props: Omit<ResponseFormatJSONSchema.JSONSchema, \"schema\" | \"strict\" | \"name\">\n) {\n if (isZodSchemaV3(zodSchema)) {\n return zodResponseFormat(zodSchema, name, props);\n }\n if (isZodSchemaV4(zodSchema)) {\n return makeParseableResponseFormat(\n {\n type: \"json_schema\",\n json_schema: {\n ...props,\n name,\n strict: true,\n schema: toJsonSchema(zodSchema, {\n cycles: \"ref\", // equivalent to nameStrategy: 'duplicate-ref'\n reused: \"ref\", // equivalent to $refStrategy: 'extract-to-root'\n override(ctx) {\n ctx.jsonSchema.title = name; // equivalent to `name` property\n // TODO: implement `nullableStrategy` patch-fix (zod doesn't support openApi3 json schema target)\n // TODO: implement `openaiStrictMode` patch-fix (where optional properties without `nullable` are not supported)\n },\n /// property equivalents from native `zodResponseFormat` fn\n // openaiStrictMode: true,\n // name,\n // nameStrategy: 'duplicate-ref',\n // $refStrategy: 'extract-to-root',\n // nullableStrategy: 'property',\n }),\n },\n },\n (content) => parseV4(zodSchema, JSON.parse(content))\n );\n }\n throw new Error(\"Unsupported schema response format\");\n}\n\n/**\n * Handle multi modal response content.\n *\n * @param content The content of the message.\n * @param messages The messages of the response.\n * @returns The new content of the message.\n */\nexport function handleMultiModalOutput(\n content: string,\n messages: unknown\n): ContentBlock[] | string {\n /**\n * Handle OpenRouter image responses\n * @see https://openrouter.ai/docs/features/multimodal/image-generation#api-usage\n */\n if (\n messages &&\n typeof messages === \"object\" &&\n \"images\" in messages &&\n Array.isArray(messages.images)\n ) {\n const images = messages.images\n .filter((image) => typeof image?.image_url?.url === \"string\")\n .map(\n (image) =>\n ({\n type: \"image\",\n url: image.image_url.url as string,\n } as const)\n );\n return [{ type: \"text\", text: content }, ...images];\n }\n\n return content;\n}\n\n// TODO: make this a converter\nexport function _convertOpenAIResponsesUsageToLangChainUsage(\n usage?: OpenAIClient.Responses.ResponseUsage\n): UsageMetadata {\n const inputTokenDetails = {\n ...(usage?.input_tokens_details?.cached_tokens != null && {\n cache_read: usage?.input_tokens_details?.cached_tokens,\n }),\n };\n const outputTokenDetails = {\n ...(usage?.output_tokens_details?.reasoning_tokens != null && {\n reasoning: usage?.output_tokens_details?.reasoning_tokens,\n }),\n };\n return {\n input_tokens: usage?.input_tokens ?? 0,\n output_tokens: usage?.output_tokens ?? 0,\n total_tokens: usage?.total_tokens ?? 0,\n input_token_details: inputTokenDetails,\n output_token_details: outputTokenDetails,\n };\n}\n"],"mappings":";;;;;;;AAYA,MAAM,oBAAoB;CACxB;CACA;CACA;AACD;;;;;;;;;;AAYD,SAAgB,0BACdA,OACAC,QACiB;;;;AAIjB,KACE,OAAO,WAAW,eAClB,CAAC,kBAAkB,SAAS,OAA0B,CAEtD,OAAM,IAAI,MACR,CAAC,gBAAgB,EAAE,OAAO,yBAAyB,EAAE,kBAAkB,KACrE,KACD,EAAE;CAIP,MAAM,0BACJ,CAAC,MAAM,WAAW,QAAQ,IAC1B,CAAC,MAAM,WAAW,SAAS,IAC3B,UAAU;;;;AAKZ,KAAI,2BAA2B,CAAC,OAC9B,QAAO;AAGT,KAAI,CAAC,2BAA2B,WAAW,aACzC,OAAM,IAAI,MACR,CAAC,wCAAwC,EAAE,MAAM,uEAAuE,CAAC;;;;AAO7H,QAAQ,UAA8B;AACvC;AAGD,SAAS,4BACPC,iBACAC,QACA;CACA,MAAM,MAAM,EAAE,GAAG,gBAAiB;CAElC,OAAO,iBAAiB,KAAK;EAC3B,QAAQ;GACN,OAAO;GACP,YAAY;EACb;EACD,WAAW;GACT,OAAO;GACP,YAAY;EACb;CACF,EAAC;AAEF,QAAO;AACR;AAED,SAAgB,yBACdC,WACAC,MACAC,OACA;AACA,qDAAkB,UAAU,CAC1B,kDAAyB,WAAW,MAAM,MAAM;AAElD,qDAAkB,UAAU,CAC1B,QAAO,4BACL;EACE,MAAM;EACN,aAAa;GACX,GAAG;GACH;GACA,QAAQ;GACR,6DAAqB,WAAW;IAC9B,QAAQ;IACR,QAAQ;IACR,SAAS,KAAK;KACZ,IAAI,WAAW,QAAQ;IAGxB;GAOF,EAAC;EACH;CACF,GACD,CAAC,mCAAoB,WAAW,KAAK,MAAM,QAAQ,CAAC,CACrD;AAEH,OAAM,IAAI,MAAM;AACjB;;;;;;;;AASD,SAAgB,uBACdC,SACAC,UACyB;;;;;AAKzB,KACE,YACA,OAAO,aAAa,YACpB,YAAY,YACZ,MAAM,QAAQ,SAAS,OAAO,EAC9B;EACA,MAAM,SAAS,SAAS,OACrB,OAAO,CAAC,UAAU,OAAO,OAAO,WAAW,QAAQ,SAAS,CAC5D,IACC,CAAC,WACE;GACC,MAAM;GACN,KAAK,MAAM,UAAU;EACtB,GACJ;AACH,SAAO,CAAC;GAAE,MAAM;GAAQ,MAAM;EAAS,GAAE,GAAG,MAAO;CACpD;AAED,QAAO;AACR"}
|
package/dist/utils/output.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isZodSchemaV3, isZodSchemaV4 } from "@langchain/core/utils/types";
|
|
2
|
-
import {
|
|
2
|
+
import { toJsonSchema } from "@langchain/core/utils/json_schema";
|
|
3
|
+
import { parse } from "zod/v4/core";
|
|
3
4
|
import { zodResponseFormat } from "openai/helpers/zod";
|
|
4
5
|
|
|
5
6
|
//#region src/utils/output.ts
|
|
@@ -55,7 +56,7 @@ function interopZodResponseFormat(zodSchema, name, props) {
|
|
|
55
56
|
...props,
|
|
56
57
|
name,
|
|
57
58
|
strict: true,
|
|
58
|
-
schema:
|
|
59
|
+
schema: toJsonSchema(zodSchema, {
|
|
59
60
|
cycles: "ref",
|
|
60
61
|
reused: "ref",
|
|
61
62
|
override(ctx) {
|
package/dist/utils/output.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","names":["model: string","method: unknown","response_format: ResponseFormatJSONSchema","parser: (content: string) => ParsedT","zodSchema: InteropZodType","name: string","props: Omit<ResponseFormatJSONSchema.JSONSchema, \"schema\" | \"strict\" | \"name\">","
|
|
1
|
+
{"version":3,"file":"output.js","names":["model: string","method: unknown","response_format: ResponseFormatJSONSchema","parser: (content: string) => ParsedT","zodSchema: InteropZodType","name: string","props: Omit<ResponseFormatJSONSchema.JSONSchema, \"schema\" | \"strict\" | \"name\">","parseV4","content: string","messages: unknown"],"sources":["../../src/utils/output.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport {\n InteropZodType,\n isZodSchemaV3,\n isZodSchemaV4,\n} from \"@langchain/core/utils/types\";\nimport { parse as parseV4 } from \"zod/v4/core\";\nimport { ResponseFormatJSONSchema } from \"openai/resources\";\nimport { zodResponseFormat } from \"openai/helpers/zod\";\nimport { ContentBlock, UsageMetadata } from \"@langchain/core/messages\";\nimport { toJsonSchema } from \"@langchain/core/utils/json_schema\";\n\nconst SUPPORTED_METHODS = [\n \"jsonSchema\",\n \"functionCalling\",\n \"jsonMode\",\n] as const;\ntype SupportedMethod = (typeof SUPPORTED_METHODS)[number];\n\n/**\n * Get the structured output method for a given model. By default, it uses\n * `jsonSchema` if the model supports it, otherwise it uses `functionCalling`.\n *\n * @throws if the method is invalid, e.g. is not a string or invalid method is provided.\n * @param model - The model name.\n * @param config - The structured output method options.\n * @returns The structured output method.\n */\nexport function getStructuredOutputMethod(\n model: string,\n method: unknown\n): SupportedMethod {\n /**\n * If a method is provided, validate it.\n */\n if (\n typeof method !== \"undefined\" &&\n !SUPPORTED_METHODS.includes(method as SupportedMethod)\n ) {\n throw new Error(\n `Invalid method: ${method}. Supported methods are: ${SUPPORTED_METHODS.join(\n \", \"\n )}`\n );\n }\n\n const hasSupportForJsonSchema =\n !model.startsWith(\"gpt-3\") &&\n !model.startsWith(\"gpt-4-\") &&\n model !== \"gpt-4\";\n\n /**\n * If the model supports JSON Schema, use it by default.\n */\n if (hasSupportForJsonSchema && !method) {\n return \"jsonSchema\";\n }\n\n if (!hasSupportForJsonSchema && method === \"jsonSchema\") {\n throw new Error(\n `JSON Schema is not supported for model \"${model}\". Please use a different method, e.g. \"functionCalling\" or \"jsonMode\".`\n );\n }\n\n /**\n * If the model does not support JSON Schema, use function calling by default.\n */\n return (method as SupportedMethod) ?? \"functionCalling\";\n}\n\n// inlined from openai/lib/parser.ts\nfunction makeParseableResponseFormat<ParsedT>(\n response_format: ResponseFormatJSONSchema,\n parser: (content: string) => ParsedT\n) {\n const obj = { ...response_format };\n\n Object.defineProperties(obj, {\n $brand: {\n value: \"auto-parseable-response-format\",\n enumerable: false,\n },\n $parseRaw: {\n value: parser,\n enumerable: false,\n },\n });\n\n return obj;\n}\n\nexport function interopZodResponseFormat(\n zodSchema: InteropZodType,\n name: string,\n props: Omit<ResponseFormatJSONSchema.JSONSchema, \"schema\" | \"strict\" | \"name\">\n) {\n if (isZodSchemaV3(zodSchema)) {\n return zodResponseFormat(zodSchema, name, props);\n }\n if (isZodSchemaV4(zodSchema)) {\n return makeParseableResponseFormat(\n {\n type: \"json_schema\",\n json_schema: {\n ...props,\n name,\n strict: true,\n schema: toJsonSchema(zodSchema, {\n cycles: \"ref\", // equivalent to nameStrategy: 'duplicate-ref'\n reused: \"ref\", // equivalent to $refStrategy: 'extract-to-root'\n override(ctx) {\n ctx.jsonSchema.title = name; // equivalent to `name` property\n // TODO: implement `nullableStrategy` patch-fix (zod doesn't support openApi3 json schema target)\n // TODO: implement `openaiStrictMode` patch-fix (where optional properties without `nullable` are not supported)\n },\n /// property equivalents from native `zodResponseFormat` fn\n // openaiStrictMode: true,\n // name,\n // nameStrategy: 'duplicate-ref',\n // $refStrategy: 'extract-to-root',\n // nullableStrategy: 'property',\n }),\n },\n },\n (content) => parseV4(zodSchema, JSON.parse(content))\n );\n }\n throw new Error(\"Unsupported schema response format\");\n}\n\n/**\n * Handle multi modal response content.\n *\n * @param content The content of the message.\n * @param messages The messages of the response.\n * @returns The new content of the message.\n */\nexport function handleMultiModalOutput(\n content: string,\n messages: unknown\n): ContentBlock[] | string {\n /**\n * Handle OpenRouter image responses\n * @see https://openrouter.ai/docs/features/multimodal/image-generation#api-usage\n */\n if (\n messages &&\n typeof messages === \"object\" &&\n \"images\" in messages &&\n Array.isArray(messages.images)\n ) {\n const images = messages.images\n .filter((image) => typeof image?.image_url?.url === \"string\")\n .map(\n (image) =>\n ({\n type: \"image\",\n url: image.image_url.url as string,\n } as const)\n );\n return [{ type: \"text\", text: content }, ...images];\n }\n\n return content;\n}\n\n// TODO: make this a converter\nexport function _convertOpenAIResponsesUsageToLangChainUsage(\n usage?: OpenAIClient.Responses.ResponseUsage\n): UsageMetadata {\n const inputTokenDetails = {\n ...(usage?.input_tokens_details?.cached_tokens != null && {\n cache_read: usage?.input_tokens_details?.cached_tokens,\n }),\n };\n const outputTokenDetails = {\n ...(usage?.output_tokens_details?.reasoning_tokens != null && {\n reasoning: usage?.output_tokens_details?.reasoning_tokens,\n }),\n };\n return {\n input_tokens: usage?.input_tokens ?? 0,\n output_tokens: usage?.output_tokens ?? 0,\n total_tokens: usage?.total_tokens ?? 0,\n input_token_details: inputTokenDetails,\n output_token_details: outputTokenDetails,\n };\n}\n"],"mappings":";;;;;;AAYA,MAAM,oBAAoB;CACxB;CACA;CACA;AACD;;;;;;;;;;AAYD,SAAgB,0BACdA,OACAC,QACiB;;;;AAIjB,KACE,OAAO,WAAW,eAClB,CAAC,kBAAkB,SAAS,OAA0B,CAEtD,OAAM,IAAI,MACR,CAAC,gBAAgB,EAAE,OAAO,yBAAyB,EAAE,kBAAkB,KACrE,KACD,EAAE;CAIP,MAAM,0BACJ,CAAC,MAAM,WAAW,QAAQ,IAC1B,CAAC,MAAM,WAAW,SAAS,IAC3B,UAAU;;;;AAKZ,KAAI,2BAA2B,CAAC,OAC9B,QAAO;AAGT,KAAI,CAAC,2BAA2B,WAAW,aACzC,OAAM,IAAI,MACR,CAAC,wCAAwC,EAAE,MAAM,uEAAuE,CAAC;;;;AAO7H,QAAQ,UAA8B;AACvC;AAGD,SAAS,4BACPC,iBACAC,QACA;CACA,MAAM,MAAM,EAAE,GAAG,gBAAiB;CAElC,OAAO,iBAAiB,KAAK;EAC3B,QAAQ;GACN,OAAO;GACP,YAAY;EACb;EACD,WAAW;GACT,OAAO;GACP,YAAY;EACb;CACF,EAAC;AAEF,QAAO;AACR;AAED,SAAgB,yBACdC,WACAC,MACAC,OACA;AACA,KAAI,cAAc,UAAU,CAC1B,QAAO,kBAAkB,WAAW,MAAM,MAAM;AAElD,KAAI,cAAc,UAAU,CAC1B,QAAO,4BACL;EACE,MAAM;EACN,aAAa;GACX,GAAG;GACH;GACA,QAAQ;GACR,QAAQ,aAAa,WAAW;IAC9B,QAAQ;IACR,QAAQ;IACR,SAAS,KAAK;KACZ,IAAI,WAAW,QAAQ;IAGxB;GAOF,EAAC;EACH;CACF,GACD,CAAC,YAAYC,MAAQ,WAAW,KAAK,MAAM,QAAQ,CAAC,CACrD;AAEH,OAAM,IAAI,MAAM;AACjB;;;;;;;;AASD,SAAgB,uBACdC,SACAC,UACyB;;;;;AAKzB,KACE,YACA,OAAO,aAAa,YACpB,YAAY,YACZ,MAAM,QAAQ,SAAS,OAAO,EAC9B;EACA,MAAM,SAAS,SAAS,OACrB,OAAO,CAAC,UAAU,OAAO,OAAO,WAAW,QAAQ,SAAS,CAC5D,IACC,CAAC,WACE;GACC,MAAM;GACN,KAAK,MAAM,UAAU;EACtB,GACJ;AACH,SAAO,CAAC;GAAE,MAAM;GAAQ,MAAM;EAAS,GAAE,GAAG,MAAO;CACpD;AAED,QAAO;AACR"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/openai",
|
|
3
|
-
"version": "1.2.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "OpenAI integrations for LangChain.js",
|
|
5
5
|
"author": "LangChain",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/providers/langchain-openai/",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"js-tiktoken": "^1.0.12",
|
|
18
|
-
"openai": "^6.
|
|
18
|
+
"openai": "^6.10.0",
|
|
19
19
|
"zod": "^3.25.76 || ^4"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@langchain/core": "1.
|
|
22
|
+
"@langchain/core": "^1.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@azure/identity": "^4.2.1",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"uuid": "^11.1.0",
|
|
37
37
|
"vitest": "^3.2.4",
|
|
38
38
|
"zod-to-json-schema": "^3.24.6",
|
|
39
|
-
"@langchain/core": "1.1.5
|
|
39
|
+
"@langchain/core": "1.1.5",
|
|
40
40
|
"@langchain/eslint": "0.1.1",
|
|
41
|
-
"@langchain/standard-tests": "0.0.8
|
|
41
|
+
"@langchain/standard-tests": "0.0.8",
|
|
42
42
|
"@langchain/tsconfig": "0.0.1"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|