@langchain/openai 1.1.1 → 1.1.2

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/azure/chat_models/common.cjs +4 -9
  3. package/dist/azure/chat_models/common.cjs.map +1 -1
  4. package/dist/azure/chat_models/common.js +6 -11
  5. package/dist/azure/chat_models/common.js.map +1 -1
  6. package/dist/azure/embeddings.cjs +4 -7
  7. package/dist/azure/embeddings.cjs.map +1 -1
  8. package/dist/azure/embeddings.js +5 -8
  9. package/dist/azure/embeddings.js.map +1 -1
  10. package/dist/azure/llms.cjs +4 -7
  11. package/dist/azure/llms.cjs.map +1 -1
  12. package/dist/azure/llms.js +5 -8
  13. package/dist/azure/llms.js.map +1 -1
  14. package/dist/chat_models/base.cjs +2 -1
  15. package/dist/chat_models/base.cjs.map +1 -1
  16. package/dist/chat_models/base.d.cts +2 -2
  17. package/dist/chat_models/base.d.cts.map +1 -1
  18. package/dist/chat_models/base.d.ts +2 -2
  19. package/dist/chat_models/base.d.ts.map +1 -1
  20. package/dist/chat_models/base.js +3 -2
  21. package/dist/chat_models/base.js.map +1 -1
  22. package/dist/embeddings.cjs +2 -0
  23. package/dist/embeddings.cjs.map +1 -1
  24. package/dist/embeddings.d.cts +4 -2
  25. package/dist/embeddings.d.cts.map +1 -1
  26. package/dist/embeddings.d.ts +4 -2
  27. package/dist/embeddings.d.ts.map +1 -1
  28. package/dist/embeddings.js +3 -1
  29. package/dist/embeddings.js.map +1 -1
  30. package/dist/index.cjs +2 -0
  31. package/dist/index.d.cts +3 -3
  32. package/dist/index.d.ts +3 -3
  33. package/dist/index.js +2 -2
  34. package/dist/llms.cjs +1 -0
  35. package/dist/llms.cjs.map +1 -1
  36. package/dist/llms.d.cts +3 -3
  37. package/dist/llms.d.cts.map +1 -1
  38. package/dist/llms.d.ts +3 -3
  39. package/dist/llms.d.ts.map +1 -1
  40. package/dist/llms.js +2 -1
  41. package/dist/llms.js.map +1 -1
  42. package/dist/types.d.cts +5 -5
  43. package/dist/types.d.cts.map +1 -1
  44. package/dist/types.d.ts +5 -5
  45. package/dist/types.d.ts.map +1 -1
  46. package/dist/utils/azure.cjs +18 -0
  47. package/dist/utils/azure.cjs.map +1 -1
  48. package/dist/utils/azure.d.cts +5 -1
  49. package/dist/utils/azure.d.cts.map +1 -1
  50. package/dist/utils/azure.d.ts +5 -1
  51. package/dist/utils/azure.d.ts.map +1 -1
  52. package/dist/utils/azure.js +16 -1
  53. package/dist/utils/azure.js.map +1 -1
  54. package/package.json +3 -3
