@langchain/openai 0.2.1 → 0.2.3
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 +41 -15
- package/dist/chat_models.d.ts +6 -3
- package/dist/chat_models.js +41 -15
- package/dist/tools/dalle.cjs +13 -4
- package/dist/tools/dalle.d.ts +6 -2
- package/dist/tools/dalle.js +13 -4
- package/dist/types.d.ts +6 -1
- package/package.json +2 -2
package/dist/chat_models.cjs
CHANGED
|
@@ -47,7 +47,7 @@ function messageToOpenAIRole(message) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
exports.messageToOpenAIRole = messageToOpenAIRole;
|
|
50
|
-
function openAIResponseToChatMessage(message,
|
|
50
|
+
function openAIResponseToChatMessage(message, rawResponse, includeRawResponse) {
|
|
51
51
|
const rawToolCalls = message.tool_calls;
|
|
52
52
|
switch (message.role) {
|
|
53
53
|
case "assistant": {
|
|
@@ -62,15 +62,26 @@ function openAIResponseToChatMessage(message, messageId) {
|
|
|
62
62
|
invalidToolCalls.push((0, openai_tools_1.makeInvalidToolCall)(rawToolCall, e.message));
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
+
const additional_kwargs = {
|
|
66
|
+
function_call: message.function_call,
|
|
67
|
+
tool_calls: rawToolCalls,
|
|
68
|
+
};
|
|
69
|
+
if (includeRawResponse !== undefined) {
|
|
70
|
+
additional_kwargs.__raw_response = rawResponse;
|
|
71
|
+
}
|
|
72
|
+
let response_metadata;
|
|
73
|
+
if (rawResponse.system_fingerprint) {
|
|
74
|
+
response_metadata = {
|
|
75
|
+
system_fingerprint: rawResponse.system_fingerprint,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
65
78
|
return new messages_1.AIMessage({
|
|
66
79
|
content: message.content || "",
|
|
67
80
|
tool_calls: toolCalls,
|
|
68
81
|
invalid_tool_calls: invalidToolCalls,
|
|
69
|
-
additional_kwargs
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
},
|
|
73
|
-
id: messageId,
|
|
82
|
+
additional_kwargs,
|
|
83
|
+
response_metadata,
|
|
84
|
+
id: rawResponse.id,
|
|
74
85
|
});
|
|
75
86
|
}
|
|
76
87
|
default:
|
|
@@ -79,7 +90,7 @@ function openAIResponseToChatMessage(message, messageId) {
|
|
|
79
90
|
}
|
|
80
91
|
function _convertDeltaToMessageChunk(
|
|
81
92
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
|
-
delta,
|
|
93
|
+
delta, rawResponse, defaultRole, includeRawResponse) {
|
|
83
94
|
const role = delta.role ?? defaultRole;
|
|
84
95
|
const content = delta.content ?? "";
|
|
85
96
|
let additional_kwargs;
|
|
@@ -96,6 +107,9 @@ delta, messageId, defaultRole) {
|
|
|
96
107
|
else {
|
|
97
108
|
additional_kwargs = {};
|
|
98
109
|
}
|
|
110
|
+
if (includeRawResponse) {
|
|
111
|
+
additional_kwargs.__raw_response = rawResponse;
|
|
112
|
+
}
|
|
99
113
|
if (role === "user") {
|
|
100
114
|
return new messages_1.HumanMessageChunk({ content });
|
|
101
115
|
}
|
|
@@ -108,6 +122,7 @@ delta, messageId, defaultRole) {
|
|
|
108
122
|
args: rawToolCall.function?.arguments,
|
|
109
123
|
id: rawToolCall.id,
|
|
110
124
|
index: rawToolCall.index,
|
|
125
|
+
type: "tool_call_chunk",
|
|
111
126
|
});
|
|
112
127
|
}
|
|
113
128
|
}
|
|
@@ -115,7 +130,7 @@ delta, messageId, defaultRole) {
|
|
|
115
130
|
content,
|
|
116
131
|
tool_call_chunks: toolCallChunks,
|
|
117
132
|
additional_kwargs,
|
|
118
|
-
id:
|
|
133
|
+
id: rawResponse.id,
|
|
119
134
|
});
|
|
120
135
|
}
|
|
121
136
|
else if (role === "system") {
|
|
@@ -410,6 +425,12 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
410
425
|
writable: true,
|
|
411
426
|
value: void 0
|
|
412
427
|
});
|
|
428
|
+
Object.defineProperty(this, "__includeRawResponse", {
|
|
429
|
+
enumerable: true,
|
|
430
|
+
configurable: true,
|
|
431
|
+
writable: true,
|
|
432
|
+
value: void 0
|
|
433
|
+
});
|
|
413
434
|
Object.defineProperty(this, "client", {
|
|
414
435
|
enumerable: true,
|
|
415
436
|
configurable: true,
|
|
@@ -465,6 +486,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
465
486
|
this.stop = fields?.stopSequences ?? fields?.stop;
|
|
466
487
|
this.stopSequences = this?.stop;
|
|
467
488
|
this.user = fields?.user;
|
|
489
|
+
this.__includeRawResponse = fields?.__includeRawResponse;
|
|
468
490
|
if (this.azureOpenAIApiKey || this.azureADTokenProvider) {
|
|
469
491
|
if (!this.azureOpenAIApiInstanceName && !this.azureOpenAIBasePath) {
|
|
470
492
|
throw new Error("Azure OpenAI API instance name not found");
|
|
@@ -514,7 +536,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
514
536
|
/**
|
|
515
537
|
* Get the parameters used to invoke the model
|
|
516
538
|
*/
|
|
517
|
-
invocationParams(options) {
|
|
539
|
+
invocationParams(options, extra) {
|
|
518
540
|
function isStructuredToolArray(tools) {
|
|
519
541
|
return (tools !== undefined &&
|
|
520
542
|
tools.every((tool) => Array.isArray(tool.lc_namespace)));
|
|
@@ -523,7 +545,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
523
545
|
if (options?.stream_options !== undefined) {
|
|
524
546
|
streamOptionsConfig = { stream_options: options.stream_options };
|
|
525
547
|
}
|
|
526
|
-
else if (this.streamUsage && this.streaming) {
|
|
548
|
+
else if (this.streamUsage && (this.streaming || extra?.streaming)) {
|
|
527
549
|
streamOptionsConfig = { stream_options: { include_usage: true } };
|
|
528
550
|
}
|
|
529
551
|
const params = {
|
|
@@ -566,7 +588,9 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
566
588
|
async *_streamResponseChunks(messages, options, runManager) {
|
|
567
589
|
const messagesMapped = convertMessagesToOpenAIParams(messages);
|
|
568
590
|
const params = {
|
|
569
|
-
...this.invocationParams(options
|
|
591
|
+
...this.invocationParams(options, {
|
|
592
|
+
streaming: true,
|
|
593
|
+
}),
|
|
570
594
|
messages: messagesMapped,
|
|
571
595
|
stream: true,
|
|
572
596
|
};
|
|
@@ -585,7 +609,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
585
609
|
if (!delta) {
|
|
586
610
|
continue;
|
|
587
611
|
}
|
|
588
|
-
const chunk = _convertDeltaToMessageChunk(delta, data
|
|
612
|
+
const chunk = _convertDeltaToMessageChunk(delta, data, defaultRole, this.__includeRawResponse);
|
|
589
613
|
defaultRole = delta.role ?? defaultRole;
|
|
590
614
|
const newTokenIndices = {
|
|
591
615
|
prompt: options.promptIndex ?? 0,
|
|
@@ -599,6 +623,9 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
599
623
|
const generationInfo = { ...newTokenIndices };
|
|
600
624
|
if (choice.finish_reason !== undefined) {
|
|
601
625
|
generationInfo.finish_reason = choice.finish_reason;
|
|
626
|
+
// Only include system fingerprint in the last chunk for now
|
|
627
|
+
// to avoid concatenation issues
|
|
628
|
+
generationInfo.system_fingerprint = data.system_fingerprint;
|
|
602
629
|
}
|
|
603
630
|
if (this.logprobs) {
|
|
604
631
|
generationInfo.logprobs = choice.logprobs;
|
|
@@ -609,8 +636,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
609
636
|
generationInfo,
|
|
610
637
|
});
|
|
611
638
|
yield generationChunk;
|
|
612
|
-
|
|
613
|
-
void runManager?.handleLLMNewToken(generationChunk.text ?? "", newTokenIndices, undefined, undefined, undefined, { chunk: generationChunk });
|
|
639
|
+
await runManager?.handleLLMNewToken(generationChunk.text ?? "", newTokenIndices, undefined, undefined, undefined, { chunk: generationChunk });
|
|
614
640
|
}
|
|
615
641
|
if (usage) {
|
|
616
642
|
const generationChunk = new outputs_1.ChatGenerationChunk({
|
|
@@ -696,7 +722,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
696
722
|
const text = part.message?.content ?? "";
|
|
697
723
|
const generation = {
|
|
698
724
|
text,
|
|
699
|
-
message: openAIResponseToChatMessage(part.message ?? { role: "assistant" }, data.
|
|
725
|
+
message: openAIResponseToChatMessage(part.message ?? { role: "assistant" }, data, this.__includeRawResponse),
|
|
700
726
|
};
|
|
701
727
|
generation.generationInfo = {
|
|
702
728
|
...(part.finish_reason ? { finish_reason: part.finish_reason } : {}),
|
package/dist/chat_models.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type StructuredToolInterface } from "@langchain/core/tools";
|
|
|
6
6
|
import { BaseChatModel, LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
7
7
|
import type { BaseFunctionCallOptions, BaseLanguageModelInput, StructuredOutputMethodOptions, StructuredOutputMethodParams } from "@langchain/core/language_models/base";
|
|
8
8
|
import { z } from "zod";
|
|
9
|
-
import { Runnable } from "@langchain/core/runnables";
|
|
9
|
+
import { Runnable, RunnableToolLike } from "@langchain/core/runnables";
|
|
10
10
|
import type { AzureOpenAIInput, OpenAICallOptions, OpenAIChatInput, OpenAICoreRequestOptions, LegacyOpenAIInput } from "./types.js";
|
|
11
11
|
export type { AzureOpenAIInput, OpenAICallOptions, OpenAIChatInput };
|
|
12
12
|
interface TokenUsage {
|
|
@@ -113,6 +113,7 @@ export declare class ChatOpenAI<CallOptions extends ChatOpenAICallOptions = Chat
|
|
|
113
113
|
azureOpenAIApiDeploymentName?: string;
|
|
114
114
|
azureOpenAIBasePath?: string;
|
|
115
115
|
organization?: string;
|
|
116
|
+
__includeRawResponse?: boolean;
|
|
116
117
|
protected client: OpenAIClient;
|
|
117
118
|
protected clientConfig: ClientOptions;
|
|
118
119
|
constructor(fields?: Partial<OpenAIChatInput> & Partial<AzureOpenAIInput> & BaseChatModelParams & {
|
|
@@ -121,11 +122,13 @@ export declare class ChatOpenAI<CallOptions extends ChatOpenAICallOptions = Chat
|
|
|
121
122
|
/** @deprecated */
|
|
122
123
|
configuration?: ClientOptions & LegacyOpenAIInput);
|
|
123
124
|
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
|
|
124
|
-
bindTools(tools: (Record<string, unknown> | StructuredToolInterface)[], kwargs?: Partial<CallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, CallOptions>;
|
|
125
|
+
bindTools(tools: (Record<string, unknown> | StructuredToolInterface | RunnableToolLike)[], kwargs?: Partial<CallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, CallOptions>;
|
|
125
126
|
/**
|
|
126
127
|
* Get the parameters used to invoke the model
|
|
127
128
|
*/
|
|
128
|
-
invocationParams(options?: this["ParsedCallOptions"]
|
|
129
|
+
invocationParams(options?: this["ParsedCallOptions"], extra?: {
|
|
130
|
+
streaming?: boolean;
|
|
131
|
+
}): Omit<OpenAIClient.Chat.ChatCompletionCreateParams, "messages">;
|
|
129
132
|
/** @ignore */
|
|
130
133
|
_identifyingParams(): Omit<OpenAIClient.Chat.ChatCompletionCreateParams, "messages"> & {
|
|
131
134
|
model_name: string;
|
package/dist/chat_models.js
CHANGED
|
@@ -43,7 +43,7 @@ export function messageToOpenAIRole(message) {
|
|
|
43
43
|
throw new Error(`Unknown message type: ${type}`);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
function openAIResponseToChatMessage(message,
|
|
46
|
+
function openAIResponseToChatMessage(message, rawResponse, includeRawResponse) {
|
|
47
47
|
const rawToolCalls = message.tool_calls;
|
|
48
48
|
switch (message.role) {
|
|
49
49
|
case "assistant": {
|
|
@@ -58,15 +58,26 @@ function openAIResponseToChatMessage(message, messageId) {
|
|
|
58
58
|
invalidToolCalls.push(makeInvalidToolCall(rawToolCall, e.message));
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
const additional_kwargs = {
|
|
62
|
+
function_call: message.function_call,
|
|
63
|
+
tool_calls: rawToolCalls,
|
|
64
|
+
};
|
|
65
|
+
if (includeRawResponse !== undefined) {
|
|
66
|
+
additional_kwargs.__raw_response = rawResponse;
|
|
67
|
+
}
|
|
68
|
+
let response_metadata;
|
|
69
|
+
if (rawResponse.system_fingerprint) {
|
|
70
|
+
response_metadata = {
|
|
71
|
+
system_fingerprint: rawResponse.system_fingerprint,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
61
74
|
return new AIMessage({
|
|
62
75
|
content: message.content || "",
|
|
63
76
|
tool_calls: toolCalls,
|
|
64
77
|
invalid_tool_calls: invalidToolCalls,
|
|
65
|
-
additional_kwargs
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
id: messageId,
|
|
78
|
+
additional_kwargs,
|
|
79
|
+
response_metadata,
|
|
80
|
+
id: rawResponse.id,
|
|
70
81
|
});
|
|
71
82
|
}
|
|
72
83
|
default:
|
|
@@ -75,7 +86,7 @@ function openAIResponseToChatMessage(message, messageId) {
|
|
|
75
86
|
}
|
|
76
87
|
function _convertDeltaToMessageChunk(
|
|
77
88
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
-
delta,
|
|
89
|
+
delta, rawResponse, defaultRole, includeRawResponse) {
|
|
79
90
|
const role = delta.role ?? defaultRole;
|
|
80
91
|
const content = delta.content ?? "";
|
|
81
92
|
let additional_kwargs;
|
|
@@ -92,6 +103,9 @@ delta, messageId, defaultRole) {
|
|
|
92
103
|
else {
|
|
93
104
|
additional_kwargs = {};
|
|
94
105
|
}
|
|
106
|
+
if (includeRawResponse) {
|
|
107
|
+
additional_kwargs.__raw_response = rawResponse;
|
|
108
|
+
}
|
|
95
109
|
if (role === "user") {
|
|
96
110
|
return new HumanMessageChunk({ content });
|
|
97
111
|
}
|
|
@@ -104,6 +118,7 @@ delta, messageId, defaultRole) {
|
|
|
104
118
|
args: rawToolCall.function?.arguments,
|
|
105
119
|
id: rawToolCall.id,
|
|
106
120
|
index: rawToolCall.index,
|
|
121
|
+
type: "tool_call_chunk",
|
|
107
122
|
});
|
|
108
123
|
}
|
|
109
124
|
}
|
|
@@ -111,7 +126,7 @@ delta, messageId, defaultRole) {
|
|
|
111
126
|
content,
|
|
112
127
|
tool_call_chunks: toolCallChunks,
|
|
113
128
|
additional_kwargs,
|
|
114
|
-
id:
|
|
129
|
+
id: rawResponse.id,
|
|
115
130
|
});
|
|
116
131
|
}
|
|
117
132
|
else if (role === "system") {
|
|
@@ -406,6 +421,12 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
406
421
|
writable: true,
|
|
407
422
|
value: void 0
|
|
408
423
|
});
|
|
424
|
+
Object.defineProperty(this, "__includeRawResponse", {
|
|
425
|
+
enumerable: true,
|
|
426
|
+
configurable: true,
|
|
427
|
+
writable: true,
|
|
428
|
+
value: void 0
|
|
429
|
+
});
|
|
409
430
|
Object.defineProperty(this, "client", {
|
|
410
431
|
enumerable: true,
|
|
411
432
|
configurable: true,
|
|
@@ -461,6 +482,7 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
461
482
|
this.stop = fields?.stopSequences ?? fields?.stop;
|
|
462
483
|
this.stopSequences = this?.stop;
|
|
463
484
|
this.user = fields?.user;
|
|
485
|
+
this.__includeRawResponse = fields?.__includeRawResponse;
|
|
464
486
|
if (this.azureOpenAIApiKey || this.azureADTokenProvider) {
|
|
465
487
|
if (!this.azureOpenAIApiInstanceName && !this.azureOpenAIBasePath) {
|
|
466
488
|
throw new Error("Azure OpenAI API instance name not found");
|
|
@@ -510,7 +532,7 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
510
532
|
/**
|
|
511
533
|
* Get the parameters used to invoke the model
|
|
512
534
|
*/
|
|
513
|
-
invocationParams(options) {
|
|
535
|
+
invocationParams(options, extra) {
|
|
514
536
|
function isStructuredToolArray(tools) {
|
|
515
537
|
return (tools !== undefined &&
|
|
516
538
|
tools.every((tool) => Array.isArray(tool.lc_namespace)));
|
|
@@ -519,7 +541,7 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
519
541
|
if (options?.stream_options !== undefined) {
|
|
520
542
|
streamOptionsConfig = { stream_options: options.stream_options };
|
|
521
543
|
}
|
|
522
|
-
else if (this.streamUsage && this.streaming) {
|
|
544
|
+
else if (this.streamUsage && (this.streaming || extra?.streaming)) {
|
|
523
545
|
streamOptionsConfig = { stream_options: { include_usage: true } };
|
|
524
546
|
}
|
|
525
547
|
const params = {
|
|
@@ -562,7 +584,9 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
562
584
|
async *_streamResponseChunks(messages, options, runManager) {
|
|
563
585
|
const messagesMapped = convertMessagesToOpenAIParams(messages);
|
|
564
586
|
const params = {
|
|
565
|
-
...this.invocationParams(options
|
|
587
|
+
...this.invocationParams(options, {
|
|
588
|
+
streaming: true,
|
|
589
|
+
}),
|
|
566
590
|
messages: messagesMapped,
|
|
567
591
|
stream: true,
|
|
568
592
|
};
|
|
@@ -581,7 +605,7 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
581
605
|
if (!delta) {
|
|
582
606
|
continue;
|
|
583
607
|
}
|
|
584
|
-
const chunk = _convertDeltaToMessageChunk(delta, data
|
|
608
|
+
const chunk = _convertDeltaToMessageChunk(delta, data, defaultRole, this.__includeRawResponse);
|
|
585
609
|
defaultRole = delta.role ?? defaultRole;
|
|
586
610
|
const newTokenIndices = {
|
|
587
611
|
prompt: options.promptIndex ?? 0,
|
|
@@ -595,6 +619,9 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
595
619
|
const generationInfo = { ...newTokenIndices };
|
|
596
620
|
if (choice.finish_reason !== undefined) {
|
|
597
621
|
generationInfo.finish_reason = choice.finish_reason;
|
|
622
|
+
// Only include system fingerprint in the last chunk for now
|
|
623
|
+
// to avoid concatenation issues
|
|
624
|
+
generationInfo.system_fingerprint = data.system_fingerprint;
|
|
598
625
|
}
|
|
599
626
|
if (this.logprobs) {
|
|
600
627
|
generationInfo.logprobs = choice.logprobs;
|
|
@@ -605,8 +632,7 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
605
632
|
generationInfo,
|
|
606
633
|
});
|
|
607
634
|
yield generationChunk;
|
|
608
|
-
|
|
609
|
-
void runManager?.handleLLMNewToken(generationChunk.text ?? "", newTokenIndices, undefined, undefined, undefined, { chunk: generationChunk });
|
|
635
|
+
await runManager?.handleLLMNewToken(generationChunk.text ?? "", newTokenIndices, undefined, undefined, undefined, { chunk: generationChunk });
|
|
610
636
|
}
|
|
611
637
|
if (usage) {
|
|
612
638
|
const generationChunk = new ChatGenerationChunk({
|
|
@@ -692,7 +718,7 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
692
718
|
const text = part.message?.content ?? "";
|
|
693
719
|
const generation = {
|
|
694
720
|
text,
|
|
695
|
-
message: openAIResponseToChatMessage(part.message ?? { role: "assistant" }, data.
|
|
721
|
+
message: openAIResponseToChatMessage(part.message ?? { role: "assistant" }, data, this.__includeRawResponse),
|
|
696
722
|
};
|
|
697
723
|
generation.generationInfo = {
|
|
698
724
|
...(part.finish_reason ? { finish_reason: part.finish_reason } : {}),
|
package/dist/tools/dalle.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DallEAPIWrapper = void 0;
|
|
4
|
+
/* eslint-disable no-param-reassign */
|
|
4
5
|
const env_1 = require("@langchain/core/utils/env");
|
|
5
6
|
const openai_1 = require("openai");
|
|
6
7
|
const tools_1 = require("@langchain/core/tools");
|
|
@@ -12,6 +13,13 @@ class DallEAPIWrapper extends tools_1.Tool {
|
|
|
12
13
|
return "DallEAPIWrapper";
|
|
13
14
|
}
|
|
14
15
|
constructor(fields) {
|
|
16
|
+
// Shim for new base tool param name
|
|
17
|
+
if (fields?.responseFormat !== undefined &&
|
|
18
|
+
["url", "b64_json"].includes(fields.responseFormat)) {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
fields.dallEResponseFormat = fields.responseFormat;
|
|
21
|
+
fields.responseFormat = "content";
|
|
22
|
+
}
|
|
15
23
|
super(fields);
|
|
16
24
|
Object.defineProperty(this, "name", {
|
|
17
25
|
enumerable: true,
|
|
@@ -61,7 +69,7 @@ class DallEAPIWrapper extends tools_1.Tool {
|
|
|
61
69
|
writable: true,
|
|
62
70
|
value: "1024x1024"
|
|
63
71
|
});
|
|
64
|
-
Object.defineProperty(this, "
|
|
72
|
+
Object.defineProperty(this, "dallEResponseFormat", {
|
|
65
73
|
enumerable: true,
|
|
66
74
|
configurable: true,
|
|
67
75
|
writable: true,
|
|
@@ -88,7 +96,8 @@ class DallEAPIWrapper extends tools_1.Tool {
|
|
|
88
96
|
this.quality = fields?.quality ?? this.quality;
|
|
89
97
|
this.n = fields?.n ?? this.n;
|
|
90
98
|
this.size = fields?.size ?? this.size;
|
|
91
|
-
this.
|
|
99
|
+
this.dallEResponseFormat =
|
|
100
|
+
fields?.dallEResponseFormat ?? this.dallEResponseFormat;
|
|
92
101
|
this.user = fields?.user;
|
|
93
102
|
}
|
|
94
103
|
/** @ignore */
|
|
@@ -98,13 +107,13 @@ class DallEAPIWrapper extends tools_1.Tool {
|
|
|
98
107
|
prompt: input,
|
|
99
108
|
n: this.n,
|
|
100
109
|
size: this.size,
|
|
101
|
-
response_format: this.
|
|
110
|
+
response_format: this.dallEResponseFormat,
|
|
102
111
|
style: this.style,
|
|
103
112
|
quality: this.quality,
|
|
104
113
|
user: this.user,
|
|
105
114
|
});
|
|
106
115
|
let data = "";
|
|
107
|
-
if (this.
|
|
116
|
+
if (this.dallEResponseFormat === "url") {
|
|
108
117
|
[data] = response.data
|
|
109
118
|
.map((item) => item.url)
|
|
110
119
|
.filter((url) => url !== "undefined");
|
package/dist/tools/dalle.d.ts
CHANGED
|
@@ -58,7 +58,11 @@ export interface DallEAPIWrapperParams extends ToolParams {
|
|
|
58
58
|
* Must be one of "url" or "b64_json".
|
|
59
59
|
* @default "url"
|
|
60
60
|
*/
|
|
61
|
-
|
|
61
|
+
dallEResponseFormat?: "url" | "b64_json";
|
|
62
|
+
/**
|
|
63
|
+
* @deprecated Use dallEResponseFormat instead for the Dall-E response type.
|
|
64
|
+
*/
|
|
65
|
+
responseFormat?: any;
|
|
62
66
|
/**
|
|
63
67
|
* A unique identifier representing your end-user, which will help
|
|
64
68
|
* OpenAI to monitor and detect abuse.
|
|
@@ -83,7 +87,7 @@ export declare class DallEAPIWrapper extends Tool {
|
|
|
83
87
|
private quality;
|
|
84
88
|
private n;
|
|
85
89
|
private size;
|
|
86
|
-
private
|
|
90
|
+
private dallEResponseFormat;
|
|
87
91
|
private user?;
|
|
88
92
|
constructor(fields?: DallEAPIWrapperParams);
|
|
89
93
|
/** @ignore */
|
package/dist/tools/dalle.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
1
2
|
import { getEnvironmentVariable } from "@langchain/core/utils/env";
|
|
2
3
|
import { OpenAI as OpenAIClient } from "openai";
|
|
3
4
|
import { Tool } from "@langchain/core/tools";
|
|
@@ -9,6 +10,13 @@ export class DallEAPIWrapper extends Tool {
|
|
|
9
10
|
return "DallEAPIWrapper";
|
|
10
11
|
}
|
|
11
12
|
constructor(fields) {
|
|
13
|
+
// Shim for new base tool param name
|
|
14
|
+
if (fields?.responseFormat !== undefined &&
|
|
15
|
+
["url", "b64_json"].includes(fields.responseFormat)) {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
fields.dallEResponseFormat = fields.responseFormat;
|
|
18
|
+
fields.responseFormat = "content";
|
|
19
|
+
}
|
|
12
20
|
super(fields);
|
|
13
21
|
Object.defineProperty(this, "name", {
|
|
14
22
|
enumerable: true,
|
|
@@ -58,7 +66,7 @@ export class DallEAPIWrapper extends Tool {
|
|
|
58
66
|
writable: true,
|
|
59
67
|
value: "1024x1024"
|
|
60
68
|
});
|
|
61
|
-
Object.defineProperty(this, "
|
|
69
|
+
Object.defineProperty(this, "dallEResponseFormat", {
|
|
62
70
|
enumerable: true,
|
|
63
71
|
configurable: true,
|
|
64
72
|
writable: true,
|
|
@@ -85,7 +93,8 @@ export class DallEAPIWrapper extends Tool {
|
|
|
85
93
|
this.quality = fields?.quality ?? this.quality;
|
|
86
94
|
this.n = fields?.n ?? this.n;
|
|
87
95
|
this.size = fields?.size ?? this.size;
|
|
88
|
-
this.
|
|
96
|
+
this.dallEResponseFormat =
|
|
97
|
+
fields?.dallEResponseFormat ?? this.dallEResponseFormat;
|
|
89
98
|
this.user = fields?.user;
|
|
90
99
|
}
|
|
91
100
|
/** @ignore */
|
|
@@ -95,13 +104,13 @@ export class DallEAPIWrapper extends Tool {
|
|
|
95
104
|
prompt: input,
|
|
96
105
|
n: this.n,
|
|
97
106
|
size: this.size,
|
|
98
|
-
response_format: this.
|
|
107
|
+
response_format: this.dallEResponseFormat,
|
|
99
108
|
style: this.style,
|
|
100
109
|
quality: this.quality,
|
|
101
110
|
user: this.user,
|
|
102
111
|
});
|
|
103
112
|
let data = "";
|
|
104
|
-
if (this.
|
|
113
|
+
if (this.dallEResponseFormat === "url") {
|
|
105
114
|
[data] = response.data
|
|
106
115
|
.map((item) => item.url)
|
|
107
116
|
.filter((url) => url !== "undefined");
|
package/dist/types.d.ts
CHANGED
|
@@ -115,7 +115,12 @@ export interface OpenAIChatInput extends OpenAIBaseInput {
|
|
|
115
115
|
*/
|
|
116
116
|
topLogprobs?: number;
|
|
117
117
|
/** ChatGPT messages to pass as a prefix to the prompt */
|
|
118
|
-
prefixMessages?: OpenAIClient.Chat.
|
|
118
|
+
prefixMessages?: OpenAIClient.Chat.ChatCompletionMessageParam[];
|
|
119
|
+
/**
|
|
120
|
+
* Whether to include the raw OpenAI response in the output message's "additional_kwargs" field.
|
|
121
|
+
* Currently in experimental beta.
|
|
122
|
+
*/
|
|
123
|
+
__includeRawResponse?: boolean;
|
|
119
124
|
}
|
|
120
125
|
export declare interface AzureOpenAIInput {
|
|
121
126
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/openai",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "OpenAI integrations for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"author": "LangChain",
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@langchain/core": ">=0.2.
|
|
38
|
+
"@langchain/core": ">=0.2.16 <0.3.0",
|
|
39
39
|
"js-tiktoken": "^1.0.12",
|
|
40
40
|
"openai": "^4.49.1",
|
|
41
41
|
"zod": "^3.22.4",
|