langchain 0.3.23 → 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.
|
@@ -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");
|
|
@@ -166,7 +166,12 @@ function _inferModelProvider(modelName) {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
exports._inferModelProvider = _inferModelProvider;
|
|
169
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Internal class used to create chat models.
|
|
171
|
+
*
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
174
|
+
class ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
170
175
|
_llmType() {
|
|
171
176
|
return "chat_model";
|
|
172
177
|
}
|
|
@@ -221,7 +226,7 @@ class _ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
|
221
226
|
writable: true,
|
|
222
227
|
value: (schema, ...args) => {
|
|
223
228
|
this._queuedMethodOperations.withStructuredOutput = [schema, ...args];
|
|
224
|
-
return new
|
|
229
|
+
return new ConfigurableModel({
|
|
225
230
|
defaultConfig: this._defaultConfig,
|
|
226
231
|
configurableFields: this._configurableFields,
|
|
227
232
|
configPrefix: this._configPrefix,
|
|
@@ -275,7 +280,7 @@ class _ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
|
275
280
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
276
281
|
params) {
|
|
277
282
|
this._queuedMethodOperations.bindTools = [tools, params];
|
|
278
|
-
return new
|
|
283
|
+
return new ConfigurableModel({
|
|
279
284
|
defaultConfig: this._defaultConfig,
|
|
280
285
|
configurableFields: this._configurableFields,
|
|
281
286
|
configPrefix: this._configPrefix,
|
|
@@ -312,7 +317,7 @@ class _ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
|
312
317
|
const remainingConfig = Object.fromEntries(Object.entries(mergedConfig).filter(([k]) => k !== "configurable"));
|
|
313
318
|
remainingConfig.configurable = Object.fromEntries(Object.entries(mergedConfig.configurable || {}).filter(([k]) => this._configPrefix &&
|
|
314
319
|
!Object.keys(modelParams).includes(this._removePrefix(k, this._configPrefix))));
|
|
315
|
-
const newConfigurableModel = new
|
|
320
|
+
const newConfigurableModel = new ConfigurableModel({
|
|
316
321
|
defaultConfig: { ...this._defaultConfig, ...modelParams },
|
|
317
322
|
configurableFields: Array.isArray(this._configurableFields)
|
|
318
323
|
? [...this._configurableFields]
|
|
@@ -377,6 +382,7 @@ class _ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
|
377
382
|
return stream_1.IterableReadableStream.fromAsyncGenerator(wrappedGenerator());
|
|
378
383
|
}
|
|
379
384
|
}
|
|
385
|
+
exports.ConfigurableModel = ConfigurableModel;
|
|
380
386
|
// ################################# FOR CONTRIBUTORS #################################
|
|
381
387
|
//
|
|
382
388
|
// If adding support for a new provider, please append the provider
|
|
@@ -416,7 +422,7 @@ class _ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
|
416
422
|
* - string[]: Specified fields are configurable.
|
|
417
423
|
* @param {string} [fields.configPrefix] - Prefix for configurable fields at runtime.
|
|
418
424
|
* @param {Record<string, any>} [fields.params] - Additional keyword args to pass to the ChatModel constructor.
|
|
419
|
-
* @returns {Promise<
|
|
425
|
+
* @returns {Promise<ConfigurableModel<RunInput, CallOptions>>} A class which extends BaseChatModel.
|
|
420
426
|
* @throws {Error} If modelProvider cannot be inferred or isn't supported.
|
|
421
427
|
* @throws {Error} If the model provider integration package is not installed.
|
|
422
428
|
*
|
|
@@ -617,7 +623,7 @@ fields) {
|
|
|
617
623
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
618
624
|
const paramsCopy = { ...params };
|
|
619
625
|
if (configurableFieldsCopy === undefined) {
|
|
620
|
-
return new
|
|
626
|
+
return new ConfigurableModel({
|
|
621
627
|
defaultConfig: {
|
|
622
628
|
...paramsCopy,
|
|
623
629
|
model,
|
|
@@ -633,7 +639,7 @@ fields) {
|
|
|
633
639
|
if (modelProvider) {
|
|
634
640
|
paramsCopy.modelProvider = modelProvider;
|
|
635
641
|
}
|
|
636
|
-
return new
|
|
642
|
+
return new ConfigurableModel({
|
|
637
643
|
defaultConfig: paramsCopy,
|
|
638
644
|
configPrefix,
|
|
639
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 {};
|
|
@@ -162,7 +162,12 @@ export function _inferModelProvider(modelName) {
|
|
|
162
162
|
return undefined;
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Internal class used to create chat models.
|
|
167
|
+
*
|
|
168
|
+
* @internal
|
|
169
|
+
*/
|
|
170
|
+
export class ConfigurableModel extends BaseChatModel {
|
|
166
171
|
_llmType() {
|
|
167
172
|
return "chat_model";
|
|
168
173
|
}
|
|
@@ -217,7 +222,7 @@ class _ConfigurableModel extends BaseChatModel {
|
|
|
217
222
|
writable: true,
|
|
218
223
|
value: (schema, ...args) => {
|
|
219
224
|
this._queuedMethodOperations.withStructuredOutput = [schema, ...args];
|
|
220
|
-
return new
|
|
225
|
+
return new ConfigurableModel({
|
|
221
226
|
defaultConfig: this._defaultConfig,
|
|
222
227
|
configurableFields: this._configurableFields,
|
|
223
228
|
configPrefix: this._configPrefix,
|
|
@@ -271,7 +276,7 @@ class _ConfigurableModel extends BaseChatModel {
|
|
|
271
276
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
272
277
|
params) {
|
|
273
278
|
this._queuedMethodOperations.bindTools = [tools, params];
|
|
274
|
-
return new
|
|
279
|
+
return new ConfigurableModel({
|
|
275
280
|
defaultConfig: this._defaultConfig,
|
|
276
281
|
configurableFields: this._configurableFields,
|
|
277
282
|
configPrefix: this._configPrefix,
|
|
@@ -308,7 +313,7 @@ class _ConfigurableModel extends BaseChatModel {
|
|
|
308
313
|
const remainingConfig = Object.fromEntries(Object.entries(mergedConfig).filter(([k]) => k !== "configurable"));
|
|
309
314
|
remainingConfig.configurable = Object.fromEntries(Object.entries(mergedConfig.configurable || {}).filter(([k]) => this._configPrefix &&
|
|
310
315
|
!Object.keys(modelParams).includes(this._removePrefix(k, this._configPrefix))));
|
|
311
|
-
const newConfigurableModel = new
|
|
316
|
+
const newConfigurableModel = new ConfigurableModel({
|
|
312
317
|
defaultConfig: { ...this._defaultConfig, ...modelParams },
|
|
313
318
|
configurableFields: Array.isArray(this._configurableFields)
|
|
314
319
|
? [...this._configurableFields]
|
|
@@ -412,7 +417,7 @@ class _ConfigurableModel extends BaseChatModel {
|
|
|
412
417
|
* - string[]: Specified fields are configurable.
|
|
413
418
|
* @param {string} [fields.configPrefix] - Prefix for configurable fields at runtime.
|
|
414
419
|
* @param {Record<string, any>} [fields.params] - Additional keyword args to pass to the ChatModel constructor.
|
|
415
|
-
* @returns {Promise<
|
|
420
|
+
* @returns {Promise<ConfigurableModel<RunInput, CallOptions>>} A class which extends BaseChatModel.
|
|
416
421
|
* @throws {Error} If modelProvider cannot be inferred or isn't supported.
|
|
417
422
|
* @throws {Error} If the model provider integration package is not installed.
|
|
418
423
|
*
|
|
@@ -613,7 +618,7 @@ fields) {
|
|
|
613
618
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
614
619
|
const paramsCopy = { ...params };
|
|
615
620
|
if (configurableFieldsCopy === undefined) {
|
|
616
|
-
return new
|
|
621
|
+
return new ConfigurableModel({
|
|
617
622
|
defaultConfig: {
|
|
618
623
|
...paramsCopy,
|
|
619
624
|
model,
|
|
@@ -629,7 +634,7 @@ fields) {
|
|
|
629
634
|
if (modelProvider) {
|
|
630
635
|
paramsCopy.modelProvider = modelProvider;
|
|
631
636
|
}
|
|
632
|
-
return new
|
|
637
|
+
return new ConfigurableModel({
|
|
633
638
|
defaultConfig: paramsCopy,
|
|
634
639
|
configPrefix,
|
|
635
640
|
configurableFields: configurableFieldsCopy,
|