package/dist/llms.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"llms.cjs","names":["BaseLLM","fields?: Partial<OpenAIInput> &\n BaseLLMParams & {\n configuration?: ClientOptions;\n }","options?: this[\"ParsedCallOptions\"]","prompts: string[]","options: this[\"ParsedCallOptions\"]","runManager?: CallbackManagerForLLMRun","choices: OpenAIClient.CompletionChoice[]","tokenUsage: TokenUsage","response: Omit<OpenAIClient.Completion, \"choices\"> | undefined","choices","input: string","GenerationChunk","request:\n | OpenAIClient.CompletionCreateParamsStreaming\n | OpenAIClient.CompletionCreateParamsNonStreaming","options?: OpenAICoreRequestOptions","wrapOpenAIClientError","options: OpenAICoreRequestOptions | undefined","openAIEndpointConfig: OpenAIEndpointConfig","getEndpoint","OpenAIClient"],"sources":["../src/llms.ts"],"sourcesContent":["import type { TiktokenModel } from \"js-tiktoken/lite\";\nimport { type ClientOptions, OpenAI as OpenAIClient } from \"openai\";\nimport { calculateMaxTokens } from \"@langchain/core/language_models/base\";\nimport { CallbackManagerForLLMRun } from \"@langchain/core/callbacks/manager\";\nimport { GenerationChunk, type LLMResult } from \"@langchain/core/outputs\";\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\nimport {\n BaseLLM,\n type BaseLLMParams,\n} from \"@langchain/core/language_models/llms\";\nimport { chunkArray } from \"@langchain/core/utils/chunk_array\";\nimport type {\n OpenAICallOptions,\n OpenAICoreRequestOptions,\n OpenAIInput,\n} from \"./types.js\";\nimport { OpenAIEndpointConfig, getEndpoint } from \"./utils/azure.js\";\nimport { wrapOpenAIClientError } from \"./utils/client.js\";\n\nexport type { OpenAICallOptions, OpenAIInput };\n\n/**\n * Interface for tracking token usage in OpenAI calls.\n */\ninterface TokenUsage {\n completionTokens?: number;\n promptTokens?: number;\n totalTokens?: number;\n}\n\n/**\n * Wrapper around OpenAI large language models.\n *\n * To use you should have the `openai` package installed, with the\n * `OPENAI_API_KEY` environment variable set.\n *\n * To use with Azure, import the `AzureOpenAI` class.\n *\n * @remarks\n * Any parameters that are valid to be passed to {@link\n * https://platform.openai.com/docs/api-reference/completions/create |\n * `openai.createCompletion`} can be passed through {@link modelKwargs}, even\n * if not explicitly available on this class.\n * @example\n * ```typescript\n * const model = new OpenAI({\n * modelName: \"gpt-4\",\n * temperature: 0.7,\n * maxTokens: 1000,\n * maxRetries: 5,\n * });\n *\n * const res = await model.invoke(\n * \"Question: What would be a good company name for a company that makes colorful socks?\\nAnswer:\"\n * );\n * console.log({ res });\n * ```\n */\nexport class OpenAI<CallOptions extends OpenAICallOptions = OpenAICallOptions>\n extends BaseLLM<CallOptions>\n implements Partial<OpenAIInput>\n{\n static lc_name() {\n return \"OpenAI\";\n }\n\n get callKeys() {\n return [...super.callKeys, \"options\"];\n }\n\n lc_serializable = true;\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n openAIApiKey: \"OPENAI_API_KEY\",\n apiKey: \"OPENAI_API_KEY\",\n organization: \"OPENAI_ORGANIZATION\",\n };\n }\n\n get lc_aliases(): Record<string, string> {\n return {\n modelName: \"model\",\n openAIApiKey: \"openai_api_key\",\n apiKey: \"openai_api_key\",\n };\n }\n\n temperature?: number;\n\n maxTokens?: number;\n\n topP?: number;\n\n frequencyPenalty?: number;\n\n presencePenalty?: number;\n\n n = 1;\n\n bestOf?: number;\n\n logitBias?: Record<string, number>;\n\n model = \"gpt-3.5-turbo-instruct\";\n\n /** @deprecated Use \"model\" instead */\n modelName: string;\n\n modelKwargs?: OpenAIInput[\"modelKwargs\"];\n\n batchSize = 20;\n\n timeout?: number;\n\n stop?: string[];\n\n stopSequences?: string[];\n\n user?: string;\n\n streaming = false;\n\n openAIApiKey?: string;\n\n apiKey?: string;\n\n organization?: string;\n\n protected client: OpenAIClient;\n\n protected clientConfig: ClientOptions;\n\n constructor(\n fields?: Partial<OpenAIInput> &\n BaseLLMParams & {\n configuration?: ClientOptions;\n }\n ) {\n super(fields ?? {});\n\n this.openAIApiKey =\n fields?.apiKey ??\n fields?.openAIApiKey ??\n getEnvironmentVariable(\"OPENAI_API_KEY\");\n this.apiKey = this.openAIApiKey;\n\n this.organization =\n fields?.configuration?.organization ??\n getEnvironmentVariable(\"OPENAI_ORGANIZATION\");\n\n this.model = fields?.model ?? fields?.modelName ?? this.model;\n if (\n (this.model?.startsWith(\"gpt-3.5-turbo\") ||\n this.model?.startsWith(\"gpt-4\") ||\n this.model?.startsWith(\"o1\")) &&\n !this.model?.includes(\"-instruct\")\n ) {\n throw new Error(\n [\n `Your chosen OpenAI model, \"${this.model}\", is a chat model and not a text-in/text-out LLM.`,\n `Passing it into the \"OpenAI\" class is no longer supported.`,\n `Please use the \"ChatOpenAI\" class instead.`,\n \"\",\n `See this page for more information:`,\n \"|\",\n `└> https://js.langchain.com/docs/integrations/chat/openai`,\n ].join(\"\\n\")\n );\n }\n this.modelName = this.model;\n this.modelKwargs = fields?.modelKwargs ?? {};\n this.batchSize = fields?.batchSize ?? this.batchSize;\n this.timeout = fields?.timeout;\n\n this.temperature = fields?.temperature ?? this.temperature;\n this.maxTokens = fields?.maxTokens ?? this.maxTokens;\n this.topP = fields?.topP ?? this.topP;\n this.frequencyPenalty = fields?.frequencyPenalty ?? this.frequencyPenalty;\n this.presencePenalty = fields?.presencePenalty ?? this.presencePenalty;\n this.n = fields?.n ?? this.n;\n this.bestOf = fields?.bestOf ?? this.bestOf;\n this.logitBias = fields?.logitBias;\n this.stop = fields?.stopSequences ?? fields?.stop;\n this.stopSequences = this.stop;\n this.user = fields?.user;\n\n this.streaming = fields?.streaming ?? false;\n\n if (this.streaming && this.bestOf && this.bestOf > 1) {\n throw new Error(\"Cannot stream results when bestOf > 1\");\n }\n\n this.clientConfig = {\n apiKey: this.apiKey,\n organization: this.organization,\n dangerouslyAllowBrowser: true,\n ...fields?.configuration,\n };\n }\n\n /**\n * Get the parameters used to invoke the model\n */\n invocationParams(\n options?: this[\"ParsedCallOptions\"]\n ): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> {\n return {\n model: this.model,\n temperature: this.temperature,\n max_tokens: this.maxTokens,\n top_p: this.topP,\n frequency_penalty: this.frequencyPenalty,\n presence_penalty: this.presencePenalty,\n n: this.n,\n best_of: this.bestOf,\n logit_bias: this.logitBias,\n stop: options?.stop ?? this.stopSequences,\n user: this.user,\n stream: this.streaming,\n ...this.modelKwargs,\n };\n }\n\n /** @ignore */\n _identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions {\n return {\n model_name: this.model,\n ...this.invocationParams(),\n ...this.clientConfig,\n };\n }\n\n /**\n * Get the identifying parameters for the model\n */\n identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions {\n return this._identifyingParams();\n }\n\n /**\n * Call out to OpenAI's endpoint with k unique prompts\n *\n * @param [prompts] - The prompts to pass into the model.\n * @param [options] - Optional list of stop words to use when generating.\n * @param [runManager] - Optional callback manager to use when generating.\n *\n * @returns The full LLM output.\n *\n * @example\n * ```ts\n * import { OpenAI } from \"langchain/llms/openai\";\n * const openai = new OpenAI();\n * const response = await openai.generate([\"Tell me a joke.\"]);\n * ```\n */\n async _generate(\n prompts: string[],\n options: this[\"ParsedCallOptions\"],\n runManager?: CallbackManagerForLLMRun\n ): Promise<LLMResult> {\n const subPrompts = chunkArray(prompts, this.batchSize);\n const choices: OpenAIClient.CompletionChoice[] = [];\n const tokenUsage: TokenUsage = {};\n\n const params = this.invocationParams(options);\n\n if (params.max_tokens === -1) {\n if (prompts.length !== 1) {\n throw new Error(\n \"max_tokens set to -1 not supported for multiple inputs\"\n );\n }\n params.max_tokens = await calculateMaxTokens({\n prompt: prompts[0],\n // Cast here to allow for other models that may not fit the union\n modelName: this.model as TiktokenModel,\n });\n }\n\n for (let i = 0; i < subPrompts.length; i += 1) {\n const data = params.stream\n ? await (async () => {\n const choices: OpenAIClient.CompletionChoice[] = [];\n let response: Omit<OpenAIClient.Completion, \"choices\"> | undefined;\n const stream = await this.completionWithRetry(\n {\n ...params,\n stream: true,\n prompt: subPrompts[i],\n },\n options\n );\n for await (const message of stream) {\n // on the first message set the response properties\n if (!response) {\n response = {\n id: message.id,\n object: message.object,\n created: message.created,\n model: message.model,\n };\n }\n\n // on all messages, update choice\n for (const part of message.choices) {\n if (!choices[part.index]) {\n choices[part.index] = part;\n } else {\n const choice = choices[part.index];\n choice.text += part.text;\n choice.finish_reason = part.finish_reason;\n choice.logprobs = part.logprobs;\n }\n // eslint-disable-next-line no-void\n void runManager?.handleLLMNewToken(part.text, {\n prompt: Math.floor(part.index / this.n),\n completion: part.index % this.n,\n });\n }\n }\n if (options.signal?.aborted) {\n throw new Error(\"AbortError\");\n }\n return { ...response, choices };\n })()\n : await this.completionWithRetry(\n {\n ...params,\n stream: false,\n prompt: subPrompts[i],\n },\n {\n signal: options.signal,\n ...options.options,\n }\n );\n\n choices.push(...data.choices);\n const {\n completion_tokens: completionTokens,\n prompt_tokens: promptTokens,\n total_tokens: totalTokens,\n } = data.usage\n ? data.usage\n : {\n completion_tokens: undefined,\n prompt_tokens: undefined,\n total_tokens: undefined,\n };\n\n if (completionTokens) {\n tokenUsage.completionTokens =\n (tokenUsage.completionTokens ?? 0) + completionTokens;\n }\n\n if (promptTokens) {\n tokenUsage.promptTokens = (tokenUsage.promptTokens ?? 0) + promptTokens;\n }\n\n if (totalTokens) {\n tokenUsage.totalTokens = (tokenUsage.totalTokens ?? 0) + totalTokens;\n }\n }\n\n const generations = chunkArray(choices, this.n).map((promptChoices) =>\n promptChoices.map((choice) => ({\n text: choice.text ?? \"\",\n generationInfo: {\n finishReason: choice.finish_reason,\n logprobs: choice.logprobs,\n },\n }))\n );\n return {\n generations,\n llmOutput: { tokenUsage },\n };\n }\n\n // TODO(jacoblee): Refactor with _generate(..., {stream: true}) implementation?\n async *_streamResponseChunks(\n input: string,\n options: this[\"ParsedCallOptions\"],\n runManager?: CallbackManagerForLLMRun\n ): AsyncGenerator<GenerationChunk> {\n const params = {\n ...this.invocationParams(options),\n prompt: input,\n stream: true as const,\n };\n const stream = await this.completionWithRetry(params, options);\n for await (const data of stream) {\n const choice = data?.choices[0];\n if (!choice) {\n continue;\n }\n const chunk = new GenerationChunk({\n text: choice.text,\n generationInfo: {\n finishReason: choice.finish_reason,\n },\n });\n yield chunk;\n // eslint-disable-next-line no-void\n void runManager?.handleLLMNewToken(chunk.text ?? \"\");\n }\n if (options.signal?.aborted) {\n throw new Error(\"AbortError\");\n }\n }\n\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n async completionWithRetry(\n request: OpenAIClient.CompletionCreateParamsStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<AsyncIterable<OpenAIClient.Completion>>;\n\n async completionWithRetry(\n request: OpenAIClient.CompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<OpenAIClient.Completions.Completion>;\n\n async completionWithRetry(\n request:\n | OpenAIClient.CompletionCreateParamsStreaming\n | OpenAIClient.CompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<\n AsyncIterable<OpenAIClient.Completion> | OpenAIClient.Completions.Completion\n > {\n const requestOptions = this._getClientOptions(options);\n return this.caller.call(async () => {\n try {\n const res = await this.client.completions.create(\n request,\n requestOptions\n );\n return res;\n } catch (e) {\n const error = wrapOpenAIClientError(e);\n throw error;\n }\n });\n }\n\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n protected _getClientOptions(\n options: OpenAICoreRequestOptions | undefined\n ): OpenAICoreRequestOptions {\n if (!this.client) {\n const openAIEndpointConfig: OpenAIEndpointConfig = {\n baseURL: this.clientConfig.baseURL,\n };\n\n const endpoint = getEndpoint(openAIEndpointConfig);\n\n const params = {\n ...this.clientConfig,\n baseURL: endpoint,\n timeout: this.timeout,\n maxRetries: 0,\n };\n\n if (!params.baseURL) {\n delete params.baseURL;\n }\n\n this.client = new OpenAIClient(params);\n }\n const requestOptions = {\n ...this.clientConfig,\n ...options,\n } as OpenAICoreRequestOptions;\n return requestOptions;\n }\n\n _llmType() {\n return \"openai\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,IAAa,SAAb,cACUA,8CAEV;CACE,OAAO,UAAU;AACf,SAAO;CACR;CAED,IAAI,WAAW;AACb,SAAO,CAAC,GAAG,MAAM,UAAU,SAAU;CACtC;CAED,kBAAkB;CAElB,IAAI,aAAoD;AACtD,SAAO;GACL,cAAc;GACd,QAAQ;GACR,cAAc;EACf;CACF;CAED,IAAI,aAAqC;AACvC,SAAO;GACL,WAAW;GACX,cAAc;GACd,QAAQ;EACT;CACF;CAED;CAEA;CAEA;CAEA;CAEA;CAEA,IAAI;CAEJ;CAEA;CAEA,QAAQ;;CAGR;CAEA;CAEA,YAAY;CAEZ;CAEA;CAEA;CAEA;CAEA,YAAY;CAEZ;CAEA;CAEA;CAEA,AAAU;CAEV,AAAU;CAEV,YACEC,QAIA;EACA,MAAM,UAAU,CAAE,EAAC;EAEnB,KAAK,eACH,QAAQ,UACR,QAAQ,uEACe,iBAAiB;EAC1C,KAAK,SAAS,KAAK;EAEnB,KAAK,eACH,QAAQ,eAAe,uEACA,sBAAs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B,OAAI,CAAC,OACH;GAEF,MAAM,QAAQ,IAAIM,yCAAgB;IAChC,MAAM,OAAO;IACb,gBAAgB,EACd,cAAc,OAAO,cACtB;GACF;GACD,MAAM;GAED,YAAY,kBAAkB,MAAM,QAAQ,GAAG;EACrD;AACD,MAAI,QAAQ,QAAQ,QAClB,OAAM,IAAI,MAAM;CAEnB;CAkBD,MAAM,oBACJC,SAGAC,SAGA;EACA,MAAM,iBAAiB,KAAK,kBAAkB,QAAQ;AACtD,SAAO,KAAK,OAAO,KAAK,YAAY;AAClC,OAAI;IACF,MAAM,MAAM,MAAM,KAAK,OAAO,YAAY,OACxC,SACA,eACD;AACD,WAAO;GACR,SAAQ,GAAG;IACV,MAAM,QAAQC,qCAAsB,EAAE;AACtC,UAAM;GACP;EACF,EAAC;CACH;;;;;;;CAQD,AAAU,kBACRC,SAC0B;AAC1B,MAAI,CAAC,KAAK,QAAQ;GAChB,MAAMC,uBAA6C,EACjD,SAAS,KAAK,aAAa,QAC5B;GAED,MAAM,WAAWC,0BAAY,qBAAqB;GAElD,MAAM,SAAS;IACb,GAAG,KAAK;IACR,SAAS;IACT,SAAS,KAAK;IACd,YAAY;GACb;AAED,OAAI,CAAC,OAAO,SACV,OAAO,OAAO;GAGhB,KAAK,SAAS,IAAIC,cAAa;EAChC;EACD,MAAM,iBAAiB;GACrB,GAAG,KAAK;GACR,GAAG;EACJ;AACD,SAAO;CACR;CAED,WAAW;AACT,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"llms.cjs","names":["BaseLLM","fields?: Partial<OpenAIInput> &\n BaseLLMParams & {\n configuration?: ClientOptions;\n }","options?: this[\"ParsedCallOptions\"]","prompts: string[]","options: this[\"ParsedCallOptions\"]","runManager?: CallbackManagerForLLMRun","choices: OpenAIClient.CompletionChoice[]","tokenUsage: TokenUsage","response: Omit<OpenAIClient.Completion, \"choices\"> | undefined","choices","input: string","GenerationChunk","request:\n | OpenAIClient.CompletionCreateParamsStreaming\n | OpenAIClient.CompletionCreateParamsNonStreaming","options?: OpenAICoreRequestOptions","wrapOpenAIClientError","options: OpenAICoreRequestOptions | undefined","openAIEndpointConfig: OpenAIEndpointConfig","getEndpoint","getHeadersWithUserAgent","OpenAIClient"],"sources":["../src/llms.ts"],"sourcesContent":["import type { TiktokenModel } from \"js-tiktoken/lite\";\nimport { type ClientOptions, OpenAI as OpenAIClient } from \"openai\";\nimport { calculateMaxTokens } from \"@langchain/core/language_models/base\";\nimport { CallbackManagerForLLMRun } from \"@langchain/core/callbacks/manager\";\nimport { GenerationChunk, type LLMResult } from \"@langchain/core/outputs\";\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\nimport {\n BaseLLM,\n type BaseLLMParams,\n} from \"@langchain/core/language_models/llms\";\nimport { chunkArray } from \"@langchain/core/utils/chunk_array\";\nimport type {\n OpenAIApiKey,\n OpenAICallOptions,\n OpenAICoreRequestOptions,\n OpenAIInput,\n} from \"./types.js\";\nimport {\n OpenAIEndpointConfig,\n getEndpoint,\n getHeadersWithUserAgent,\n} from \"./utils/azure.js\";\nimport { wrapOpenAIClientError } from \"./utils/client.js\";\n\nexport type { OpenAICallOptions, OpenAIInput };\n\n/**\n * Interface for tracking token usage in OpenAI calls.\n */\ninterface TokenUsage {\n completionTokens?: number;\n promptTokens?: number;\n totalTokens?: number;\n}\n\n/**\n * Wrapper around OpenAI large language models.\n *\n * To use you should have the `openai` package installed, with the\n * `OPENAI_API_KEY` environment variable set.\n *\n * To use with Azure, import the `AzureOpenAI` class.\n *\n * @remarks\n * Any parameters that are valid to be passed to {@link\n * https://platform.openai.com/docs/api-reference/completions/create |\n * `openai.createCompletion`} can be passed through {@link modelKwargs}, even\n * if not explicitly available on this class.\n * @example\n * ```typescript\n * const model = new OpenAI({\n * modelName: \"gpt-4\",\n * temperature: 0.7,\n * maxTokens: 1000,\n * maxRetries: 5,\n * });\n *\n * const res = await model.invoke(\n * \"Question: What would be a good company name for a company that makes colorful socks?\\nAnswer:\"\n * );\n * console.log({ res });\n * ```\n */\nexport class OpenAI<CallOptions extends OpenAICallOptions = OpenAICallOptions>\n extends BaseLLM<CallOptions>\n implements Partial<OpenAIInput>\n{\n static lc_name() {\n return \"OpenAI\";\n }\n\n get callKeys() {\n return [...super.callKeys, \"options\"];\n }\n\n lc_serializable = true;\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n openAIApiKey: \"OPENAI_API_KEY\",\n apiKey: \"OPENAI_API_KEY\",\n organization: \"OPENAI_ORGANIZATION\",\n };\n }\n\n get lc_aliases(): Record<string, string> {\n return {\n modelName: \"model\",\n openAIApiKey: \"openai_api_key\",\n apiKey: \"openai_api_key\",\n };\n }\n\n temperature?: number;\n\n maxTokens?: number;\n\n topP?: number;\n\n frequencyPenalty?: number;\n\n presencePenalty?: number;\n\n n = 1;\n\n bestOf?: number;\n\n logitBias?: Record<string, number>;\n\n model = \"gpt-3.5-turbo-instruct\";\n\n /** @deprecated Use \"model\" instead */\n modelName: string;\n\n modelKwargs?: OpenAIInput[\"modelKwargs\"];\n\n batchSize = 20;\n\n timeout?: number;\n\n stop?: string[];\n\n stopSequences?: string[];\n\n user?: string;\n\n streaming = false;\n\n openAIApiKey?: OpenAIApiKey;\n\n apiKey?: OpenAIApiKey;\n\n organization?: string;\n\n protected client: OpenAIClient;\n\n protected clientConfig: ClientOptions;\n\n constructor(\n fields?: Partial<OpenAIInput> &\n BaseLLMParams & {\n configuration?: ClientOptions;\n }\n ) {\n super(fields ?? {});\n\n this.openAIApiKey =\n fields?.apiKey ??\n fields?.openAIApiKey ??\n getEnvironmentVariable(\"OPENAI_API_KEY\");\n this.apiKey = this.openAIApiKey;\n\n this.organization =\n fields?.configuration?.organization ??\n getEnvironmentVariable(\"OPENAI_ORGANIZATION\");\n\n this.model = fields?.model ?? fields?.modelName ?? this.model;\n if (\n (this.model?.startsWith(\"gpt-3.5-turbo\") ||\n this.model?.startsWith(\"gpt-4\") ||\n this.model?.startsWith(\"o1\")) &&\n !this.model?.includes(\"-instruct\")\n ) {\n throw new Error(\n [\n `Your chosen OpenAI model, \"${this.model}\", is a chat model and not a text-in/text-out LLM.`,\n `Passing it into the \"OpenAI\" class is no longer supported.`,\n `Please use the \"ChatOpenAI\" class instead.`,\n \"\",\n `See this page for more information:`,\n \"|\",\n `└> https://js.langchain.com/docs/integrations/chat/openai`,\n ].join(\"\\n\")\n );\n }\n this.modelName = this.model;\n this.modelKwargs = fields?.modelKwargs ?? {};\n this.batchSize = fields?.batchSize ?? this.batchSize;\n this.timeout = fields?.timeout;\n\n this.temperature = fields?.temperature ?? this.temperature;\n this.maxTokens = fields?.maxTokens ?? this.maxTokens;\n this.topP = fields?.topP ?? this.topP;\n this.frequencyPenalty = fields?.frequencyPenalty ?? this.frequencyPenalty;\n this.presencePenalty = fields?.presencePenalty ?? this.presencePenalty;\n this.n = fields?.n ?? this.n;\n this.bestOf = fields?.bestOf ?? this.bestOf;\n this.logitBias = fields?.logitBias;\n this.stop = fields?.stopSequences ?? fields?.stop;\n this.stopSequences = this.stop;\n this.user = fields?.user;\n\n this.streaming = fields?.streaming ?? false;\n\n if (this.streaming && this.bestOf && this.bestOf > 1) {\n throw new Error(\"Cannot stream results when bestOf > 1\");\n }\n\n this.clientConfig = {\n apiKey: this.apiKey,\n organization: this.organization,\n dangerouslyAllowBrowser: true,\n ...fields?.configuration,\n };\n }\n\n /**\n * Get the parameters used to invoke the model\n */\n invocationParams(\n options?: this[\"ParsedCallOptions\"]\n ): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> {\n return {\n model: this.model,\n temperature: this.temperature,\n max_tokens: this.maxTokens,\n top_p: this.topP,\n frequency_penalty: this.frequencyPenalty,\n presence_penalty: this.presencePenalty,\n n: this.n,\n best_of: this.bestOf,\n logit_bias: this.logitBias,\n stop: options?.stop ?? this.stopSequences,\n user: this.user,\n stream: this.streaming,\n ...this.modelKwargs,\n };\n }\n\n /** @ignore */\n _identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions {\n return {\n model_name: this.model,\n ...this.invocationParams(),\n ...this.clientConfig,\n };\n }\n\n /**\n * Get the identifying parameters for the model\n */\n identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions {\n return this._identifyingParams();\n }\n\n /**\n * Call out to OpenAI's endpoint with k unique prompts\n *\n * @param [prompts] - The prompts to pass into the model.\n * @param [options] - Optional list of stop words to use when generating.\n * @param [runManager] - Optional callback manager to use when generating.\n *\n * @returns The full LLM output.\n *\n * @example\n * ```ts\n * import { OpenAI } from \"langchain/llms/openai\";\n * const openai = new OpenAI();\n * const response = await openai.generate([\"Tell me a joke.\"]);\n * ```\n */\n async _generate(\n prompts: string[],\n options: this[\"ParsedCallOptions\"],\n runManager?: CallbackManagerForLLMRun\n ): Promise<LLMResult> {\n const subPrompts = chunkArray(prompts, this.batchSize);\n const choices: OpenAIClient.CompletionChoice[] = [];\n const tokenUsage: TokenUsage = {};\n\n const params = this.invocationParams(options);\n\n if (params.max_tokens === -1) {\n if (prompts.length !== 1) {\n throw new Error(\n \"max_tokens set to -1 not supported for multiple inputs\"\n );\n }\n params.max_tokens = await calculateMaxTokens({\n prompt: prompts[0],\n // Cast here to allow for other models that may not fit the union\n modelName: this.model as TiktokenModel,\n });\n }\n\n for (let i = 0; i < subPrompts.length; i += 1) {\n const data = params.stream\n ? await (async () => {\n const choices: OpenAIClient.CompletionChoice[] = [];\n let response: Omit<OpenAIClient.Completion, \"choices\"> | undefined;\n const stream = await this.completionWithRetry(\n {\n ...params,\n stream: true,\n prompt: subPrompts[i],\n },\n options\n );\n for await (const message of stream) {\n // on the first message set the response properties\n if (!response) {\n response = {\n id: message.id,\n object: message.object,\n created: message.created,\n model: message.model,\n };\n }\n\n // on all messages, update choice\n for (const part of message.choices) {\n if (!choices[part.index]) {\n choices[part.index] = part;\n } else {\n const choice = choices[part.index];\n choice.text += part.text;\n choice.finish_reason = part.finish_reason;\n choice.logprobs = part.logprobs;\n }\n // eslint-disable-next-line no-void\n void runManager?.handleLLMNewToken(part.text, {\n prompt: Math.floor(part.index / this.n),\n completion: part.index % this.n,\n });\n }\n }\n if (options.signal?.aborted) {\n throw new Error(\"AbortError\");\n }\n return { ...response, choices };\n })()\n : await this.completionWithRetry(\n {\n ...params,\n stream: false,\n prompt: subPrompts[i],\n },\n {\n signal: options.signal,\n ...options.options,\n }\n );\n\n choices.push(...data.choices);\n const {\n completion_tokens: completionTokens,\n prompt_tokens: promptTokens,\n total_tokens: totalTokens,\n } = data.usage\n ? data.usage\n : {\n completion_tokens: undefined,\n prompt_tokens: undefined,\n total_tokens: undefined,\n };\n\n if (completionTokens) {\n tokenUsage.completionTokens =\n (tokenUsage.completionTokens ?? 0) + completionTokens;\n }\n\n if (promptTokens) {\n tokenUsage.promptTokens = (tokenUsage.promptTokens ?? 0) + promptTokens;\n }\n\n if (totalTokens) {\n tokenUsage.totalTokens = (tokenUsage.totalTokens ?? 0) + totalTokens;\n }\n }\n\n const generations = chunkArray(choices, this.n).map((promptChoices) =>\n promptChoices.map((choice) => ({\n text: choice.text ?? \"\",\n generationInfo: {\n finishReason: choice.finish_reason,\n logprobs: choice.logprobs,\n },\n }))\n );\n return {\n generations,\n llmOutput: { tokenUsage },\n };\n }\n\n // TODO(jacoblee): Refactor with _generate(..., {stream: true}) implementation?\n async *_streamResponseChunks(\n input: string,\n options: this[\"ParsedCallOptions\"],\n runManager?: CallbackManagerForLLMRun\n ): AsyncGenerator<GenerationChunk> {\n const params = {\n ...this.invocationParams(options),\n prompt: input,\n stream: true as const,\n };\n const stream = await this.completionWithRetry(params, options);\n for await (const data of stream) {\n const choice = data?.choices[0];\n if (!choice) {\n continue;\n }\n const chunk = new GenerationChunk({\n text: choice.text,\n generationInfo: {\n finishReason: choice.finish_reason,\n },\n });\n yield chunk;\n // eslint-disable-next-line no-void\n void runManager?.handleLLMNewToken(chunk.text ?? \"\");\n }\n if (options.signal?.aborted) {\n throw new Error(\"AbortError\");\n }\n }\n\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n async completionWithRetry(\n request: OpenAIClient.CompletionCreateParamsStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<AsyncIterable<OpenAIClient.Completion>>;\n\n async completionWithRetry(\n request: OpenAIClient.CompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<OpenAIClient.Completions.Completion>;\n\n async completionWithRetry(\n request:\n | OpenAIClient.CompletionCreateParamsStreaming\n | OpenAIClient.CompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<\n AsyncIterable<OpenAIClient.Completion> | OpenAIClient.Completions.Completion\n > {\n const requestOptions = this._getClientOptions(options);\n return this.caller.call(async () => {\n try {\n const res = await this.client.completions.create(\n request,\n requestOptions\n );\n return res;\n } catch (e) {\n const error = wrapOpenAIClientError(e);\n throw error;\n }\n });\n }\n\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n protected _getClientOptions(\n options: OpenAICoreRequestOptions | undefined\n ): OpenAICoreRequestOptions {\n if (!this.client) {\n const openAIEndpointConfig: OpenAIEndpointConfig = {\n baseURL: this.clientConfig.baseURL,\n };\n\n const endpoint = getEndpoint(openAIEndpointConfig);\n\n const params = {\n ...this.clientConfig,\n baseURL: endpoint,\n timeout: this.timeout,\n maxRetries: 0,\n };\n\n if (!params.baseURL) {\n delete params.baseURL;\n }\n\n params.defaultHeaders = getHeadersWithUserAgent(params.defaultHeaders);\n\n this.client = new OpenAIClient(params);\n }\n const requestOptions = {\n ...this.clientConfig,\n ...options,\n } as OpenAICoreRequestOptions;\n return requestOptions;\n }\n\n _llmType() {\n return \"openai\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,IAAa,SA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GAED,MAAM,WAAWC,0BAAY,qBAAqB;GAElD,MAAM,SAAS;IACb,GAAG,KAAK;IACR,SAAS;IACT,SAAS,KAAK;IACd,YAAY;GACb;AAED,OAAI,CAAC,OAAO,SACV,OAAO,OAAO;GAGhB,OAAO,iBAAiBC,sCAAwB,OAAO,eAAe;GAEtE,KAAK,SAAS,IAAIC,cAAa;EAChC;EACD,MAAM,iBAAiB;GACrB,GAAG,KAAK;GACR,GAAG;EACJ;AACD,SAAO;CACR;CAED,WAAW;AACT,SAAO;CACR;AACF"}
package/dist/llms.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { OpenAICallOptions, OpenAICoreRequestOptions, OpenAIInput } from "./types.cjs";
1
+ import { OpenAIApiKey, OpenAICallOptions, OpenAICoreRequestOptions, OpenAIInput } from "./types.cjs";
2
2
  import { ClientOptions, OpenAI as OpenAI$1 } from "openai";
3
3
  import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
4
4
  import { GenerationChunk, LLMResult } from "@langchain/core/outputs";
@@ -60,8 +60,8 @@ declare class OpenAI$2<CallOptions extends OpenAICallOptions = OpenAICallOptions
60
60
  stopSequences?: string[];
61
61
  user?: string;
62
62
  streaming: boolean;
63
- openAIApiKey?: string;
64
- apiKey?: string;
63
+ openAIApiKey?: OpenAIApiKey;
64
+ apiKey?: OpenAIApiKey;
65
65
  organization?: string;
66
66
  protected client: OpenAI$1;
67
67
  protected clientConfig: ClientOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"llms.d.cts","names":["ClientOptions","OpenAI","OpenAIClient","CallbackManagerForLLMRun","GenerationChunk","LLMResult","BaseLLM","BaseLLMParams","OpenAICallOptions","OpenAICoreRequestOptions","OpenAIInput","CallOptions","Record","Partial","CompletionCreateParams","Omit","Promise","AsyncGenerator","CompletionCreateParamsStreaming","Completion","AsyncIterable","CompletionCreateParamsNonStreaming","Completions"],"sources":["../src/llms.d.ts"],"sourcesContent":["import { type ClientOptions, OpenAI as OpenAIClient } from \"openai\";\nimport { CallbackManagerForLLMRun } from \"@langchain/core/callbacks/manager\";\nimport { GenerationChunk, type LLMResult } from \"@langchain/core/outputs\";\nimport { BaseLLM, type BaseLLMParams } from \"@langchain/core/language_models/llms\";\nimport type { OpenAICallOptions, OpenAICoreRequestOptions, OpenAIInput } from \"./types.js\";\nexport type { OpenAICallOptions, OpenAIInput };\n/**\n * Wrapper around OpenAI large language models.\n *\n * To use you should have the `openai` package installed, with the\n * `OPENAI_API_KEY` environment variable set.\n *\n * To use with Azure, import the `AzureOpenAI` class.\n *\n * @remarks\n * Any parameters that are valid to be passed to {@link\n * https://platform.openai.com/docs/api-reference/completions/create |\n * `openai.createCompletion`} can be passed through {@link modelKwargs}, even\n * if not explicitly available on this class.\n * @example\n * ```typescript\n * const model = new OpenAI({\n * modelName: \"gpt-4\",\n * temperature: 0.7,\n * maxTokens: 1000,\n * maxRetries: 5,\n * });\n *\n * const res = await model.invoke(\n * \"Question: What would be a good company name for a company that makes colorful socks?\\nAnswer:\"\n * );\n * console.log({ res });\n * ```\n */\nexport declare class OpenAI<CallOptions extends OpenAICallOptions = OpenAICallOptions> extends BaseLLM<CallOptions> implements Partial<OpenAIInput> {\n static lc_name(): string;\n get callKeys(): string[];\n lc_serializable: boolean;\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n get lc_aliases(): Record<string, string>;\n temperature?: number;\n maxTokens?: number;\n topP?: number;\n frequencyPenalty?: number;\n presencePenalty?: number;\n n: number;\n bestOf?: number;\n logitBias?: Record<string, number>;\n model: string;\n /** @deprecated Use \"model\" instead */\n modelName: string;\n modelKwargs?: OpenAIInput[\"modelKwargs\"];\n batchSize: number;\n timeout?: number;\n stop?: string[];\n stopSequences?: string[];\n user?: string;\n streaming: boolean;\n openAIApiKey?: string;\n apiKey?: string;\n organization?: string;\n protected client: OpenAIClient;\n protected clientConfig: ClientOptions;\n constructor(fields?: Partial<OpenAIInput> & BaseLLMParams & {\n configuration?: ClientOptions;\n });\n /**\n * Get the parameters used to invoke the model\n */\n invocationParams(options?: this[\"ParsedCallOptions\"]): Omit<OpenAIClient.CompletionCreateParams, \"prompt\">;\n /** @ignore */\n _identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions;\n /**\n * Get the identifying parameters for the model\n */\n identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions;\n /**\n * Call out to OpenAI's endpoint with k unique prompts\n *\n * @param [prompts] - The prompts to pass into the model.\n * @param [options] - Optional list of stop words to use when generating.\n * @param [runManager] - Optional callback manager to use when generating.\n *\n * @returns The full LLM output.\n *\n * @example\n * ```ts\n * import { OpenAI } from \"langchain/llms/openai\";\n * const openai = new OpenAI();\n * const response = await openai.generate([\"Tell me a joke.\"]);\n * ```\n */\n _generate(prompts: string[], options: this[\"ParsedCallOptions\"], runManager?: CallbackManagerForLLMRun): Promise<LLMResult>;\n // TODO(jacoblee): Refactor with _generate(..., {stream: true}) implementation?\n _streamResponseChunks(input: string, options: this[\"ParsedCallOptions\"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<GenerationChunk>;\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n completionWithRetry(request: OpenAIClient.CompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Completion>>;\n completionWithRetry(request: OpenAIClient.CompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Completions.Completion>;\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;\n _llmType(): string;\n}\n"],"mappings":";;;;;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAk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Z,2BAA2BO,QAAQd,QAAAA,CAAaoB,WAAAA,CAAYH;;;;;;;uCAO/GV,uCAAuCA"}
