@langchain/openai 0.6.3 → 0.6.4
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/chat_models.cjs +15 -4
- package/dist/chat_models.d.ts +3 -2
- package/dist/chat_models.js +15 -4
- package/package.json +1 -1
package/dist/chat_models.cjs
CHANGED
|
@@ -1125,7 +1125,7 @@ class ChatOpenAIResponses extends BaseChatOpenAI {
|
|
|
1125
1125
|
};
|
|
1126
1126
|
}
|
|
1127
1127
|
}
|
|
1128
|
-
async *_streamResponseChunks(messages, options) {
|
|
1128
|
+
async *_streamResponseChunks(messages, options, runManager) {
|
|
1129
1129
|
const streamIterable = await this.completionWithRetry({
|
|
1130
1130
|
...this.invocationParams(options),
|
|
1131
1131
|
input: this._convertMessagesToResponsesParams(messages),
|
|
@@ -1136,6 +1136,10 @@ class ChatOpenAIResponses extends BaseChatOpenAI {
|
|
|
1136
1136
|
if (chunk == null)
|
|
1137
1137
|
continue;
|
|
1138
1138
|
yield chunk;
|
|
1139
|
+
await runManager?.handleLLMNewToken(chunk.text || "", {
|
|
1140
|
+
prompt: options.promptIndex ?? 0,
|
|
1141
|
+
completion: 0,
|
|
1142
|
+
}, undefined, undefined, undefined, { chunk });
|
|
1139
1143
|
}
|
|
1140
1144
|
}
|
|
1141
1145
|
async completionWithRetry(request, requestOptions) {
|
|
@@ -2619,6 +2623,12 @@ class ChatOpenAI extends BaseChatOpenAI {
|
|
|
2619
2623
|
}
|
|
2620
2624
|
constructor(fields) {
|
|
2621
2625
|
super(fields);
|
|
2626
|
+
Object.defineProperty(this, "fields", {
|
|
2627
|
+
enumerable: true,
|
|
2628
|
+
configurable: true,
|
|
2629
|
+
writable: true,
|
|
2630
|
+
value: fields
|
|
2631
|
+
});
|
|
2622
2632
|
/**
|
|
2623
2633
|
* Whether to use the responses API for all requests. If `false` the responses API will be used
|
|
2624
2634
|
* only when required in order to fulfill the request.
|
|
@@ -2678,14 +2688,15 @@ class ChatOpenAI extends BaseChatOpenAI {
|
|
|
2678
2688
|
}
|
|
2679
2689
|
async *_streamResponseChunks(messages, options, runManager) {
|
|
2680
2690
|
if (this._useResponsesApi(options)) {
|
|
2681
|
-
yield* this.responses._streamResponseChunks(messages, this._combineCallOptions(options));
|
|
2691
|
+
yield* this.responses._streamResponseChunks(messages, this._combineCallOptions(options), runManager);
|
|
2682
2692
|
return;
|
|
2683
2693
|
}
|
|
2684
2694
|
yield* this.completions._streamResponseChunks(messages, this._combineCallOptions(options), runManager);
|
|
2685
2695
|
}
|
|
2686
2696
|
withConfig(config) {
|
|
2687
|
-
|
|
2688
|
-
|
|
2697
|
+
const newModel = new ChatOpenAI(this.fields);
|
|
2698
|
+
newModel.defaultOptions = { ...this.defaultOptions, ...config };
|
|
2699
|
+
return newModel;
|
|
2689
2700
|
}
|
|
2690
2701
|
}
|
|
2691
2702
|
exports.ChatOpenAI = ChatOpenAI;
|
package/dist/chat_models.d.ts
CHANGED
|
@@ -271,7 +271,7 @@ type ChatResponsesInvocationParams = Omit<OpenAIClient.Responses.ResponseCreateP
|
|
|
271
271
|
export declare class ChatOpenAIResponses<CallOptions extends ChatOpenAIResponsesCallOptions = ChatOpenAIResponsesCallOptions> extends BaseChatOpenAI<CallOptions> {
|
|
272
272
|
invocationParams(options?: this["ParsedCallOptions"]): ChatResponsesInvocationParams;
|
|
273
273
|
_generate(messages: BaseMessage[], options: this["ParsedCallOptions"]): Promise<ChatResult>;
|
|
274
|
-
_streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"]): AsyncGenerator<ChatGenerationChunk>;
|
|
274
|
+
_streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
275
275
|
/**
|
|
276
276
|
* Calls the Responses API with retry logic in case of failures.
|
|
277
277
|
* @param request The request to send to the OpenAI API.
|
|
@@ -872,6 +872,7 @@ export interface ChatOpenAIFields extends BaseChatOpenAIFields {
|
|
|
872
872
|
* <br />
|
|
873
873
|
*/
|
|
874
874
|
export declare class ChatOpenAI<CallOptions extends ChatOpenAICallOptions = ChatOpenAICallOptions> extends BaseChatOpenAI<CallOptions> {
|
|
875
|
+
protected fields?: ChatOpenAIFields | undefined;
|
|
875
876
|
/**
|
|
876
877
|
* Whether to use the responses API for all requests. If `false` the responses API will be used
|
|
877
878
|
* only when required in order to fulfill the request.
|
|
@@ -880,7 +881,7 @@ export declare class ChatOpenAI<CallOptions extends ChatOpenAICallOptions = Chat
|
|
|
880
881
|
protected responses: ChatOpenAIResponses;
|
|
881
882
|
protected completions: ChatOpenAICompletions;
|
|
882
883
|
get lc_serializable_keys(): string[];
|
|
883
|
-
constructor(fields?: ChatOpenAIFields);
|
|
884
|
+
constructor(fields?: ChatOpenAIFields | undefined);
|
|
884
885
|
protected _useResponsesApi(options: this["ParsedCallOptions"] | undefined): boolean;
|
|
885
886
|
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
|
|
886
887
|
invocationParams(options?: this["ParsedCallOptions"]): ChatResponsesInvocationParams | ChatCompletionsInvocationParams;
|
package/dist/chat_models.js
CHANGED
|
@@ -1119,7 +1119,7 @@ export class ChatOpenAIResponses extends BaseChatOpenAI {
|
|
|
1119
1119
|
};
|
|
1120
1120
|
}
|
|
1121
1121
|
}
|
|
1122
|
-
async *_streamResponseChunks(messages, options) {
|
|
1122
|
+
async *_streamResponseChunks(messages, options, runManager) {
|
|
1123
1123
|
const streamIterable = await this.completionWithRetry({
|
|
1124
1124
|
...this.invocationParams(options),
|
|
1125
1125
|
input: this._convertMessagesToResponsesParams(messages),
|
|
@@ -1130,6 +1130,10 @@ export class ChatOpenAIResponses extends BaseChatOpenAI {
|
|
|
1130
1130
|
if (chunk == null)
|
|
1131
1131
|
continue;
|
|
1132
1132
|
yield chunk;
|
|
1133
|
+
await runManager?.handleLLMNewToken(chunk.text || "", {
|
|
1134
|
+
prompt: options.promptIndex ?? 0,
|
|
1135
|
+
completion: 0,
|
|
1136
|
+
}, undefined, undefined, undefined, { chunk });
|
|
1133
1137
|
}
|
|
1134
1138
|
}
|
|
1135
1139
|
async completionWithRetry(request, requestOptions) {
|
|
@@ -2611,6 +2615,12 @@ export class ChatOpenAI extends BaseChatOpenAI {
|
|
|
2611
2615
|
}
|
|
2612
2616
|
constructor(fields) {
|
|
2613
2617
|
super(fields);
|
|
2618
|
+
Object.defineProperty(this, "fields", {
|
|
2619
|
+
enumerable: true,
|
|
2620
|
+
configurable: true,
|
|
2621
|
+
writable: true,
|
|
2622
|
+
value: fields
|
|
2623
|
+
});
|
|
2614
2624
|
/**
|
|
2615
2625
|
* Whether to use the responses API for all requests. If `false` the responses API will be used
|
|
2616
2626
|
* only when required in order to fulfill the request.
|
|
@@ -2670,13 +2680,14 @@ export class ChatOpenAI extends BaseChatOpenAI {
|
|
|
2670
2680
|
}
|
|
2671
2681
|
async *_streamResponseChunks(messages, options, runManager) {
|
|
2672
2682
|
if (this._useResponsesApi(options)) {
|
|
2673
|
-
yield* this.responses._streamResponseChunks(messages, this._combineCallOptions(options));
|
|
2683
|
+
yield* this.responses._streamResponseChunks(messages, this._combineCallOptions(options), runManager);
|
|
2674
2684
|
return;
|
|
2675
2685
|
}
|
|
2676
2686
|
yield* this.completions._streamResponseChunks(messages, this._combineCallOptions(options), runManager);
|
|
2677
2687
|
}
|
|
2678
2688
|
withConfig(config) {
|
|
2679
|
-
|
|
2680
|
-
|
|
2689
|
+
const newModel = new ChatOpenAI(this.fields);
|
|
2690
|
+
newModel.defaultOptions = { ...this.defaultOptions, ...config };
|
|
2691
|
+
return newModel;
|
|
2681
2692
|
}
|
|
2682
2693
|
}
|