@langchain/openai 0.6.1 → 0.6.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.
- package/dist/azure/chat_models.cjs +1 -0
- package/dist/azure/chat_models.d.ts +2 -1
- package/dist/azure/chat_models.js +1 -0
- package/dist/chat_models.cjs +40 -23
- package/dist/chat_models.d.ts +8 -1
- package/dist/chat_models.js +40 -23
- package/package.json +1 -1
|
@@ -442,7 +442,8 @@ export declare class AzureChatOpenAI extends ChatOpenAI {
|
|
|
442
442
|
configuration?: ClientOptions;
|
|
443
443
|
});
|
|
444
444
|
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
|
|
445
|
-
|
|
445
|
+
/** @internal */
|
|
446
|
+
_getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
|
|
446
447
|
toJSON(): any;
|
|
447
448
|
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
448
449
|
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
package/dist/chat_models.cjs
CHANGED
|
@@ -543,6 +543,12 @@ class BaseChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
543
543
|
writable: true,
|
|
544
544
|
value: void 0
|
|
545
545
|
});
|
|
546
|
+
Object.defineProperty(this, "defaultOptions", {
|
|
547
|
+
enumerable: true,
|
|
548
|
+
configurable: true,
|
|
549
|
+
writable: true,
|
|
550
|
+
value: void 0
|
|
551
|
+
});
|
|
546
552
|
Object.defineProperty(this, "lc_serializable", {
|
|
547
553
|
enumerable: true,
|
|
548
554
|
configurable: true,
|
|
@@ -637,6 +643,13 @@ class BaseChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
637
643
|
}
|
|
638
644
|
return resFormat;
|
|
639
645
|
}
|
|
646
|
+
_combineCallOptions(additionalOptions) {
|
|
647
|
+
return {
|
|
648
|
+
...this.defaultOptions,
|
|
649
|
+
...(additionalOptions ?? {}),
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
/** @internal */
|
|
640
653
|
_getClientOptions(options) {
|
|
641
654
|
if (!this.client) {
|
|
642
655
|
const openAIEndpointConfig = {
|
|
@@ -691,6 +704,12 @@ class BaseChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
691
704
|
...kwargs,
|
|
692
705
|
});
|
|
693
706
|
}
|
|
707
|
+
async stream(input, options) {
|
|
708
|
+
return super.stream(input, this._combineCallOptions(options));
|
|
709
|
+
}
|
|
710
|
+
async invoke(input, options) {
|
|
711
|
+
return super.invoke(input, this._combineCallOptions(options));
|
|
712
|
+
}
|
|
694
713
|
/** @ignore */
|
|
695
714
|
_combineLLMOutput(...llmOutputs) {
|
|
696
715
|
return llmOutputs.reduce((acc, llmOutput) => {
|
|
@@ -2616,6 +2635,9 @@ class ChatOpenAI extends BaseChatOpenAI {
|
|
|
2616
2635
|
this.useResponsesApi = fields?.useResponsesApi ?? false;
|
|
2617
2636
|
this.responses = new ChatOpenAIResponses(fields);
|
|
2618
2637
|
this.completions = new ChatOpenAICompletions(fields);
|
|
2638
|
+
// Override `_getClientOptions` so sub classes of ChatOpenAI use the same client config
|
|
2639
|
+
this.responses._getClientOptions = this._getClientOptions;
|
|
2640
|
+
this.completions._getClientOptions = this._getClientOptions;
|
|
2619
2641
|
}
|
|
2620
2642
|
_useResponsesApi(options) {
|
|
2621
2643
|
const usesBuiltInTools = options?.tools?.some(isBuiltInTool);
|
|
@@ -2627,6 +2649,20 @@ class ChatOpenAI extends BaseChatOpenAI {
|
|
|
2627
2649
|
this.reasoning?.summary != null;
|
|
2628
2650
|
return this.useResponsesApi || usesBuiltInTools || hasResponsesOnlyKwargs;
|
|
2629
2651
|
}
|
|
2652
|
+
getLsParams(options) {
|
|
2653
|
+
const optionsWithDefaults = this._combineCallOptions(options);
|
|
2654
|
+
if (this._useResponsesApi(options)) {
|
|
2655
|
+
return this.responses.getLsParams(optionsWithDefaults);
|
|
2656
|
+
}
|
|
2657
|
+
return this.completions.getLsParams(optionsWithDefaults);
|
|
2658
|
+
}
|
|
2659
|
+
invocationParams(options) {
|
|
2660
|
+
const optionsWithDefaults = this._combineCallOptions(options);
|
|
2661
|
+
if (this._useResponsesApi(options)) {
|
|
2662
|
+
return this.responses.invocationParams(optionsWithDefaults);
|
|
2663
|
+
}
|
|
2664
|
+
return this.completions.invocationParams(optionsWithDefaults);
|
|
2665
|
+
}
|
|
2630
2666
|
/** @ignore */
|
|
2631
2667
|
async _generate(messages, options, runManager) {
|
|
2632
2668
|
if (this._useResponsesApi(options)) {
|
|
@@ -2636,33 +2672,14 @@ class ChatOpenAI extends BaseChatOpenAI {
|
|
|
2636
2672
|
}
|
|
2637
2673
|
async *_streamResponseChunks(messages, options, runManager) {
|
|
2638
2674
|
if (this._useResponsesApi(options)) {
|
|
2639
|
-
yield* this.responses._streamResponseChunks(messages, options);
|
|
2675
|
+
yield* this.responses._streamResponseChunks(messages, this._combineCallOptions(options));
|
|
2640
2676
|
return;
|
|
2641
2677
|
}
|
|
2642
|
-
yield* this.completions._streamResponseChunks(messages, options, runManager);
|
|
2678
|
+
yield* this.completions._streamResponseChunks(messages, this._combineCallOptions(options), runManager);
|
|
2643
2679
|
}
|
|
2644
2680
|
withConfig(config) {
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
// and still thread config options, which is important since this class is a "proxy"
|
|
2648
|
-
// for the inner chat classes. This will be fixed in a later version of langchain
|
|
2649
|
-
// when the core runnable interface is improved (0.4) to support this out of the box.
|
|
2650
|
-
const bindChatOpenAIConfig = (cls, config) => {
|
|
2651
|
-
const oldGenerate = cls._generate;
|
|
2652
|
-
const oldStreamResponseChunks = cls._streamResponseChunks;
|
|
2653
|
-
return Object.assign(cls, {
|
|
2654
|
-
_generate(messages, options, runManager) {
|
|
2655
|
-
return oldGenerate.call(cls, messages, { ...options, ...config }, runManager);
|
|
2656
|
-
},
|
|
2657
|
-
_streamResponseChunks(messages, options, runManager) {
|
|
2658
|
-
return oldStreamResponseChunks.call(cls, messages, { ...options, ...config }, runManager);
|
|
2659
|
-
},
|
|
2660
|
-
});
|
|
2661
|
-
};
|
|
2662
|
-
this.responses = bindChatOpenAIConfig(this.responses, config);
|
|
2663
|
-
this.completions = bindChatOpenAIConfig(this.completions, config);
|
|
2664
|
-
// Proxy chat class is also bound for `_useResponsesApi`,
|
|
2665
|
-
return bindChatOpenAIConfig(this, config);
|
|
2681
|
+
this.defaultOptions = { ...this.defaultOptions, ...config };
|
|
2682
|
+
return this;
|
|
2666
2683
|
}
|
|
2667
2684
|
}
|
|
2668
2685
|
exports.ChatOpenAI = ChatOpenAI;
|
package/dist/chat_models.d.ts
CHANGED
|
@@ -168,6 +168,7 @@ declare abstract class BaseChatOpenAI<CallOptions extends BaseChatOpenAICallOpti
|
|
|
168
168
|
* Specifies the service tier for prioritization and latency optimization.
|
|
169
169
|
*/
|
|
170
170
|
service_tier?: OpenAIClient.Chat.ChatCompletionCreateParams["service_tier"];
|
|
171
|
+
protected defaultOptions: CallOptions;
|
|
171
172
|
_llmType(): string;
|
|
172
173
|
static lc_name(): string;
|
|
173
174
|
get callKeys(): string[];
|
|
@@ -199,11 +200,15 @@ declare abstract class BaseChatOpenAI<CallOptions extends BaseChatOpenAICallOpti
|
|
|
199
200
|
* @internal
|
|
200
201
|
*/
|
|
201
202
|
protected _getResponseFormat(resFormat?: CallOptions["response_format"]): ResponseFormatText | ResponseFormatJSONObject | ResponseFormatJSONSchema | undefined;
|
|
202
|
-
protected
|
|
203
|
+
protected _combineCallOptions(additionalOptions?: this["ParsedCallOptions"]): this["ParsedCallOptions"];
|
|
204
|
+
/** @internal */
|
|
205
|
+
_getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
|
|
203
206
|
protected _convertChatOpenAIToolToCompletionsTool(tool: ChatOpenAIToolType, fields?: {
|
|
204
207
|
strict?: boolean;
|
|
205
208
|
}): OpenAIClient.ChatCompletionTool;
|
|
206
209
|
bindTools(tools: ChatOpenAIToolType[], kwargs?: Partial<CallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, CallOptions>;
|
|
210
|
+
stream(input: BaseLanguageModelInput, options?: CallOptions): Promise<import("@langchain/core/utils/stream").IterableReadableStream<AIMessageChunk>>;
|
|
211
|
+
invoke(input: BaseLanguageModelInput, options?: CallOptions): Promise<AIMessageChunk>;
|
|
207
212
|
/** @ignore */
|
|
208
213
|
_combineLLMOutput(...llmOutputs: OpenAILLMOutput[]): OpenAILLMOutput;
|
|
209
214
|
getNumTokensFromMessages(messages: BaseMessage[]): Promise<{
|
|
@@ -863,6 +868,8 @@ export declare class ChatOpenAI<CallOptions extends ChatOpenAICallOptions = Chat
|
|
|
863
868
|
get lc_serializable_keys(): string[];
|
|
864
869
|
constructor(fields?: ChatOpenAIFields);
|
|
865
870
|
protected _useResponsesApi(options: this["ParsedCallOptions"] | undefined): boolean;
|
|
871
|
+
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
|
|
872
|
+
invocationParams(options?: this["ParsedCallOptions"]): ChatResponsesInvocationParams | ChatCompletionsInvocationParams;
|
|
866
873
|
/** @ignore */
|
|
867
874
|
_generate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
|
|
868
875
|
_streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
package/dist/chat_models.js
CHANGED
|
@@ -538,6 +538,12 @@ class BaseChatOpenAI extends BaseChatModel {
|
|
|
538
538
|
writable: true,
|
|
539
539
|
value: void 0
|
|
540
540
|
});
|
|
541
|
+
Object.defineProperty(this, "defaultOptions", {
|
|
542
|
+
enumerable: true,
|
|
543
|
+
configurable: true,
|
|
544
|
+
writable: true,
|
|
545
|
+
value: void 0
|
|
546
|
+
});
|
|
541
547
|
Object.defineProperty(this, "lc_serializable", {
|
|
542
548
|
enumerable: true,
|
|
543
549
|
configurable: true,
|
|
@@ -632,6 +638,13 @@ class BaseChatOpenAI extends BaseChatModel {
|
|
|
632
638
|
}
|
|
633
639
|
return resFormat;
|
|
634
640
|
}
|
|
641
|
+
_combineCallOptions(additionalOptions) {
|
|
642
|
+
return {
|
|
643
|
+
...this.defaultOptions,
|
|
644
|
+
...(additionalOptions ?? {}),
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
/** @internal */
|
|
635
648
|
_getClientOptions(options) {
|
|
636
649
|
if (!this.client) {
|
|
637
650
|
const openAIEndpointConfig = {
|
|
@@ -686,6 +699,12 @@ class BaseChatOpenAI extends BaseChatModel {
|
|
|
686
699
|
...kwargs,
|
|
687
700
|
});
|
|
688
701
|
}
|
|
702
|
+
async stream(input, options) {
|
|
703
|
+
return super.stream(input, this._combineCallOptions(options));
|
|
704
|
+
}
|
|
705
|
+
async invoke(input, options) {
|
|
706
|
+
return super.invoke(input, this._combineCallOptions(options));
|
|
707
|
+
}
|
|
689
708
|
/** @ignore */
|
|
690
709
|
_combineLLMOutput(...llmOutputs) {
|
|
691
710
|
return llmOutputs.reduce((acc, llmOutput) => {
|
|
@@ -2609,6 +2628,9 @@ export class ChatOpenAI extends BaseChatOpenAI {
|
|
|
2609
2628
|
this.useResponsesApi = fields?.useResponsesApi ?? false;
|
|
2610
2629
|
this.responses = new ChatOpenAIResponses(fields);
|
|
2611
2630
|
this.completions = new ChatOpenAICompletions(fields);
|
|
2631
|
+
// Override `_getClientOptions` so sub classes of ChatOpenAI use the same client config
|
|
2632
|
+
this.responses._getClientOptions = this._getClientOptions;
|
|
2633
|
+
this.completions._getClientOptions = this._getClientOptions;
|
|
2612
2634
|
}
|
|
2613
2635
|
_useResponsesApi(options) {
|
|
2614
2636
|
const usesBuiltInTools = options?.tools?.some(isBuiltInTool);
|
|
@@ -2620,6 +2642,20 @@ export class ChatOpenAI extends BaseChatOpenAI {
|
|
|
2620
2642
|
this.reasoning?.summary != null;
|
|
2621
2643
|
return this.useResponsesApi || usesBuiltInTools || hasResponsesOnlyKwargs;
|
|
2622
2644
|
}
|
|
2645
|
+
getLsParams(options) {
|
|
2646
|
+
const optionsWithDefaults = this._combineCallOptions(options);
|
|
2647
|
+
if (this._useResponsesApi(options)) {
|
|
2648
|
+
return this.responses.getLsParams(optionsWithDefaults);
|
|
2649
|
+
}
|
|
2650
|
+
return this.completions.getLsParams(optionsWithDefaults);
|
|
2651
|
+
}
|
|
2652
|
+
invocationParams(options) {
|
|
2653
|
+
const optionsWithDefaults = this._combineCallOptions(options);
|
|
2654
|
+
if (this._useResponsesApi(options)) {
|
|
2655
|
+
return this.responses.invocationParams(optionsWithDefaults);
|
|
2656
|
+
}
|
|
2657
|
+
return this.completions.invocationParams(optionsWithDefaults);
|
|
2658
|
+
}
|
|
2623
2659
|
/** @ignore */
|
|
2624
2660
|
async _generate(messages, options, runManager) {
|
|
2625
2661
|
if (this._useResponsesApi(options)) {
|
|
@@ -2629,32 +2665,13 @@ export class ChatOpenAI extends BaseChatOpenAI {
|
|
|
2629
2665
|
}
|
|
2630
2666
|
async *_streamResponseChunks(messages, options, runManager) {
|
|
2631
2667
|
if (this._useResponsesApi(options)) {
|
|
2632
|
-
yield* this.responses._streamResponseChunks(messages, options);
|
|
2668
|
+
yield* this.responses._streamResponseChunks(messages, this._combineCallOptions(options));
|
|
2633
2669
|
return;
|
|
2634
2670
|
}
|
|
2635
|
-
yield* this.completions._streamResponseChunks(messages, options, runManager);
|
|
2671
|
+
yield* this.completions._streamResponseChunks(messages, this._combineCallOptions(options), runManager);
|
|
2636
2672
|
}
|
|
2637
2673
|
withConfig(config) {
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
// and still thread config options, which is important since this class is a "proxy"
|
|
2641
|
-
// for the inner chat classes. This will be fixed in a later version of langchain
|
|
2642
|
-
// when the core runnable interface is improved (0.4) to support this out of the box.
|
|
2643
|
-
const bindChatOpenAIConfig = (cls, config) => {
|
|
2644
|
-
const oldGenerate = cls._generate;
|
|
2645
|
-
const oldStreamResponseChunks = cls._streamResponseChunks;
|
|
2646
|
-
return Object.assign(cls, {
|
|
2647
|
-
_generate(messages, options, runManager) {
|
|
2648
|
-
return oldGenerate.call(cls, messages, { ...options, ...config }, runManager);
|
|
2649
|
-
},
|
|
2650
|
-
_streamResponseChunks(messages, options, runManager) {
|
|
2651
|
-
return oldStreamResponseChunks.call(cls, messages, { ...options, ...config }, runManager);
|
|
2652
|
-
},
|
|
2653
|
-
});
|
|
2654
|
-
};
|
|
2655
|
-
this.responses = bindChatOpenAIConfig(this.responses, config);
|
|
2656
|
-
this.completions = bindChatOpenAIConfig(this.completions, config);
|
|
2657
|
-
// Proxy chat class is also bound for `_useResponsesApi`,
|
|
2658
|
-
return bindChatOpenAIConfig(this, config);
|
|
2674
|
+
this.defaultOptions = { ...this.defaultOptions, ...config };
|
|
2675
|
+
return this;
|
|
2659
2676
|
}
|
|
2660
2677
|
}
|