1
+ {"version":3,"file":"llms.d.cts","names":["ClientOptions","OpenAI","OpenAIClient","CallbackManagerForLLMRun","GenerationChunk","LLMResult","BaseLLM","BaseLLMParams","OpenAIApiKey","OpenAICallOptions","OpenAICoreRequestOptions","OpenAIInput","CallOptions","Record","Partial","CompletionCreateParams","Omit","Promise","AsyncGenerator","CompletionCreateParamsStreaming","Completion","AsyncIterable","CompletionCreateParamsNonStreaming","Completions"],"sources":["../src/llms.d.ts"],"sourcesContent":["import { type ClientOptions, OpenAI as OpenAIClient } from \"openai\";\nimport { CallbackManagerForLLMRun } from \"@langchain/core/callbacks/manager\";\nimport { GenerationChunk, type LLMResult } from \"@langchain/core/outputs\";\nimport { BaseLLM, type BaseLLMParams } from \"@langchain/core/language_models/llms\";\nimport type { OpenAIApiKey, OpenAICallOptions, OpenAICoreRequestOptions, OpenAIInput } from \"./types.js\";\nexport type { OpenAICallOptions, OpenAIInput };\n/**\n * Wrapper around OpenAI large language models.\n *\n * To use you should have the `openai` package installed, with the\n * `OPENAI_API_KEY` environment variable set.\n *\n * To use with Azure, import the `AzureOpenAI` class.\n *\n * @remarks\n * Any parameters that are valid to be passed to {@link\n * https://platform.openai.com/docs/api-reference/completions/create |\n * `openai.createCompletion`} can be passed through {@link modelKwargs}, even\n * if not explicitly available on this class.\n * @example\n * ```typescript\n * const model = new OpenAI({\n * modelName: \"gpt-4\",\n * temperature: 0.7,\n * maxTokens: 1000,\n * maxRetries: 5,\n * });\n *\n * const res = await model.invoke(\n * \"Question: What would be a good company name for a company that makes colorful socks?\\nAnswer:\"\n * );\n * console.log({ res });\n * ```\n */\nexport declare class OpenAI<CallOptions extends OpenAICallOptions = OpenAICallOptions> extends BaseLLM<CallOptions> implements Partial<OpenAIInput> {\n static lc_name(): string;\n get callKeys(): string[];\n lc_serializable: boolean;\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n get lc_aliases(): Record<string, string>;\n temperature?: number;\n maxTokens?: number;\n topP?: number;\n frequencyPenalty?: number;\n presencePenalty?: number;\n n: number;\n bestOf?: number;\n logitBias?: Record<string, number>;\n model: string;\n /** @deprecated Use \"model\" instead */\n modelName: string;\n modelKwargs?: OpenAIInput[\"modelKwargs\"];\n batchSize: number;\n timeout?: number;\n stop?: string[];\n stopSequences?: string[];\n user?: string;\n streaming: boolean;\n openAIApiKey?: OpenAIApiKey;\n apiKey?: OpenAIApiKey;\n organization?: string;\n protected client: OpenAIClient;\n protected clientConfig: ClientOptions;\n constructor(fields?: Partial<OpenAIInput> & BaseLLMParams & {\n configuration?: ClientOptions;\n });\n /**\n * Get the parameters used to invoke the model\n */\n invocationParams(options?: this[\"ParsedCallOptions\"]): Omit<OpenAIClient.CompletionCreateParams, \"prompt\">;\n /** @ignore */\n _identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions;\n /**\n * Get the identifying parameters for the model\n */\n identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions;\n /**\n * Call out to OpenAI's endpoint with k unique prompts\n *\n * @param [prompts] - The prompts to pass into the model.\n * @param [options] - Optional list of stop words to use when generating.\n * @param [runManager] - Optional callback manager to use when generating.\n *\n * @returns The full LLM output.\n *\n * @example\n * ```ts\n * import { OpenAI } from \"langchain/llms/openai\";\n * const openai = new OpenAI();\n * const response = await openai.generate([\"Tell me a joke.\"]);\n * ```\n */\n _generate(prompts: string[], options: this[\"ParsedCallOptions\"], runManager?: CallbackManagerForLLMRun): Promise<LLMResult>;\n // TODO(jacoblee): Refactor with _generate(..., {stream: true}) implementation?\n _streamResponseChunks(input: string, options: this[\"ParsedCallOptions\"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<GenerationChunk>;\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n completionWithRetry(request: OpenAIClient.CompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Completion>>;\n completionWithRetry(request: OpenAIClient.CompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Completions.Completion>;\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;\n _llmType(): string;\n}\n"],"mappings":";;;;;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgE6GiB,cAhExFhB,QAgEwFgB,CAAAA,oBAhE7DR,iBAgE6DQ,GAhEzCR,iBAgEyCQ,CAAAA,SAhEdX,OAgEcW,CAhENL,WAgEMK,CAAAA,YAhEkBH,OAgElBG,CAhE0BN,WAgE1BM,CAAAA,CAAAA;EAAO,OAE1Bd,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAwB,IAAkBC,QAAAA,CAAAA,CAAAA,EAAAA,MAAAA,EAAAA;EAAe,eAA9Bc,EAAAA,OAAAA;EAAc,IAOlGhB,UAAaiB,CAAAA,CAAAA,EAAAA;IAA2CT,CAAAA,GAAAA,EAAAA,MAAAA,CAAAA,EAAAA,MAAAA;EAAwB,CAAA,GAAyBR,SAAakB;EAAU,IAArCC,UAAAA,CAAAA,CAAAA,EAlEtGR,MAkEsGQ,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EAAa,WAArBJ,CAAAA,EAAAA,MAAAA;EAAO,SAC1Ff,CAAAA,EAAaoB,MAAAA;EAAkC,IAAYZ,CAAAA,EAAAA,MAAAA;EAAwB,gBAAwBa,CAAAA,EAAAA,MAAYH;EAAU,eAA3CH,CAAAA,EAAAA,MAAAA;EAAO,CAAA,EAOrFP,MAAAA;EAAwB,MAAeA,CAAAA,EAAAA,MAAAA;EAAwB,SAjFTJ,CAAAA,EAe/EO,MAf+EP,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EAAO,KAAyBQ,EAAAA,MAAAA;EAAO;;gBAmBpHH;;;;;;;iBAOCH;WACNA;;oBAESN;0BACMF;uBACHc,QAAQH,eAAeJ;oBACxBP;;;;;yDAKmCgB,KAAKd,QAAAA,CAAaa;;wBAEnDC,KAAKd,QAAAA,CAAaa;;MAEpCf;;;;uBAIiBgB,KAAKd,QAAAA,CAAaa;;MAEnCf;;;;;;;;;;;;;;;;;gFAiB0EG,2BAA2Bc,QAAQZ;;wFAE3BF,2BAA2Be,eAAed;;;;;;;+BAOnGF,QAAAA,CAAaiB,2CAA2CT,2BAA2BO,QAAQI,cAAcnB,QAAAA,CAAakB;+BACtHlB,QAAAA,CAAaoB,8CAA8CZ,2BAA2BO,QAAQf,QAAAA,CAAaqB,WAAAA,CAAYH;;;;;;;uCAO/GV,uCAAuCA"}
package/dist/llms.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { OpenAICallOptions, OpenAICoreRequestOptions, OpenAIInput } from "./types.js";
1
+ import { OpenAIApiKey, OpenAICallOptions, OpenAICoreRequestOptions, OpenAIInput } from "./types.js";
2
2
  import { ClientOptions, OpenAI as OpenAI$1 } from "openai";
