langchain 0.3.22 → 0.3.24
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/universal.cjs +16 -9
- package/dist/chat_models/universal.d.ts +10 -5
- package/dist/chat_models/universal.js +14 -8
- package/dist/experimental/chrome_ai/app/dist/bundle.cjs +1250 -0
- package/dist/experimental/chrome_ai/app/dist/bundle.d.ts +1 -0
- package/dist/experimental/chrome_ai/app/dist/bundle.js +1249 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initChatModel = exports._inferModelProvider = void 0;
|
|
3
|
+
exports.initChatModel = exports.ConfigurableModel = exports._inferModelProvider = void 0;
|
|
4
4
|
const chat_models_1 = require("@langchain/core/language_models/chat_models");
|
|
5
5
|
const runnables_1 = require("@langchain/core/runnables");
|
|
6
6
|
const stream_1 = require("@langchain/core/utils/stream");
|
|
@@ -142,7 +142,8 @@ function _inferModelProvider(modelName) {
|
|
|
142
142
|
if (modelName.startsWith("gpt-3") ||
|
|
143
143
|
modelName.startsWith("gpt-4") ||
|
|
144
144
|
modelName.startsWith("o1") ||
|
|
145
|
-
modelName.startsWith("o3")
|
|
145
|
+
modelName.startsWith("o3") ||
|
|
146
|
+
modelName.startsWith("o4")) {
|
|
146
147
|
return "openai";
|
|
147
148
|
}
|
|
148
149
|
else if (modelName.startsWith("claude")) {
|
|
@@ -165,7 +166,12 @@ function _inferModelProvider(modelName) {
|
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
exports._inferModelProvider = _inferModelProvider;
|
|
168
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Internal class used to create chat models.
|
|
171
|
+
*
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
174
|
+
class ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
169
175
|
_llmType() {
|
|
170
176
|
return "chat_model";
|
|
171
177
|
}
|
|
@@ -220,7 +226,7 @@ class _ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
|
220
226
|
writable: true,
|
|
221
227
|
value: (schema, ...args) => {
|
|
222
228
|
this._queuedMethodOperations.withStructuredOutput = [schema, ...args];
|
|
223
|
-
return new
|
|
229
|
+
return new ConfigurableModel({
|
|
224
230
|
defaultConfig: this._defaultConfig,
|
|
225
231
|
configurableFields: this._configurableFields,
|
|
226
232
|
configPrefix: this._configPrefix,
|
|
@@ -274,7 +280,7 @@ class _ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
|
274
280
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
275
281
|
params) {
|
|
276
282
|
this._queuedMethodOperations.bindTools = [tools, params];
|
|
277
|
-
return new
|
|
283
|
+
return new ConfigurableModel({
|
|
278
284
|
defaultConfig: this._defaultConfig,
|
|
279
285
|
configurableFields: this._configurableFields,
|
|
280
286
|
configPrefix: this._configPrefix,
|
|
@@ -311,7 +317,7 @@ class _ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
|
311
317
|
const remainingConfig = Object.fromEntries(Object.entries(mergedConfig).filter(([k]) => k !== "configurable"));
|
|
312
318
|
remainingConfig.configurable = Object.fromEntries(Object.entries(mergedConfig.configurable || {}).filter(([k]) => this._configPrefix &&
|
|
313
319
|
!Object.keys(modelParams).includes(this._removePrefix(k, this._configPrefix))));
|
|
314
|
-
const newConfigurableModel = new
|
|
320
|
+
const newConfigurableModel = new ConfigurableModel({
|
|
315
321
|
defaultConfig: { ...this._defaultConfig, ...modelParams },
|
|
316
322
|
configurableFields: Array.isArray(this._configurableFields)
|
|
317
323
|
? [...this._configurableFields]
|
|
@@ -376,6 +382,7 @@ class _ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
|
376
382
|
return stream_1.IterableReadableStream.fromAsyncGenerator(wrappedGenerator());
|
|
377
383
|
}
|
|
378
384
|
}
|
|
385
|
+
exports.ConfigurableModel = ConfigurableModel;
|
|
379
386
|
// ################################# FOR CONTRIBUTORS #################################
|
|
380
387
|
//
|
|
381
388
|
// If adding support for a new provider, please append the provider
|
|
@@ -415,7 +422,7 @@ class _ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
|
415
422
|
* - string[]: Specified fields are configurable.
|
|
416
423
|
* @param {string} [fields.configPrefix] - Prefix for configurable fields at runtime.
|
|
417
424
|
* @param {Record<string, any>} [fields.params] - Additional keyword args to pass to the ChatModel constructor.
|
|
418
|
-
* @returns {Promise<
|
|
425
|
+
* @returns {Promise<ConfigurableModel<RunInput, CallOptions>>} A class which extends BaseChatModel.
|
|
419
426
|
* @throws {Error} If modelProvider cannot be inferred or isn't supported.
|
|
420
427
|
* @throws {Error} If the model provider integration package is not installed.
|
|
421
428
|
*
|
|
@@ -616,7 +623,7 @@ fields) {
|
|
|
616
623
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
617
624
|
const paramsCopy = { ...params };
|
|
618
625
|
if (configurableFieldsCopy === undefined) {
|
|
619
|
-
return new
|
|
626
|
+
return new ConfigurableModel({
|
|
620
627
|
defaultConfig: {
|
|
621
628
|
...paramsCopy,
|
|
622
629
|
model,
|
|
@@ -632,7 +639,7 @@ fields) {
|
|
|
632
639
|
if (modelProvider) {
|
|
633
640
|
paramsCopy.modelProvider = modelProvider;
|
|
634
641
|
}
|
|
635
|
-
return new
|
|
642
|
+
return new ConfigurableModel({
|
|
636
643
|
defaultConfig: paramsCopy,
|
|
637
644
|
configPrefix,
|
|
638
645
|
configurableFields: configurableFieldsCopy,
|
|
@@ -42,7 +42,12 @@ interface ConfigurableModelFields extends BaseChatModelParams {
|
|
|
42
42
|
*/
|
|
43
43
|
queuedMethodOperations?: Record<string, any>;
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Internal class used to create chat models.
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export declare class ConfigurableModel<RunInput extends BaseLanguageModelInput = BaseLanguageModelInput, CallOptions extends ConfigurableChatModelCallOptions = ConfigurableChatModelCallOptions> extends BaseChatModel<CallOptions, AIMessageChunk> {
|
|
46
51
|
_llmType(): string;
|
|
47
52
|
lc_namespace: string[];
|
|
48
53
|
_defaultConfig?: Record<string, any>;
|
|
@@ -62,7 +67,7 @@ declare class _ConfigurableModel<RunInput extends BaseLanguageModelInput = BaseL
|
|
|
62
67
|
constructor(fields: ConfigurableModelFields);
|
|
63
68
|
_model(config?: RunnableConfig): Promise<BaseChatModel<BaseChatModelCallOptions, AIMessageChunk>>;
|
|
64
69
|
_generate(messages: BaseMessage[], options?: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
|
|
65
|
-
bindTools(tools: BindToolsInput[], params?: Record<string, any>):
|
|
70
|
+
bindTools(tools: BindToolsInput[], params?: Record<string, any>): ConfigurableModel<RunInput, CallOptions>;
|
|
66
71
|
withStructuredOutput: BaseChatModel["withStructuredOutput"];
|
|
67
72
|
_modelParams(config?: RunnableConfig): Record<string, any>;
|
|
68
73
|
_removePrefix(str: string, prefix: string): string;
|
|
@@ -101,15 +106,15 @@ export declare function initChatModel<RunInput extends BaseLanguageModelInput =
|
|
|
101
106
|
modelProvider?: string;
|
|
102
107
|
configurableFields?: never;
|
|
103
108
|
configPrefix?: string;
|
|
104
|
-
}): Promise<
|
|
109
|
+
}): Promise<ConfigurableModel<RunInput, CallOptions>>;
|
|
105
110
|
export declare function initChatModel<RunInput extends BaseLanguageModelInput = BaseLanguageModelInput, CallOptions extends ConfigurableChatModelCallOptions = ConfigurableChatModelCallOptions>(model: never, options?: Partial<Record<string, any>> & {
|
|
106
111
|
modelProvider?: string;
|
|
107
112
|
configurableFields?: never;
|
|
108
113
|
configPrefix?: string;
|
|
109
|
-
}): Promise<
|
|
114
|
+
}): Promise<ConfigurableModel<RunInput, CallOptions>>;
|
|
110
115
|
export declare function initChatModel<RunInput extends BaseLanguageModelInput = BaseLanguageModelInput, CallOptions extends ConfigurableChatModelCallOptions = ConfigurableChatModelCallOptions>(model?: string, options?: Partial<Record<string, any>> & {
|
|
111
116
|
modelProvider?: string;
|
|
112
117
|
configurableFields?: ConfigurableFields;
|
|
113
118
|
configPrefix?: string;
|
|
114
|
-
}): Promise<
|
|
119
|
+
}): Promise<ConfigurableModel<RunInput, CallOptions>>;
|
|
115
120
|
export {};
|
|
@@ -139,7 +139,8 @@ export function _inferModelProvider(modelName) {
|
|
|
139
139
|
if (modelName.startsWith("gpt-3") ||
|
|
140
140
|
modelName.startsWith("gpt-4") ||
|
|
141
141
|
modelName.startsWith("o1") ||
|
|
142
|
-
modelName.startsWith("o3")
|
|
142
|
+
modelName.startsWith("o3") ||
|
|
143
|
+
modelName.startsWith("o4")) {
|
|
143
144
|
return "openai";
|
|
144
145
|
}
|
|
145
146
|
else if (modelName.startsWith("claude")) {
|
|
@@ -161,7 +162,12 @@ export function _inferModelProvider(modelName) {
|
|
|
161
162
|
return undefined;
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Internal class used to create chat models.
|
|
167
|
+
*
|
|
168
|
+
* @internal
|
|
169
|
+
*/
|
|
170
|
+
export class ConfigurableModel extends BaseChatModel {
|
|
165
171
|
_llmType() {
|
|
166
172
|
return "chat_model";
|
|
167
173
|
}
|
|
@@ -216,7 +222,7 @@ class _ConfigurableModel extends BaseChatModel {
|
|
|
216
222
|
writable: true,
|
|
217
223
|
value: (schema, ...args) => {
|
|
218
224
|
this._queuedMethodOperations.withStructuredOutput = [schema, ...args];
|
|
219
|
-
return new
|
|
225
|
+
return new ConfigurableModel({
|
|
220
226
|
defaultConfig: this._defaultConfig,
|
|
221
227
|
configurableFields: this._configurableFields,
|
|
222
228
|
configPrefix: this._configPrefix,
|
|
@@ -270,7 +276,7 @@ class _ConfigurableModel extends BaseChatModel {
|
|
|
270
276
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
271
277
|
params) {
|
|
272
278
|
this._queuedMethodOperations.bindTools = [tools, params];
|
|
273
|
-
return new
|
|
279
|
+
return new ConfigurableModel({
|
|
274
280
|
defaultConfig: this._defaultConfig,
|
|
275
281
|
configurableFields: this._configurableFields,
|
|
276
282
|
configPrefix: this._configPrefix,
|
|
@@ -307,7 +313,7 @@ class _ConfigurableModel extends BaseChatModel {
|
|
|
307
313
|
const remainingConfig = Object.fromEntries(Object.entries(mergedConfig).filter(([k]) => k !== "configurable"));
|
|
308
314
|
remainingConfig.configurable = Object.fromEntries(Object.entries(mergedConfig.configurable || {}).filter(([k]) => this._configPrefix &&
|
|
309
315
|
!Object.keys(modelParams).includes(this._removePrefix(k, this._configPrefix))));
|
|
310
|
-
const newConfigurableModel = new
|
|
316
|
+
const newConfigurableModel = new ConfigurableModel({
|
|
311
317
|
defaultConfig: { ...this._defaultConfig, ...modelParams },
|
|
312
318
|
configurableFields: Array.isArray(this._configurableFields)
|
|
313
319
|
? [...this._configurableFields]
|
|
@@ -411,7 +417,7 @@ class _ConfigurableModel extends BaseChatModel {
|
|
|
411
417
|
* - string[]: Specified fields are configurable.
|
|
412
418
|
* @param {string} [fields.configPrefix] - Prefix for configurable fields at runtime.
|
|
413
419
|
* @param {Record<string, any>} [fields.params] - Additional keyword args to pass to the ChatModel constructor.
|
|
414
|
-
* @returns {Promise<
|
|
420
|
+
* @returns {Promise<ConfigurableModel<RunInput, CallOptions>>} A class which extends BaseChatModel.
|
|
415
421
|
* @throws {Error} If modelProvider cannot be inferred or isn't supported.
|
|
416
422
|
* @throws {Error} If the model provider integration package is not installed.
|
|
417
423
|
*
|
|
@@ -612,7 +618,7 @@ fields) {
|
|
|
612
618
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
613
619
|
const paramsCopy = { ...params };
|
|
614
620
|
if (configurableFieldsCopy === undefined) {
|
|
615
|
-
return new
|
|
621
|
+
return new ConfigurableModel({
|
|
616
622
|
defaultConfig: {
|
|
617
623
|
...paramsCopy,
|
|
618
624
|
model,
|
|
@@ -628,7 +634,7 @@ fields) {
|
|
|
628
634
|
if (modelProvider) {
|
|
629
635
|
paramsCopy.modelProvider = modelProvider;
|
|
630
636
|
}
|
|
631
|
-
return new
|
|
637
|
+
return new ConfigurableModel({
|
|
632
638
|
defaultConfig: paramsCopy,
|
|
633
639
|
configPrefix,
|
|
634
640
|
configurableFields: configurableFieldsCopy,
|