3
3
  import { GenerationChunk, LLMResult } from "@langchain/core/outputs";
4
4
  import { BaseLLM, BaseLLMParams } from "@langchain/core/language_models/llms";
@@ -60,8 +60,8 @@ declare class OpenAI$2<CallOptions extends OpenAICallOptions = OpenAICallOptions
60
60
  stopSequences?: string[];
61
61
  user?: string;
62
62
  streaming: boolean;
63
- openAIApiKey?: string;
64
- apiKey?: string;
63
+ openAIApiKey?: OpenAIApiKey;
64
+ apiKey?: OpenAIApiKey;
65
65
  organization?: string;
66
66
  protected client: OpenAI$1;
67
67
  protected clientConfig: ClientOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"llms.d.ts","names":["ClientOptions","OpenAI","OpenAIClient","CallbackManagerForLLMRun","GenerationChunk","LLMResult","BaseLLM","BaseLLMParams","OpenAICallOptions","OpenAICoreRequestOptions","OpenAIInput","CallOptions","Record","Partial","CompletionCreateParams","Omit","Promise","AsyncGenerator","CompletionCreateParamsStreaming","Completion","AsyncIterable","CompletionCreateParamsNonStreaming","Completions"],"sources":["../src/llms.d.ts"],"sourcesContent":["import { type ClientOptions, OpenAI as OpenAIClient } from \"openai\";\nimport { CallbackManagerForLLMRun } from \"@langchain/core/callbacks/manager\";\nimport { GenerationChunk, type LLMResult } from \"@langchain/core/outputs\";\nimport { BaseLLM, type BaseLLMParams } from \"@langchain/core/language_models/llms\";\nimport type { OpenAICallOptions, OpenAICoreRequestOptions, OpenAIInput } from \"./types.js\";\nexport type { OpenAICallOptions, OpenAIInput };\n/**\n * Wrapper around OpenAI large language models.\n *\n * To use you should have the `openai` package installed, with the\n * `OPENAI_API_KEY` environment variable set.\n *\n * To use with Azure, import the `AzureOpenAI` class.\n *\n * @remarks\n * Any parameters that are valid to be passed to {@link\n * https://platform.openai.com/docs/api-reference/completions/create |\n * `openai.createCompletion`} can be passed through {@link modelKwargs}, even\n * if not explicitly available on this class.\n * @example\n * ```typescript\n * const model = new OpenAI({\n * modelName: \"gpt-4\",\n * temperature: 0.7,\n * maxTokens: 1000,\n * maxRetries: 5,\n * });\n *\n * const res = await model.invoke(\n * \"Question: What would be a good company name for a company that makes colorful socks?\\nAnswer:\"\n * );\n * console.log({ res });\n * ```\n */\nexport declare class OpenAI<CallOptions extends OpenAICallOptions = OpenAICallOptions> extends BaseLLM<CallOptions> implements Partial<OpenAIInput> {\n static lc_name(): string;\n get callKeys(): string[];\n lc_serializable: boolean;\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n get lc_aliases(): Record<string, string>;\n temperature?: number;\n maxTokens?: number;\n topP?: number;\n frequencyPenalty?: number;\n presencePenalty?: number;\n n: number;\n bestOf?: number;\n logitBias?: Record<string, number>;\n model: string;\n /** @deprecated Use \"model\" instead */\n modelName: string;\n modelKwargs?: OpenAIInput[\"modelKwargs\"];\n batchSize: number;\n timeout?: number;\n stop?: string[];\n stopSequences?: string[];\n user?: string;\n streaming: boolean;\n openAIApiKey?: string;\n apiKey?: string;\n organization?: string;\n protected client: OpenAIClient;\n protected clientConfig: ClientOptions;\n constructor(fields?: Partial<OpenAIInput> & BaseLLMParams & {\n configuration?: ClientOptions;\n });\n /**\n * Get the parameters used to invoke the model\n */\n invocationParams(options?: this[\"ParsedCallOptions\"]): Omit<OpenAIClient.CompletionCreateParams, \"prompt\">;\n /** @ignore */\n _identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions;\n /**\n * Get the identifying parameters for the model\n */\n identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions;\n /**\n * Call out to OpenAI's endpoint with k unique prompts\n *\n * @param [prompts] - The prompts to pass into the model.\n * @param [options] - Optional list of stop words to use when generating.\n * @param [runManager] - Optional callback manager to use when generating.\n *\n * @returns The full LLM output.\n *\n * @example\n * ```ts\n * import { OpenAI } from \"langchain/llms/openai\";\n * const openai = new OpenAI();\n * const response = await openai.generate([\"Tell me a joke.\"]);\n * ```\n */\n _generate(prompts: string[], options: this[\"ParsedCallOptions\"], runManager?: CallbackManagerForLLMRun): Promise<LLMResult>;\n // TODO(jacoblee): Refactor with _generate(..., {stream: true}) implementation?\n _streamResponseChunks(input: string, options: this[\"ParsedCallOptions\"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<GenerationChunk>;\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n completionWithRetry(request: OpenAIClient.CompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Completion>>;\n completionWithRetry(request: OpenAIClient.CompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Completions.Completion>;\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;\n _llmType(): string;\n}\n"],"mappings":";;;;;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEoII,cAlE/GH,QAkE+GG,CAAAA,oBAlEpFI,iBAkEoFJ,GAlEhEI,iBAkEgEJ,CAAAA,SAlErCE,OAkEqCF,CAlE7BO,WAkE6BP,CAAAA,YAlELS,OAkEKT,CAlEGM,WAkEHN,CAAAA,CAAAA;EAAe,OAA9Ba,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAc,IAOlGf,QAAagB,CAAAA,CAAAA,EAAAA,MAAAA,EAAAA;EAA+B,eAAYT,EAAAA,OAAAA;EAAwB,IAAyBP,UAAaiB,CAAAA,CAAAA,EAAAA;IAA3BC,CAAAA,GAAAA,EAAAA,MAAAA,CAAAA,EAAAA,MAAAA;EAAa,CAAA,GAArBJ,SAAAA;EAAO,IAC1Fd,UAAamB,CAAAA,CAAAA,EAnExBT,MAmEwBS,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EAAkC,WAAYZ,CAAAA,EAAAA,MAAAA;EAAwB,SAAWP,CAAAA,EAAaoB,MAAAA;EAAsB,IAA3CN,CAAAA,EAAAA,MAAAA;EAAO,gBAOrFP,CAAAA,EAAAA,MAAAA;EAAwB,eAAeA,CAAAA,EAAAA,MAAAA;EAAwB,CAAA,EAjFTH,MAAAA;EAAO,MAAyBO,CAAAA,EAAAA,MAAAA;EAAO,SAAA,CAAA,EAetHD,MAfsH,CAAA,MAAA,EAAA,MAAA,CAAA;;;;gBAmBpHF;;;;;;;;;;oBAUIR;0BACMF;uBACHa,QAAQH,eAAeH;oBACxBP;;;;;yDAKmCe,KAAKb,QAAAA,CAAaY;;wBAEnDC,KAAKb,QAAAA,CAAaY;;MAEpCd;;;;uBAIiBe,KAAKb,QAAAA,CAAaY;;MAEnCd;;;;;;;;;;;;;;;;;gFAiB0EG,2BAA2Ba,QAAQX;;wFAE3BF,2BAA2Bc,eAAeb;;;;;;;+BAOnGF,QAAAA,CAAagB,2CAA2CT,2BAA2BO,QAAQI,cAAclB,QAAAA,CAAaiB;+BACtHjB,QAAAA,CAAamB,8CAA8CZ,2BAA2BO,QAAQd,QAAAA,CAAaoB,WAAAA,CAAYH;;;;;;;uCAO/GV,uCAAuCA"}
1
+ {"version":3,"file":"llms.d.ts","names":["ClientOptions","OpenAI","OpenAIClient","CallbackManagerForLLMRun","GenerationChunk","LLMResult","BaseLLM","BaseLLMParams","OpenAIApiKey","OpenAICallOptions","OpenAICoreRequestOptions","OpenAIInput","CallOptions","Record","Partial","CompletionCreateParams","Omit","Promise","AsyncGenerator","CompletionCreateParamsStreaming","Completion","AsyncIterable","CompletionCreateParamsNonStreaming","Completions"],"sources":["../src/llms.d.ts"],"sourcesContent":["import { type ClientOptions, OpenAI as OpenAIClient } from \"openai\";\nimport { CallbackManagerForLLMRun } from \"@langchain/core/callbacks/manager\";\nimport { GenerationChunk, type LLMResult } from \"@langchain/core/outputs\";\nimport { BaseLLM, type BaseLLMParams } from \"@langchain/core/language_models/llms\";\nimport type { OpenAIApiKey, OpenAICallOptions, OpenAICoreRequestOptions, OpenAIInput } from \"./types.js\";\nexport type { OpenAICallOptions, OpenAIInput };\n/**\n * Wrapper around OpenAI large language models.\n *\n * To use you should have the `openai` package installed, with the\n * `OPENAI_API_KEY` environment variable set.\n *\n * To use with Azure, import the `AzureOpenAI` class.\n *\n * @remarks\n * Any parameters that are valid to be passed to {@link\n * https://platform.openai.com/docs/api-reference/completions/create |\n * `openai.createCompletion`} can be passed through {@link modelKwargs}, even\n * if not explicitly available on this class.\n * @example\n * ```typescript\n * const model = new OpenAI({\n * modelName: \"gpt-4\",\n * temperature: 0.7,\n * maxTokens: 1000,\n * maxRetries: 5,\n * });\n *\n * const res = await model.invoke(\n * \"Question: What would be a good company name for a company that makes colorful socks?\\nAnswer:\"\n * );\n * console.log({ res });\n * ```\n */\nexport declare class OpenAI<CallOptions extends OpenAICallOptions = OpenAICallOptions> extends BaseLLM<CallOptions> implements Partial<OpenAIInput> {\n static lc_name(): string;\n get callKeys(): string[];\n lc_serializable: boolean;\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n get lc_aliases(): Record<string, string>;\n temperature?: number;\n maxTokens?: number;\n topP?: number;\n frequencyPenalty?: number;\n presencePenalty?: number;\n n: number;\n bestOf?: number;\n logitBias?: Record<string, number>;\n model: string;\n /** @deprecated Use \"model\" instead */\n modelName: string;\n modelKwargs?: OpenAIInput[\"modelKwargs\"];\n batchSize: number;\n timeout?: number;\n stop?: string[];\n stopSequences?: string[];\n user?: string;\n streaming: boolean;\n openAIApiKey?: OpenAIApiKey;\n apiKey?: OpenAIApiKey;\n organization?: string;\n protected client: OpenAIClient;\n protected clientConfig: ClientOptions;\n constructor(fields?: Partial<OpenAIInput> & BaseLLMParams & {\n configuration?: ClientOptions;\n });\n /**\n * Get the parameters used to invoke the model\n */\n invocationParams(options?: this[\"ParsedCallOptions\"]): Omit<OpenAIClient.CompletionCreateParams, \"prompt\">;\n /** @ignore */\n _identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions;\n /**\n * Get the identifying parameters for the model\n */\n identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions;\n /**\n * Call out to OpenAI's endpoint with k unique prompts\n *\n * @param [prompts] - The prompts to pass into the model.\n * @param [options] - Optional list of stop words to use when generating.\n * @param [runManager] - Optional callback manager to use when generating.\n *\n * @returns The full LLM output.\n *\n * @example\n * ```ts\n * import { OpenAI } from \"langchain/llms/openai\";\n * const openai = new OpenAI();\n * const response = await openai.generate([\"Tell me a joke.\"]);\n * ```\n */\n _generate(prompts: string[], options: this[\"ParsedCallOptions\"], runManager?: CallbackManagerForLLMRun): Promise<LLMResult>;\n // TODO(jacoblee): Refactor with _generate(..., {stream: true}) implementation?\n _streamResponseChunks(input: string, options: this[\"ParsedCallOptions\"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<GenerationChunk>;\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n completionWithRetry(request: OpenAIClient.CompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Completion>>;\n completionWithRetry(request: OpenAIClient.CompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Completions.Completion>;\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;\n _llmType(): string;\n}\n"],"mappings":";;;;;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgE6GiB,cAhExFhB,QAgEwFgB,CAAAA,oBAhE7DR,iBAgE6DQ,GAhEzCR,iBAgEyCQ,CAAAA,SAhEdX,OAgEcW,CAhENL,WAgEMK,CAAAA,YAhEkBH,OAgElBG,CAhE0BN,WAgE1BM,CAAAA,CAAAA;EAAO,OAE1Bd,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAwB,IAAkBC,QAAAA,CAAAA,CAAAA,EAAAA,MAAAA,EAAAA;EAAe,eAA9Bc,EAAAA,OAAAA;EAAc,IAOlGhB,UAAaiB,CAAAA,CAAAA,EAAAA;IAA2CT,CAAAA,GAAAA,EAAAA,MAAAA,CAAAA,EAAAA,MAAAA;EAAwB,CAAA,GAAyBR,SAAakB;EAAU,IAArCC,UAAAA,CAAAA,CAAAA,EAlEtGR,MAkEsGQ,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EAAa,WAArBJ,CAAAA,EAAAA,MAAAA;EAAO,SAC1Ff,CAAAA,EAAaoB,MAAAA;EAAkC,IAAYZ,CAAAA,EAAAA,MAAAA;EAAwB,gBAAwBa,CAAAA,EAAAA,MAAYH;EAAU,eAA3CH,CAAAA,EAAAA,MAAAA;EAAO,CAAA,EAOrFP,MAAAA;EAAwB,MAAeA,CAAAA,EAAAA,MAAAA;EAAwB,SAjFTJ,CAAAA,EAe/EO,MAf+EP,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EAAO,KAAyBQ,EAAAA,MAAAA;EAAO;;gBAmBpHH;;;;;;;iBAOCH;WACNA;;oBAESN;0BACMF;uBACHc,QAAQH,eAAeJ;oBACxBP;;;;;yDAKmCgB,KAAKd,QAAAA,CAAaa;;wBAEnDC,KAAKd,QAAAA,CAAaa;;MAEpCf;;;;uBAIiBgB,KAAKd,QAAAA,CAAaa;;MAEnCf;;;;;;;;;;;;;;;;;gFAiB0EG,2BAA2Bc,QAAQZ;;wFAE3BF,2BAA2Be,eAAed;;;;;;;+BAOnGF,QAAAA,CAAaiB,2CAA2CT,2BAA2BO,QAAQI,cAAcnB,QAAAA,CAAakB;+BACtHlB,QAAAA,CAAaoB,8CAA8CZ,2BAA2BO,QAAQf,QAAAA,CAAaqB,WAAAA,CAAYH;;;;;;;uCAO/GV,uCAAuCA"}
package/dist/llms.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { wrapOpenAIClientError } from "./utils/client.js";
2
- import { getEndpoint } from "./utils/azure.js";
2
+ import { getEndpoint, getHeadersWithUserAgent } from "./utils/azure.js";
3
3
  import { OpenAI as OpenAI$1 } from "openai";
4
4
  import { GenerationChunk } from "@langchain/core/outputs";
5
5
  import { getEnvironmentVariable } from "@langchain/core/utils/env";
@@ -295,6 +295,7 @@ var OpenAI$2 = class extends BaseLLM {
295
295
  maxRetries: 0
296
296
  };
297
297
  if (!params.baseURL) delete params.baseURL;
298
+ params.defaultHeaders = getHeadersWithUserAgent(params.defaultHeaders);
298
299
  this.client = new OpenAI$1(params);
299
300
  }
300
301
  const requestOptions = {
package/dist/llms.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"llms.js","names":["OpenAI","fields?: Partial<OpenAIInput> &\n BaseLLMParams & {\n configuration?: ClientOptions;\n }","options?: this[\"ParsedCallOptions\"]","prompts: string[]","options: this[\"ParsedCallOptions\"]","runManager?: CallbackManagerForLLMRun","choices: OpenAIClient.CompletionChoice[]","tokenUsage: TokenUsage","response: Omit<OpenAIClient.Completion, \"choices\"> | undefined","choices","input: string","request:\n | OpenAIClient.CompletionCreateParamsStreaming\n | OpenAIClient.CompletionCreateParamsNonStreaming","options?: OpenAICoreRequestOptions","options: OpenAICoreRequestOptions | undefined","openAIEndpointConfig: OpenAIEndpointConfig","OpenAIClient"],"sources":["../src/llms.ts"],"sourcesContent":["import type { TiktokenModel } from \"js-tiktoken/lite\";\nimport { type ClientOptions, OpenAI as OpenAIClient } from \"openai\";\nimport { calculateMaxTokens } from \"@langchain/core/language_models/base\";\nimport { CallbackManagerForLLMRun } from \"@langchain/core/callbacks/manager\";\nimport { GenerationChunk, type LLMResult } from \"@langchain/core/outputs\";\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\nimport {\n BaseLLM,\n type BaseLLMParams,\n} from \"@langchain/core/language_models/llms\";\nimport { chunkArray } from \"@langchain/core/utils/chunk_array\";\nimport type {\n OpenAICallOptions,\n OpenAICoreRequestOptions,\n OpenAIInput,\n} from \"./types.js\";\nimport { OpenAIEndpointConfig, getEndpoint } from \"./utils/azure.js\";\nimport { wrapOpenAIClientError } from \"./utils/client.js\";\n\nexport type { OpenAICallOptions, OpenAIInput };\n\n/**\n * Interface for tracking token usage in OpenAI calls.\n */\ninterface TokenUsage {\n completionTokens?: number;\n promptTokens?: number;\n totalTokens?: number;\n}\n\n/**\n * Wrapper around OpenAI large language models.\n *\n * To use you should have the `openai` package installed, with the\n * `OPENAI_API_KEY` environment variable set.\n *\n * To use with Azure, import the `AzureOpenAI` class.\n *\n * @remarks\n * Any parameters that are valid to be passed to {@link\n * https://platform.openai.com/docs/api-reference/completions/create |\n * `openai.createCompletion`} can be passed through {@link modelKwargs}, even\n * if not explicitly available on this class.\n * @example\n * ```typescript\n * const model = new OpenAI({\n * modelName: \"gpt-4\",\n * temperature: 0.7,\n * maxTokens: 1000,\n * maxRetries: 5,\n * });\n *\n * const res = await model.invoke(\n * \"Question: What would be a good company name for a company that makes colorful socks?\\nAnswer:\"\n * );\n * console.log({ res });\n * ```\n */\nexport class OpenAI<CallOptions extends OpenAICallOptions = OpenAICallOptions>\n extends BaseLLM<CallOptions>\n implements Partial<OpenAIInput>\n{\n static lc_name() {\n return \"OpenAI\";\n }\n\n get callKeys() {\n return [...super.callKeys, \"options\"];\n }\n\n lc_serializable = true;\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n openAIApiKey: \"OPENAI_API_KEY\",\n apiKey: \"OPENAI_API_KEY\",\n organization: \"OPENAI_ORGANIZATION\",\n };\n }\n\n get lc_aliases(): Record<string, string> {\n return {\n modelName: \"model\",\n openAIApiKey: \"openai_api_key\",\n apiKey: \"openai_api_key\",\n };\n }\n\n temperature?: number;\n\n maxTokens?: number;\n\n topP?: number;\n\n frequencyPenalty?: number;\n\n presencePenalty?: number;\n\n n = 1;\n\n bestOf?: number;\n\n logitBias?: Record<string, number>;\n\n model = \"gpt-3.5-turbo-instruct\";\n\n /** @deprecated Use \"model\" instead */\n modelName: string;\n\n modelKwargs?: OpenAIInput[\"modelKwargs\"];\n\n batchSize = 20;\n\n timeout?: number;\n\n stop?: string[];\n\n stopSequences?: string[];\n\n user?: string;\n\n streaming = false;\n\n openAIApiKey?: string;\n\n apiKey?: string;\n\n organization?: string;\n\n protected client: OpenAIClient;\n\n protected clientConfig: ClientOptions;\n\n constructor(\n fields?: Partial<OpenAIInput> &\n BaseLLMParams & {\n configuration?: ClientOptions;\n }\n ) {\n super(fields ?? {});\n\n this.openAIApiKey =\n fields?.apiKey ??\n fields?.openAIApiKey ??\n getEnvironmentVariable(\"OPENAI_API_KEY\");\n this.apiKey = this.openAIApiKey;\n\n this.organization =\n fields?.configuration?.organization ??\n getEnvironmentVariable(\"OPENAI_ORGANIZATION\");\n\n this.model = fields?.model ?? fields?.modelName ?? this.model;\n if (\n (this.model?.startsWith(\"gpt-3.5-turbo\") ||\n this.model?.startsWith(\"gpt-4\") ||\n this.model?.startsWith(\"o1\")) &&\n !this.model?.includes(\"-instruct\")\n ) {\n throw new Error(\n [\n `Your chosen OpenAI model, \"${this.model}\", is a chat model and not a text-in/text-out LLM.`,\n `Passing it into the \"OpenAI\" class is no longer supported.`,\n `Please use the \"ChatOpenAI\" class instead.`,\n \"\",\n `See this page for more information:`,\n \"|\",\n `└> https://js.langchain.com/docs/integrations/chat/openai`,\n ].join(\"\\n\")\n );\n }\n this.modelName = this.model;\n this.modelKwargs = fields?.modelKwargs ?? {};\n this.batchSize = fields?.batchSize ?? this.batchSize;\n this.timeout = fields?.timeout;\n\n this.temperature = fields?.temperature ?? this.temperature;\n this.maxTokens = fields?.maxTokens ?? this.maxTokens;\n this.topP = fields?.topP ?? this.topP;\n this.frequencyPenalty = fields?.frequencyPenalty ?? this.frequencyPenalty;\n this.presencePenalty = fields?.presencePenalty ?? this.presencePenalty;\n this.n = fields?.n ?? this.n;\n this.bestOf = fields?.bestOf ?? this.bestOf;\n this.logitBias = fields?.logitBias;\n this.stop = fields?.stopSequences ?? fields?.stop;\n this.stopSequences = this.stop;\n this.user = fields?.user;\n\n this.streaming = fields?.streaming ?? false;\n\n if (this.streaming && this.bestOf && this.bestOf > 1) {\n throw new Error(\"Cannot stream results when bestOf > 1\");\n }\n\n this.clientConfig = {\n apiKey: this.apiKey,\n organization: this.organization,\n dangerouslyAllowBrowser: true,\n ...fields?.configuration,\n };\n }\n\n /**\n * Get the parameters used to invoke the model\n */\n invocationParams(\n options?: this[\"ParsedCallOptions\"]\n ): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> {\n return {\n model: this.model,\n temperature: this.temperature,\n max_tokens: this.maxTokens,\n top_p: this.topP,\n frequency_penalty: this.frequencyPenalty,\n presence_penalty: this.presencePenalty,\n n: this.n,\n best_of: this.bestOf,\n logit_bias: this.logitBias,\n stop: options?.stop ?? this.stopSequences,\n user: this.user,\n stream: this.streaming,\n ...this.modelKwargs,\n };\n }\n\n /** @ignore */\n _identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions {\n return {\n model_name: this.model,\n ...this.invocationParams(),\n ...this.clientConfig,\n };\n }\n\n /**\n * Get the identifying parameters for the model\n */\n identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions {\n return this._identifyingParams();\n }\n\n /**\n * Call out to OpenAI's endpoint with k unique prompts\n *\n * @param [prompts] - The prompts to pass into the model.\n * @param [options] - Optional list of stop words to use when generating.\n * @param [runManager] - Optional callback manager to use when generating.\n *\n * @returns The full LLM output.\n *\n * @example\n * ```ts\n * import { OpenAI } from \"langchain/llms/openai\";\n * const openai = new OpenAI();\n * const response = await openai.generate([\"Tell me a joke.\"]);\n * ```\n */\n async _generate(\n prompts: string[],\n options: this[\"ParsedCallOptions\"],\n runManager?: CallbackManagerForLLMRun\n ): Promise<LLMResult> {\n const subPrompts = chunkArray(prompts, this.batchSize);\n const choices: OpenAIClient.CompletionChoice[] = [];\n const tokenUsage: TokenUsage = {};\n\n const params = this.invocationParams(options);\n\n if (params.max_tokens === -1) {\n if (prompts.length !== 1) {\n throw new Error(\n \"max_tokens set to -1 not supported for multiple inputs\"\n );\n }\n params.max_tokens = await calculateMaxTokens({\n prompt: prompts[0],\n // Cast here to allow for other models that may not fit the union\n modelName: this.model as TiktokenModel,\n });\n }\n\n for (let i = 0; i < subPrompts.length; i += 1) {\n const data = params.stream\n ? await (async () => {\n const choices: OpenAIClient.CompletionChoice[] = [];\n let response: Omit<OpenAIClient.Completion, \"choices\"> | undefined;\n const stream = await this.completionWithRetry(\n {\n ...params,\n stream: true,\n prompt: subPrompts[i],\n },\n options\n );\n for await (const message of stream) {\n // on the first message set the response properties\n if (!response) {\n response = {\n id: message.id,\n object: message.object,\n created: message.created,\n model: message.model,\n };\n }\n\n // on all messages, update choice\n for (const part of message.choices) {\n if (!choices[part.index]) {\n choices[part.index] = part;\n } else {\n const choice = choices[part.index];\n choice.text += part.text;\n choice.finish_reason = part.finish_reason;\n choice.logprobs = part.logprobs;\n }\n // eslint-disable-next-line no-void\n void runManager?.handleLLMNewToken(part.text, {\n prompt: Math.floor(part.index / this.n),\n completion: part.index % this.n,\n });\n }\n }\n if (options.signal?.aborted) {\n throw new Error(\"AbortError\");\n }\n return { ...response, choices };\n })()\n : await this.completionWithRetry(\n {\n ...params,\n stream: false,\n prompt: subPrompts[i],\n },\n {\n signal: options.signal,\n ...options.options,\n }\n );\n\n choices.push(...data.choices);\n const {\n completion_tokens: completionTokens,\n prompt_tokens: promptTokens,\n total_tokens: totalTokens,\n } = data.usage\n ? data.usage\n : {\n completion_tokens: undefined,\n prompt_tokens: undefined,\n total_tokens: undefined,\n };\n\n if (completionTokens) {\n tokenUsage.completionTokens =\n (tokenUsage.completionTokens ?? 0) + completionTokens;\n }\n\n if (promptTokens) {\n tokenUsage.promptTokens = (tokenUsage.promptTokens ?? 0) + promptTokens;\n }\n\n if (totalTokens) {\n tokenUsage.totalTokens = (tokenUsage.totalTokens ?? 0) + totalTokens;\n }\n }\n\n const generations = chunkArray(choices, this.n).map((promptChoices) =>\n promptChoices.map((choice) => ({\n text: choice.text ?? \"\",\n generationInfo: {\n finishReason: choice.finish_reason,\n logprobs: choice.logprobs,\n },\n }))\n );\n return {\n generations,\n llmOutput: { tokenUsage },\n };\n }\n\n // TODO(jacoblee): Refactor with _generate(..., {stream: true}) implementation?\n async *_streamResponseChunks(\n input: string,\n options: this[\"ParsedCallOptions\"],\n runManager?: CallbackManagerForLLMRun\n ): AsyncGenerator<GenerationChunk> {\n const params = {\n ...this.invocationParams(options),\n prompt: input,\n stream: true as const,\n };\n const stream = await this.completionWithRetry(params, options);\n for await (const data of stream) {\n const choice = data?.choices[0];\n if (!choice) {\n continue;\n }\n const chunk = new GenerationChunk({\n text: choice.text,\n generationInfo: {\n finishReason: choice.finish_reason,\n },\n });\n yield chunk;\n // eslint-disable-next-line no-void\n void runManager?.handleLLMNewToken(chunk.text ?? \"\");\n }\n if (options.signal?.aborted) {\n throw new Error(\"AbortError\");\n }\n }\n\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n async completionWithRetry(\n request: OpenAIClient.CompletionCreateParamsStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<AsyncIterable<OpenAIClient.Completion>>;\n\n async completionWithRetry(\n request: OpenAIClient.CompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<OpenAIClient.Completions.Completion>;\n\n async completionWithRetry(\n request:\n | OpenAIClient.CompletionCreateParamsStreaming\n | OpenAIClient.CompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<\n AsyncIterable<OpenAIClient.Completion> | OpenAIClient.Completions.Completion\n > {\n const requestOptions = this._getClientOptions(options);\n return this.caller.call(async () => {\n try {\n const res = await this.client.completions.create(\n request,\n requestOptions\n );\n return res;\n } catch (e) {\n const error = wrapOpenAIClientError(e);\n throw error;\n }\n });\n }\n\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n protected _getClientOptions(\n options: OpenAICoreRequestOptions | undefined\n ): OpenAICoreRequestOptions {\n if (!this.client) {\n const openAIEndpointConfig: OpenAIEndpointConfig = {\n baseURL: this.clientConfig.baseURL,\n };\n\n const endpoint = getEndpoint(openAIEndpointConfig);\n\n const params = {\n ...this.clientConfig,\n baseURL: endpoint,\n timeout: this.timeout,\n maxRetries: 0,\n };\n\n if (!params.baseURL) {\n delete params.baseURL;\n }\n\n this.client = new OpenAIClient(params);\n }\n const requestOptions = {\n ...this.clientConfig,\n ...options,\n } as OpenAICoreRequestOptions;\n return requestOptions;\n }\n\n _llmType() {\n return \"openai\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,IAAaA,WAAb,cACU,QAEV;CACE,OAAO,UAAU;AACf,SAAO;CACR;CAED,IAAI,WAAW;AACb,SAAO,CAAC,GAAG,MAAM,UAAU,SAAU;CACtC;CAED,kBAAkB;CAElB,IAAI,aAAoD;AACtD,SAAO;GACL,cAAc;GACd,QAAQ;GACR,cAAc;EACf;CACF;CAED,IAAI,aAAqC;AACvC,SAAO;GACL,WAAW;GACX,cAAc;GACd,QAAQ;EACT;CACF;CAED;CAEA;CAEA;CAEA;CAEA;CAEA,IAAI;CAEJ;CAEA;CAEA,QAAQ;;CAGR;CAEA;CAEA,YAAY;CAEZ;CAEA;CAEA;CAEA;CAEA,YAAY;CAEZ;CAEA;CAEA;CAEA,AAAU;CAEV,AAAU;CAEV,YACEC,QAIA;EACA,MAAM,UAAU,CAAE,EAAC;EAEnB,KAAK,eACH,QAAQ,UACR,QAAQ,gBACR,uBAAuB,iBAAiB;EAC1C,KAAK,SAAS,KAAK;EAEnB,KAAK,eACH,QAAQ,eAAe,gBACvB,uBAAuB,sBAAsB;EAE/C,KAAK,QAAQ,QAAQ,SAAS,QAAQ,aAAa,KAAK;AACxD,OACG,KAAK,OAAO,WAAW,gBAAgB,IACtC,KAAK,OAAO,WAAW,QAAQ,IAC/B,KAAK,OAAO,WAAW,KAAK,KAC9B,CAAC,KAAK,OAAO,SAAS,YAAY,CAElC,OAAM,IAAI,MACR;GACE,CAAC,2BAA2B,EAAE,KAAK,MAAM,kDAAkD,CAAC;GAC5F,CAAC,0DAA0D,CAAC;GAC5D,CAAC,0CAA0C,CAAC;GAC5C;GACA,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,KAAK,YAAY;AAClC,OAAI;IACF,MAAM,MAAM,MAAM,KAAK,OAAO,YAAY,OACxC,SACA,eACD;AACD,WAAO;GACR,SAAQ,GAAG;IACV,MAAM,QAAQ,sBAAsB,EAAE;AACtC,UAAM;GACP;EACF,EAAC;CACH;;;;;;;CAQD,AAAU,kBACRC,SAC0B;AAC1B,MAAI,CAAC,KAAK,QAAQ;GAChB,MAAMC,uBAA6C,EACjD,SAAS,KAAK,aAAa,QAC5B;GAED,MAAM,WAAW,YAAY,qBAAqB;GAElD,MAAM,SAAS;IACb,GAAG,KAAK;IACR,SAAS;IACT,SAAS,KAAK;IACd,YAAY;GACb;AAED,OAAI,CAAC,OAAO,SACV,OAAO,OAAO;GAGhB,KAAK,SAAS,IAAIC,SAAa;EAChC;EACD,MAAM,iBAAiB;GACrB,GAAG,KAAK;GACR,GAAG;EACJ;AACD,SAAO;CACR;CAED,WAAW;AACT,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"llms.js","names":["OpenAI","fields?: Partial<OpenAIInput> &\n BaseLLMParams & {\n configuration?: ClientOptions;\n }","options?: this[\"ParsedCallOptions\"]","prompts: string[]","options: this[\"ParsedCallOptions\"]","runManager?: CallbackManagerForLLMRun","choices: OpenAIClient.CompletionChoice[]","tokenUsage: TokenUsage","response: Omit<OpenAIClient.Completion, \"choices\"> | undefined","choices","input: string","request:\n | OpenAIClient.CompletionCreateParamsStreaming\n | OpenAIClient.CompletionCreateParamsNonStreaming","options?: OpenAICoreRequestOptions","options: OpenAICoreRequestOptions | undefined","openAIEndpointConfig: OpenAIEndpointConfig","OpenAIClient"],"sources":["../src/llms.ts"],"sourcesContent":["import type { TiktokenModel } from \"js-tiktoken/lite\";\nimport { type ClientOptions, OpenAI as OpenAIClient } from \"openai\";\nimport { calculateMaxTokens } from \"@langchain/core/language_models/base\";\nimport { CallbackManagerForLLMRun } from \"@langchain/core/callbacks/manager\";\nimport { GenerationChunk, type LLMResult } from \"@langchain/core/outputs\";\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\nimport {\n BaseLLM,\n type BaseLLMParams,\n} from \"@langchain/core/language_models/llms\";\nimport { chunkArray } from \"@langchain/core/utils/chunk_array\";\nimport type {\n OpenAIApiKey,\n OpenAICallOptions,\n OpenAICoreRequestOptions,\n OpenAIInput,\n} from \"./types.js\";\nimport {\n OpenAIEndpointConfig,\n getEndpoint,\n getHeadersWithUserAgent,\n} from \"./utils/azure.js\";\nimport { wrapOpenAIClientError } from \"./utils/client.js\";\n\nexport type { OpenAICallOptions, OpenAIInput };\n\n/**\n * Interface for tracking token usage in OpenAI calls.\n */\ninterface TokenUsage {\n completionTokens?: number;\n promptTokens?: number;\n totalTokens?: number;\n}\n\n/**\n * Wrapper around OpenAI large language models.\n *\n * To use you should have the `openai` package installed, with the\n * `OPENAI_API_KEY` environment variable set.\n *\n * To use with Azure, import the `AzureOpenAI` class.\n *\n * @remarks\n * Any parameters that are valid to be passed to {@link\n * https://platform.openai.com/docs/api-reference/completions/create |\n * `openai.createCompletion`} can be passed through {@link modelKwargs}, even\n * if not explicitly available on this class.\n * @example\n * ```typescript\n * const model = new OpenAI({\n * modelName: \"gpt-4\",\n * temperature: 0.7,\n * maxTokens: 1000,\n * maxRetries: 5,\n * });\n *\n * const res = await model.invoke(\n * \"Question: What would be a good company name for a company that makes colorful socks?\\nAnswer:\"\n * );\n * console.log({ res });\n * ```\n */\nexport class OpenAI<CallOptions extends OpenAICallOptions = OpenAICallOptions>\n extends BaseLLM<CallOptions>\n implements Partial<OpenAIInput>\n{\n static lc_name() {\n return \"OpenAI\";\n }\n\n get callKeys() {\n return [...super.callKeys, \"options\"];\n }\n\n lc_serializable = true;\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n openAIApiKey: \"OPENAI_API_KEY\",\n apiKey: \"OPENAI_API_KEY\",\n organization: \"OPENAI_ORGANIZATION\",\n };\n }\n\n get lc_aliases(): Record<string, string> {\n return {\n modelName: \"model\",\n openAIApiKey: \"openai_api_key\",\n apiKey: \"openai_api_key\",\n };\n }\n\n temperature?: number;\n\n maxTokens?: number;\n\n topP?: number;\n\n frequencyPenalty?: number;\n\n presencePenalty?: number;\n\n n = 1;\n\n bestOf?: number;\n\n logitBias?: Record<string, number>;\n\n model = \"gpt-3.5-turbo-instruct\";\n\n /** @deprecated Use \"model\" instead */\n modelName: string;\n\n modelKwargs?: OpenAIInput[\"modelKwargs\"];\n\n batchSize = 20;\n\n timeout?: number;\n\n stop?: string[];\n\n stopSequences?: string[];\n\n user?: string;\n\n streaming = false;\n\n openAIApiKey?: OpenAIApiKey;\n\n apiKey?: OpenAIApiKey;\n\n organization?: string;\n\n protected client: OpenAIClient;\n\n protected clientConfig: ClientOptions;\n\n constructor(\n fields?: Partial<OpenAIInput> &\n BaseLLMParams & {\n configuration?: ClientOptions;\n }\n ) {\n super(fields ?? {});\n\n this.openAIApiKey =\n fields?.apiKey ??\n fields?.openAIApiKey ??\n getEnvironmentVariable(\"OPENAI_API_KEY\");\n this.apiKey = this.openAIApiKey;\n\n this.organization =\n fields?.configuration?.organization ??\n getEnvironmentVariable(\"OPENAI_ORGANIZATION\");\n\n this.model = fields?.model ?? fields?.modelName ?? this.model;\n if (\n (this.model?.startsWith(\"gpt-3.5-turbo\") ||\n this.model?.startsWith(\"gpt-4\") ||\n this.model?.startsWith(\"o1\")) &&\n !this.model?.includes(\"-instruct\")\n ) {\n throw new Error(\n [\n `Your chosen OpenAI model, \"${this.model}\", is a chat model and not a text-in/text-out LLM.`,\n `Passing it into the \"OpenAI\" class is no longer supported.`,\n `Please use the \"ChatOpenAI\" class instead.`,\n \"\",\n `See this page for more information:`,\n \"|\",\n `└> https://js.langchain.com/docs/integrations/chat/openai`,\n ].join(\"\\n\")\n );\n }\n this.modelName = this.model;\n this.modelKwargs = fields?.modelKwargs ?? {};\n this.batchSize = fields?.batchSize ?? this.batchSize;\n this.timeout = fields?.timeout;\n\n this.temperature = fields?.temperature ?? this.temperature;\n this.maxTokens = fields?.maxTokens ?? this.maxTokens;\n this.topP = fields?.topP ?? this.topP;\n this.frequencyPenalty = fields?.frequencyPenalty ?? this.frequencyPenalty;\n this.presencePenalty = fields?.presencePenalty ?? this.presencePenalty;\n this.n = fields?.n ?? this.n;\n this.bestOf = fields?.bestOf ?? this.bestOf;\n this.logitBias = fields?.logitBias;\n this.stop = fields?.stopSequences ?? fields?.stop;\n this.stopSequences = this.stop;\n this.user = fields?.user;\n\n this.streaming = fields?.streaming ?? false;\n\n if (this.streaming && this.bestOf && this.bestOf > 1) {\n throw new Error(\"Cannot stream results when bestOf > 1\");\n }\n\n this.clientConfig = {\n apiKey: this.apiKey,\n organization: this.organization,\n dangerouslyAllowBrowser: true,\n ...fields?.configuration,\n };\n }\n\n /**\n * Get the parameters used to invoke the model\n */\n invocationParams(\n options?: this[\"ParsedCallOptions\"]\n ): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> {\n return {\n model: this.model,\n temperature: this.temperature,\n max_tokens: this.maxTokens,\n top_p: this.topP,\n frequency_penalty: this.frequencyPenalty,\n presence_penalty: this.presencePenalty,\n n: this.n,\n best_of: this.bestOf,\n logit_bias: this.logitBias,\n stop: options?.stop ?? this.stopSequences,\n user: this.user,\n stream: this.streaming,\n ...this.modelKwargs,\n };\n }\n\n /** @ignore */\n _identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions {\n return {\n model_name: this.model,\n ...this.invocationParams(),\n ...this.clientConfig,\n };\n }\n\n /**\n * Get the identifying parameters for the model\n */\n identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, \"prompt\"> & {\n model_name: string;\n } & ClientOptions {\n return this._identifyingParams();\n }\n\n /**\n * Call out to OpenAI's endpoint with k unique prompts\n *\n * @param [prompts] - The prompts to pass into the model.\n * @param [options] - Optional list of stop words to use when generating.\n * @param [runManager] - Optional callback manager to use when generating.\n *\n * @returns The full LLM output.\n *\n * @example\n * ```ts\n * import { OpenAI } from \"langchain/llms/openai\";\n * const openai = new OpenAI();\n * const response = await openai.generate([\"Tell me a joke.\"]);\n * ```\n */\n async _generate(\n prompts: string[],\n options: this[\"ParsedCallOptions\"],\n runManager?: CallbackManagerForLLMRun\n ): Promise<LLMResult> {\n const subPrompts = chunkArray(prompts, this.batchSize);\n const choices: OpenAIClient.CompletionChoice[] = [];\n const tokenUsage: TokenUsage = {};\n\n const params = this.invocationParams(options);\n\n if (params.max_tokens === -1) {\n if (prompts.length !== 1) {\n throw new Error(\n \"max_tokens set to -1 not supported for multiple inputs\"\n );\n }\n params.max_tokens = await calculateMaxTokens({\n prompt: prompts[0],\n // Cast here to allow for other models that may not fit the union\n modelName: this.model as TiktokenModel,\n });\n }\n\n for (let i = 0; i < subPrompts.length; i += 1) {\n const data = params.stream\n ? await (async () => {\n const choices: OpenAIClient.CompletionChoice[] = [];\n let response: Omit<OpenAIClient.Completion, \"choices\"> | undefined;\n const stream = await this.completionWithRetry(\n {\n ...params,\n stream: true,\n prompt: subPrompts[i],\n },\n options\n );\n for await (const message of stream) {\n // on the first message set the response properties\n if (!response) {\n response = {\n id: message.id,\n object: message.object,\n created: message.created,\n model: message.model,\n };\n }\n\n // on all messages, update choice\n for (const part of message.choices) {\n if (!choices[part.index]) {\n choices[part.index] = part;\n } else {\n const choice = choices[part.index];\n choice.text += part.text;\n choice.finish_reason = part.finish_reason;\n choice.logprobs = part.logprobs;\n }\n // eslint-disable-next-line no-void\n void runManager?.handleLLMNewToken(part.text, {\n prompt: Math.floor(part.index / this.n),\n completion: part.index % this.n,\n });\n }\n }\n if (options.signal?.aborted) {\n throw new Error(\"AbortError\");\n }\n return { ...response, choices };\n })()\n : await this.completionWithRetry(\n {\n ...params,\n stream: false,\n prompt: subPrompts[i],\n },\n {\n signal: options.signal,\n ...options.options,\n }\n );\n\n choices.push(...data.choices);\n const {\n completion_tokens: completionTokens,\n prompt_tokens: promptTokens,\n total_tokens: totalTokens,\n } = data.usage\n ? data.usage\n : {\n completion_tokens: undefined,\n prompt_tokens: undefined,\n total_tokens: undefined,\n };\n\n if (completionTokens) {\n tokenUsage.completionTokens =\n (tokenUsage.completionTokens ?? 0) + completionTokens;\n }\n\n if (promptTokens) {\n tokenUsage.promptTokens = (tokenUsage.promptTokens ?? 0) + promptTokens;\n }\n\n if (totalTokens) {\n tokenUsage.totalTokens = (tokenUsage.totalTokens ?? 0) + totalTokens;\n }\n }\n\n const generations = chunkArray(choices, this.n).map((promptChoices) =>\n promptChoices.map((choice) => ({\n text: choice.text ?? \"\",\n generationInfo: {\n finishReason: choice.finish_reason,\n logprobs: choice.logprobs,\n },\n }))\n );\n return {\n generations,\n llmOutput: { tokenUsage },\n };\n }\n\n // TODO(jacoblee): Refactor with _generate(..., {stream: true}) implementation?\n async *_streamResponseChunks(\n input: string,\n options: this[\"ParsedCallOptions\"],\n runManager?: CallbackManagerForLLMRun\n ): AsyncGenerator<GenerationChunk> {\n const params = {\n ...this.invocationParams(options),\n prompt: input,\n stream: true as const,\n };\n const stream = await this.completionWithRetry(params, options);\n for await (const data of stream) {\n const choice = data?.choices[0];\n if (!choice) {\n continue;\n }\n const chunk = new GenerationChunk({\n text: choice.text,\n generationInfo: {\n finishReason: choice.finish_reason,\n },\n });\n yield chunk;\n // eslint-disable-next-line no-void\n void runManager?.handleLLMNewToken(chunk.text ?? \"\");\n }\n if (options.signal?.aborted) {\n throw new Error(\"AbortError\");\n }\n }\n\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n async completionWithRetry(\n request: OpenAIClient.CompletionCreateParamsStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<AsyncIterable<OpenAIClient.Completion>>;\n\n async completionWithRetry(\n request: OpenAIClient.CompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<OpenAIClient.Completions.Completion>;\n\n async completionWithRetry(\n request:\n | OpenAIClient.CompletionCreateParamsStreaming\n | OpenAIClient.CompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<\n AsyncIterable<OpenAIClient.Completion> | OpenAIClient.Completions.Completion\n > {\n const requestOptions = this._getClientOptions(options);\n return this.caller.call(async () => {\n try {\n const res = await this.client.completions.create(\n request,\n requestOptions\n );\n return res;\n } catch (e) {\n const error = wrapOpenAIClientError(e);\n throw error;\n }\n });\n }\n\n /**\n * Calls the OpenAI API with retry logic in case of failures.\n * @param request The request to send to the OpenAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the OpenAI API.\n */\n protected _getClientOptions(\n options: OpenAICoreRequestOptions | undefined\n ): OpenAICoreRequestOptions {\n if (!this.client) {\n const openAIEndpointConfig: OpenAIEndpointConfig = {\n baseURL: this.clientConfig.baseURL,\n };\n\n const endpoint = getEndpoint(openAIEndpointConfig);\n\n const params = {\n ...this.clientConfig,\n baseURL: endpoint,\n timeout: this.timeout,\n maxRetries: 0,\n };\n\n if (!params.baseURL) {\n delete params.baseURL;\n }\n\n params.defaultHeaders = getHeadersWithUserAgent(params.defaultHeaders);\n\n this.client = new OpenAIClient(params);\n }\n const requestOptions = {\n ...this.clientConfig,\n ...options,\n } as OpenAICoreRequestOptions;\n return requestOptions;\n }\n\n _llmType() {\n return \"openai\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,IAAaA,WAAb,cACU,QAEV;CACE,OAAO,UAAU;AACf,SAAO;CACR;CAED,IAAI,WAAW;AACb,SAAO,CAAC,GAAG,MAAM,UAAU,SAAU;CACtC;CAED,kBAAkB;CAElB,IAAI,aAAoD;AACtD,SAAO;GACL,cAAc;GACd,QAAQ;GACR,cAAc;EACf;CACF;CAED,IAAI,aAAqC;AACvC,SAAO;GACL,WAAW;GACX,cAAc;GACd,QAAQ;EACT;CACF;CAED;CAEA;CAEA;CAEA;CAEA;CAEA,IAAI;CAEJ;CAEA;CAEA,QAAQ;;CAGR;CAEA;CAEA,YAAY;CAEZ;CAEA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ANGED
@@ -1,4 +1,4 @@
1
- import { OpenAI as OpenAI$1 } from "openai";
1
+ import { ClientOptions, OpenAI as OpenAI$1 } from "openai";
2
2
  import { TiktokenModel } from "js-tiktoken/lite";
3
3
  import { BaseLanguageModelCallOptions } from "@langchain/core/language_models/base";
4
4
  import { ResponseFormatJSONObject, ResponseFormatJSONSchema, ResponseFormatText, ResponseFormatTextGrammar, ResponseFormatTextPython } from "openai/resources/shared";
@@ -11,6 +11,7 @@ import { InteropZodObject } from "@langchain/core/utils/types";
11
11
  */
12
12
  type OpenAIChatModelId = OpenAI$1.ChatModel | (string & NonNullable<unknown>);
13
13
  type OpenAIVerbosityParam = "low" | "medium" | "high" | null;
14
+ type OpenAIApiKey = ClientOptions["apiKey"];
14
15
  declare interface OpenAIBaseInput {
15
16
  /** Sampling temperature to use */
16
17
  temperature: number;
@@ -74,12 +75,12 @@ declare interface OpenAIBaseInput {
74
75
  * `OPENAI_API_KEY` environment variable.
75
76
  * Alias for `apiKey`
76
77
  */
77
- openAIApiKey?: string;
78
+ openAIApiKey?: OpenAIApiKey;
78
79
  /**
79
80
  * API key to use when making requests to OpenAI. Defaults to the value of
80
81
  * `OPENAI_API_KEY` environment variable.
81
82
  */
82
- apiKey?: string;
83
+ apiKey?: OpenAIApiKey;
83
84
  /**
84
85
  * The verbosity of the model's response.
85
86
  */
@@ -228,7 +229,6 @@ interface AzureOpenAIInput {
228
229
  azureADTokenProvider?: () => Promise<string>;
229
230
  }
230
231
  interface AzureOpenAIChatInput extends OpenAIChatInput, AzureOpenAIInput {
231
- openAIApiKey?: string;
232
232
  openAIApiVersion?: string;
233
233
  openAIBasePath?: string;
234
234
  deploymentName?: string;
@@ -259,5 +259,5 @@ type ChatOpenAIReasoningSummary = Omit<OpenAI$1.Responses.ResponseReasoningItem,
259
259
  type ChatOpenAIResponseFormat = ResponseFormatText | ResponseFormatJSONObject | ResponseFormatTextGrammar | ResponseFormatTextPython | ChatOpenAIResponseFormatJSONSchema;
260
260
  type ResponseFormatConfiguration = ResponseFormatText | ResponseFormatJSONObject | ResponseFormatJSONSchema;
261
261
  //#endregion
262
- export { AzureOpenAIChatInput, AzureOpenAIInput, ChatOpenAIReasoningSummary, ChatOpenAIResponseFormat, OpenAIBaseInput, OpenAICallOptions, OpenAIChatInput, OpenAIChatModelId, OpenAICoreRequestOptions, OpenAIInput, OpenAIVerbosityParam, ResponseFormatConfiguration, type TiktokenModel };
262
+ export { AzureOpenAIChatInput, AzureOpenAIInput, ChatOpenAIReasoningSummary, ChatOpenAIResponseFormat, OpenAIApiKey, OpenAIBaseInput, OpenAICallOptions, OpenAIChatInput, OpenAIChatModelId, OpenAICoreRequestOptions, OpenAIInput, OpenAIVerbosityParam, ResponseFormatConfiguration, type TiktokenModel };
263
263
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":["OpenAI","OpenAIClient","ResponseFormatText","ResponseFormatJSONObject","ResponseFormatJSONSchema","ResponseFormatTextPython","ResponseFormatTextGrammar","TiktokenModel","BaseLanguageModelCallOptions","InteropZodObject","OpenAIChatModelId","ChatModel","NonNullable","OpenAIVerbosityParam","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 } 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\";\n// reexport this type from the included package so we can easily override and extend it if needed in the future\n// also makes it easier for folks to import this type without digging around into the dependent packages\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 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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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?: string;\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?: string;\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 openAIApiKey?: string;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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"],"mappings":";;;;;;;;;;;AAW8E,KAAlEU,iBAAAA,GAAoBT,QAAAA,CAAaU,SAAiC,GAAA,CAAA,MAAA,GAAXC,WAAW,CAAA,OAAA,CAAA,CAAA;AAClEC,KAAAA,oBAAAA,GAAoB,KAAA,GAAA,QAAA,GAAA,MAAA,GAAA,IAAA;AACPC,kBAAAA,eAAAA,CAAe;EAAA;EAAA,WAuBxBC,EAAAA,MAAAA;EAAM;;;AAiDc;EAExBC,SAAAA,CAAAA,EAAAA,MAAAA;EACKE;;;;AAAsD;EAS9CC,mBAAW,CAAA,EAAA,MAASL;EAM5BM;EAAe,IAAA,EAAA,MAAA;EAAA;EAYiC,gBAuB7BC,EAAKE,MAAAA;EAAsB;EAAzC,eAMGF,EAAKI,MAAAA;EAAwB;EAOhB,CAAA,EAYnBxB,MAAAA;EAA2C;EA5DN,SAAA,CAAA,EAnExCc,MAmEwC,CAAA,MAAA,EAAA,MAAA,CAAA;EAoEvCc;EA0DAE,IAAAA,CAAAA,EAAAA,MAAAA;EAAoB;EAAA,SAASX,EAAAA,OAAAA;EAAe;AAAkB;AAK9E;;EACsC,WAAQhB,CAAAA,EAAAA,OAAAA;EAAwB;;;;;EAOjB,SAAA,EAAA,MAAA;EAM1C8B;EAA0B,KAAA,EAnM3BxB,iBAmM2B;EAAA;;;;EAMpB;EAIN2B,WAAAA,CAAAA,EAvMMtB,MAuMNsB,CAAAA,MAAwB,EAAA,GAAA,CAAA;EAAA;;;;EAA4E,IAAGhC,CAAAA,EAAAA,MAAAA,EAAAA;EAAwB;EAAqC,aAAA,CAAA,EAAA,MAAA,EAAA;EACpKiC;;;EAAgD,OAAGnC,CAAAA,EAAAA,MAAAA;EAAwB;AAA2B;;;;;;;;;;;;;cA9KlGU;;KAEJG,wBAAAA,GAA2Bf,QAAAA,CAAagB;UACnCC,iBAAAA,SAA0BV;;;;YAI7BQ;;;;;kBAKWG,WAAAA,SAAoBL;;;;;;UAM5BM,eAAAA,SAAwBN;;;;;;;;;;;;mBAYpBb,QAAAA,CAAaoB,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;eAuBtBE,MAAMvB,QAAAA,CAAaoB,IAAAA,CAAKE;;;;;;UAM7BtB,QAAAA,CAAaoB,IAAAA,CAAKI;;;;;;;cAOdxB,QAAAA,CAAayB;;;;;;;;;;;;iBAYVzB,QAAAA,CAAa0B,SAAAA,CAAUC;;;;;;;;UAQzBC,gBAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAwDgBC;;UAEhBC,oBAAAA,SAA6BX,iBAAiBS;;;;;;KAM1DG,kCAAAA,GAAqCC,KAAK7B;eAC9B6B,KAAK7B;;;;;;YAMNW,sBAAsBN;;;;;;KAM1ByB,0BAAAA,GAA6BD,KAAKhC,QAAAA,CAAa0B,SAAAA,CAAUQ;;;;;;WAMxDX,MAAMvB,QAAAA,CAAa0B,SAAAA,CAAUQ,qBAAAA,CAAsBC;;;;KAIpDC,wBAAAA,GAA2BnC,qBAAqBC,2BAA2BG,4BAA4BD,2BAA2B2B;KAClIM,2BAAAA,GAA8BpC,qBAAqBC,2BAA2BC"}
1
+ {"version":3,"file":"types.d.cts","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\";\n// reexport this type from the included package so we can easily override and extend it if needed in the future\n// also makes it easier for folks to import this type without digging around into the dependent packages\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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"],"mappings":";;;;;;;;;;;AAW8E,KAAlEW,iBAAAA,GAAoBV,QAAAA,CAAaW,SAAiC,GAAA,CAAA,MAAA,GAAXC,WAAW,CAAA,OAAA,CAAA,CAAA;AAClEC,KAAAA,oBAAAA,GAAoB,KAAA,GAAA,QAAA,GAAA,MAAA,GAAA,IAAA;AACpBC,KAAAA,YAAAA,GAAeb,aAAAA,CAAAA,QAAa,CAAA;AACfc,kBAAAA,eAAAA,CAAe;EAAA;EAAA,WAuBxBC,EAAAA,MAAAA;EAAM;;;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C;;;;;;;;UAQzBC,gBAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAwDgBC;;UAEhBC,oBAAAA,SAA6BX,iBAAiBS;;;;;KAK1DG,kCAAAA,GAAqCC,KAAK9B;eAC9B8B,KAAK9B;;;;;;YAMNY,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"}
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { OpenAI as OpenAI$1 } from "openai";
1
+ import { ClientOptions, OpenAI as OpenAI$1 } from "openai";
2
2
  import { InteropZodObject } from "@langchain/core/utils/types";
3
3
  import { BaseLanguageModelCallOptions } from "@langchain/core/language_models/base";
4
4
  import { TiktokenModel } from "js-tiktoken/lite";
@@ -11,6 +11,7 @@ import { ResponseFormatJSONObject, ResponseFormatJSONSchema, ResponseFormatText,
11
11
  */
12
12
  type OpenAIChatModelId = OpenAI$1.ChatModel | (string & NonNullable<unknown>);
13
13
  type OpenAIVerbosityParam = "low" | "medium" | "high" | null;
14
+ type OpenAIApiKey = ClientOptions["apiKey"];
14
15
  declare interface OpenAIBaseInput {
15
16
  /** Sampling temperature to use */
16
17
  temperature: number;
@@ -74,12 +75,12 @@ declare interface OpenAIBaseInput {
74
75
  * `OPENAI_API_KEY` environment variable.
75
76
  * Alias for `apiKey`
76
77
  */
77
- openAIApiKey?: string;
78
+ openAIApiKey?: OpenAIApiKey;
78
79
  /**
79
80
  * API key to use when making requests to OpenAI. Defaults to the value of
80
81
  * `OPENAI_API_KEY` environment variable.
81
82
  */
82
- apiKey?: string;
83
+ apiKey?: OpenAIApiKey;
83
84
  /**
84
85
  * The verbosity of the model's response.
85
86
  */
@@ -228,7 +229,6 @@ interface AzureOpenAIInput {
228
229
  azureADTokenProvider?: () => Promise<string>;
229
230
  }
230
231
  interface AzureOpenAIChatInput extends OpenAIChatInput, AzureOpenAIInput {
231
- openAIApiKey?: string;
232
232
  openAIApiVersion?: string;
233
233
  openAIBasePath?: string;
234
234
  deploymentName?: string;
@@ -259,5 +259,5 @@ type ChatOpenAIReasoningSummary = Omit<OpenAI$1.Responses.ResponseReasoningItem,
259
259
  type ChatOpenAIResponseFormat = ResponseFormatText | ResponseFormatJSONObject | ResponseFormatTextGrammar | ResponseFormatTextPython | ChatOpenAIResponseFormatJSONSchema;
260
260
  type ResponseFormatConfiguration = ResponseFormatText | ResponseFormatJSONObject | ResponseFormatJSONSchema;
261
261
  //#endregion
262
- export { AzureOpenAIChatInput, AzureOpenAIInput, ChatOpenAIReasoningSummary, ChatOpenAIResponseFormat, OpenAIBaseInput, OpenAICallOptions, OpenAIChatInput, OpenAIChatModelId, OpenAICoreRequestOptions, OpenAIInput, OpenAIVerbosityParam, ResponseFormatConfiguration, type TiktokenModel };
262
+ export { AzureOpenAIChatInput, AzureOpenAIInput, ChatOpenAIReasoningSummary, ChatOpenAIResponseFormat, OpenAIApiKey, OpenAIBaseInput, OpenAICallOptions, OpenAIChatInput, OpenAIChatModelId, OpenAICoreRequestOptions, OpenAIInput, OpenAIVerbosityParam, ResponseFormatConfiguration, type TiktokenModel };
263
263
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":["OpenAI","OpenAIClient","ResponseFormatText","ResponseFormatJSONObject","ResponseFormatJSONSchema","ResponseFormatTextPython","ResponseFormatTextGrammar","TiktokenModel","BaseLanguageModelCallOptions","InteropZodObject","OpenAIChatModelId","ChatModel","NonNullable","OpenAIVerbosityParam","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 } 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\";\n// reexport this type from the included package so we can easily override and extend it if needed in the future\n// also makes it easier for folks to import this type without digging around into the dependent packages\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 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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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?: string;\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?: string;\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 openAIApiKey?: string;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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"],"mappings":";;;;;;;;;;;AAW8E,KAAlEU,iBAAAA,GAAoBT,QAAAA,CAAaU,SAAiC,GAAA,CAAA,MAAA,GAAXC,WAAW,CAAA,OAAA,CAAA,CAAA;AAClEC,KAAAA,oBAAAA,GAAoB,KAAA,GAAA,QAAA,GAAA,MAAA,GAAA,IAAA;AACPC,kBAAAA,eAAAA,CAAe;EAAA;EAAA,WAuBxBC,EAAAA,MAAAA;EAAM;;;AAiDc;EAExBC,SAAAA,CAAAA,EAAAA,MAAAA;EACKE;;;;AAAsD;EAS9CC,mBAAW,CAAA,EAAA,MAASL;EAM5BM;EAAe,IAAA,EAAA,MAAA;EAAA;EAYiC,gBAuB7BC,EAAKE,MAAAA;EAAsB;EAAzC,eAMGF,EAAKI,M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AM1ByB,0BAAAA,GAA6BD,KAAKhC,QAAAA,CAAa0B,SAAAA,CAAUQ;;;;;;WAMxDX,MAAMvB,QAAAA,CAAa0B,SAAAA,CAAUQ,qBAAAA,CAAsBC;;;;KAIpDC,wBAAAA,GAA2BnC,qBAAqBC,2BAA2BG,4BAA4BD,2BAA2B2B;KAClIM,2BAAAA,GAA8BpC,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","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\";\n// reexport this type from the included package so we can easily override and extend it if needed in the future\n// also makes it easier for folks to import this type without digging around into the dependent packages\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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"],"mappings":";;;;;;;;;;;AAW8E,KAAlEW,iBAAAA,GAAoBV,QAAAA,CAAaW,SAAiC,GAAA,CAAA,MAAA,GAAXC,WAAW,CAAA,OAAA,CAAA,CAAA;AAClEC,KAAAA,oBAAAA,GAAoB,KAAA,GAAA,QAAA,GAAA,MAAA,GAAA,IAAA;AACpBC,KAAAA,YAAAA,GAAeb,aAAAA,CAAAA,QAAa,CAAA;AACfc,kBAAAA,eAAAA,CAAe;EAAA;EAAA,WAuBxBC,EAAAA,MAAAA;EAAM;;;;EA6CG,SAITH,CAAAA,EAAAA,MAAAA;EAAoB;AAEpC;AACA;;;EAIsC,mBAJKL,CAAAA,EAAAA,MAAAA;EAA4B;EAS9CY,IAAAA,EAAAA,MAAAA;EAMRC;EAAe,gBAAA,EAAA,MAAA;EAAA;EAYiC,eAuB7BC,EAAKE,MAAAA;EAAsB;EAAzC,CAAA,EAMVxB,MAAAA;EAA0C;EAOhB,SAYnBA,CAAAA,EA/HHgB,MA+HgBY,CAAAA,MAAUC,EAAAA,MAAAA,CAAAA;EAAoB;EA5DN,IAAA,CAAA,EAAA,MAAA;EAoEvCC;EA0DAE,SAAAA,EAAAA,OAAAA;EAAoB;;;AAA0C;EAK1EC,WAAAA,CAAAA,EAAAA,OAAAA;EAAkC;;;;;EAClB,SAMLjB,EAAAA,MAAAA;EAAM;EAAgC,KAAA,EA5L3CN,iBA4L2C;EAM1CyB;;;;EAAiC;EAM0B,WAA1DV,CAAAA,EAlMKT,MAkMLS,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA;EAAK;AAIlB;;;EAAyD,IAAGtB,CAAAA,EAAAA,MAAAA,EAAAA;EAAwB;EAA4B,aAAGE,CAAAA,EAAAA,MAAAA,EAAAA;EAAwB;AAAqC;AAChL;EAAuC,OAAA,CAAA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