@stackfactor/agent-utils 1.0.13 → 1.0.14
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAmVQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,KACV,GAAG;sBAyBG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAmfF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCAxYO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDA6rBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CA7vB8B,GAAG,KAAG,MAAM;;AAwzBzD,wBAOE"}
|
package/dist/cjs/langChain.js
CHANGED
|
@@ -191,17 +191,50 @@ const extractJSONFromResponse = (text) => {
|
|
|
191
191
|
}
|
|
192
192
|
return null;
|
|
193
193
|
};
|
|
194
|
+
/**
|
|
195
|
+
* Maps a model name prefix to its OpenAI-compatible provider configuration. DeepSeek,
|
|
196
|
+
* Kimi (Moonshot), and GLM (Zhipu) all expose OpenAI-compatible chat completion APIs
|
|
197
|
+
* and can be routed through `ChatOpenAI` with a custom base URL and API key.
|
|
198
|
+
* @param modelName - The model identifier to inspect
|
|
199
|
+
* @param config - Configuration object containing provider-specific API keys
|
|
200
|
+
* @returns An object with `apiKey` and `baseURL` when the model matches a known
|
|
201
|
+
* OpenAI-compatible provider, or `null` otherwise
|
|
202
|
+
*/
|
|
203
|
+
const getOpenAICompatibleProvider = (modelName, config) => {
|
|
204
|
+
if (modelName.startsWith("deepseek-")) {
|
|
205
|
+
return {
|
|
206
|
+
apiKey: config.deepSeekAPIKey,
|
|
207
|
+
baseURL: "https://api.deepseek.com/v1",
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
if (modelName.startsWith("kimi-") || modelName.startsWith("moonshot-")) {
|
|
211
|
+
return {
|
|
212
|
+
apiKey: config.kimiAPIKey,
|
|
213
|
+
baseURL: "https://api.moonshot.ai/v1",
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
if (modelName.startsWith("glm-")) {
|
|
217
|
+
return {
|
|
218
|
+
apiKey: config.glmAPIKey,
|
|
219
|
+
baseURL: "https://open.bigmodel.cn/api/paas/v4/",
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
};
|
|
194
224
|
/**
|
|
195
225
|
* Instantiates and returns the appropriate LangChain chat model based on the model
|
|
196
226
|
* name prefix. `claude-` maps to `ChatAnthropic`, `gemini-` maps to
|
|
197
|
-
* `ChatGoogleGenerativeAI`, and `gpt-` maps to `ChatOpenAI`.
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
227
|
+
* `ChatGoogleGenerativeAI`, and `gpt-` maps to `ChatOpenAI`. DeepSeek (`deepseek-`),
|
|
228
|
+
* Kimi/Moonshot (`kimi-`, `moonshot-`), and GLM/Zhipu (`glm-`) models are routed
|
|
229
|
+
* through `ChatOpenAI` against each provider's OpenAI-compatible endpoint. When a Zod
|
|
230
|
+
* `schema` is provided for a GPT model, native `response_format` with `json_schema` is
|
|
231
|
+
* configured for structured output. Throws a `BAD_REQUEST` error for unrecognised
|
|
232
|
+
* model names.
|
|
201
233
|
* @param modelName - The model identifier, e.g. `"gpt-4o"`, `"claude-3-5-sonnet"`,
|
|
202
|
-
* `"gemini-1.5-pro"`
|
|
234
|
+
* `"gemini-1.5-pro"`, `"deepseek-chat"`, `"kimi-k2-0905-preview"`, `"glm-4.6"`
|
|
203
235
|
* @param config - Configuration object containing API keys (`openAIAPIKey`,
|
|
204
|
-
* `anthropicAPIKey`, `googleAPIKey`
|
|
236
|
+
* `anthropicAPIKey`, `googleAPIKey`, `deepSeekAPIKey`, `kimiAPIKey`, `glmAPIKey`),
|
|
237
|
+
* optional `maxTokens`, and optional `temperature`
|
|
205
238
|
* @param schema - Optional Zod schema used to configure structured JSON output for
|
|
206
239
|
* OpenAI GPT models via `response_format`; ignored for other providers
|
|
207
240
|
* @returns A configured LangChain chat model instance
|
|
@@ -252,6 +285,17 @@ const getLLMModel = (modelName, config, schema = null) => {
|
|
|
252
285
|
}
|
|
253
286
|
return new openai_1.ChatOpenAI(openAISettings);
|
|
254
287
|
}
|
|
288
|
+
// OpenAI-compatible providers: DeepSeek, Kimi (Moonshot), GLM (Zhipu)
|
|
289
|
+
const openAICompatible = getOpenAICompatibleProvider(modelName, config);
|
|
290
|
+
if (openAICompatible) {
|
|
291
|
+
return new openai_1.ChatOpenAI({
|
|
292
|
+
apiKey: openAICompatible.apiKey,
|
|
293
|
+
maxTokens: config.maxTokens || 200000,
|
|
294
|
+
modelName: modelName,
|
|
295
|
+
configuration: { baseURL: openAICompatible.baseURL },
|
|
296
|
+
...modelSettings,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
255
299
|
throw errorHandling_js_1.default.create(const_js_1.default.HTTP_CODES.BAD_REQUEST, const_js_1.default.ERROR.UNSUPPORTED_MODEL + ": " + modelName);
|
|
256
300
|
};
|
|
257
301
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAmVQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,KACV,GAAG;sBAyBG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAmfF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCAxYO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDA6rBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CA7vB8B,GAAG,KAAG,MAAM;;AAwzBzD,wBAOE"}
|
package/dist/esm/langChain.js
CHANGED
|
@@ -186,17 +186,50 @@ const extractJSONFromResponse = (text) => {
|
|
|
186
186
|
}
|
|
187
187
|
return null;
|
|
188
188
|
};
|
|
189
|
+
/**
|
|
190
|
+
* Maps a model name prefix to its OpenAI-compatible provider configuration. DeepSeek,
|
|
191
|
+
* Kimi (Moonshot), and GLM (Zhipu) all expose OpenAI-compatible chat completion APIs
|
|
192
|
+
* and can be routed through `ChatOpenAI` with a custom base URL and API key.
|
|
193
|
+
* @param modelName - The model identifier to inspect
|
|
194
|
+
* @param config - Configuration object containing provider-specific API keys
|
|
195
|
+
* @returns An object with `apiKey` and `baseURL` when the model matches a known
|
|
196
|
+
* OpenAI-compatible provider, or `null` otherwise
|
|
197
|
+
*/
|
|
198
|
+
const getOpenAICompatibleProvider = (modelName, config) => {
|
|
199
|
+
if (modelName.startsWith("deepseek-")) {
|
|
200
|
+
return {
|
|
201
|
+
apiKey: config.deepSeekAPIKey,
|
|
202
|
+
baseURL: "https://api.deepseek.com/v1",
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
if (modelName.startsWith("kimi-") || modelName.startsWith("moonshot-")) {
|
|
206
|
+
return {
|
|
207
|
+
apiKey: config.kimiAPIKey,
|
|
208
|
+
baseURL: "https://api.moonshot.ai/v1",
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
if (modelName.startsWith("glm-")) {
|
|
212
|
+
return {
|
|
213
|
+
apiKey: config.glmAPIKey,
|
|
214
|
+
baseURL: "https://open.bigmodel.cn/api/paas/v4/",
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
};
|
|
189
219
|
/**
|
|
190
220
|
* Instantiates and returns the appropriate LangChain chat model based on the model
|
|
191
221
|
* name prefix. `claude-` maps to `ChatAnthropic`, `gemini-` maps to
|
|
192
|
-
* `ChatGoogleGenerativeAI`, and `gpt-` maps to `ChatOpenAI`.
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
222
|
+
* `ChatGoogleGenerativeAI`, and `gpt-` maps to `ChatOpenAI`. DeepSeek (`deepseek-`),
|
|
223
|
+
* Kimi/Moonshot (`kimi-`, `moonshot-`), and GLM/Zhipu (`glm-`) models are routed
|
|
224
|
+
* through `ChatOpenAI` against each provider's OpenAI-compatible endpoint. When a Zod
|
|
225
|
+
* `schema` is provided for a GPT model, native `response_format` with `json_schema` is
|
|
226
|
+
* configured for structured output. Throws a `BAD_REQUEST` error for unrecognised
|
|
227
|
+
* model names.
|
|
196
228
|
* @param modelName - The model identifier, e.g. `"gpt-4o"`, `"claude-3-5-sonnet"`,
|
|
197
|
-
* `"gemini-1.5-pro"`
|
|
229
|
+
* `"gemini-1.5-pro"`, `"deepseek-chat"`, `"kimi-k2-0905-preview"`, `"glm-4.6"`
|
|
198
230
|
* @param config - Configuration object containing API keys (`openAIAPIKey`,
|
|
199
|
-
* `anthropicAPIKey`, `googleAPIKey`
|
|
231
|
+
* `anthropicAPIKey`, `googleAPIKey`, `deepSeekAPIKey`, `kimiAPIKey`, `glmAPIKey`),
|
|
232
|
+
* optional `maxTokens`, and optional `temperature`
|
|
200
233
|
* @param schema - Optional Zod schema used to configure structured JSON output for
|
|
201
234
|
* OpenAI GPT models via `response_format`; ignored for other providers
|
|
202
235
|
* @returns A configured LangChain chat model instance
|
|
@@ -247,6 +280,17 @@ const getLLMModel = (modelName, config, schema = null) => {
|
|
|
247
280
|
}
|
|
248
281
|
return new ChatOpenAI(openAISettings);
|
|
249
282
|
}
|
|
283
|
+
// OpenAI-compatible providers: DeepSeek, Kimi (Moonshot), GLM (Zhipu)
|
|
284
|
+
const openAICompatible = getOpenAICompatibleProvider(modelName, config);
|
|
285
|
+
if (openAICompatible) {
|
|
286
|
+
return new ChatOpenAI({
|
|
287
|
+
apiKey: openAICompatible.apiKey,
|
|
288
|
+
maxTokens: config.maxTokens || 200000,
|
|
289
|
+
modelName: modelName,
|
|
290
|
+
configuration: { baseURL: openAICompatible.baseURL },
|
|
291
|
+
...modelSettings,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
250
294
|
throw errorHandlingHelper.create(constants.HTTP_CODES.BAD_REQUEST, constants.ERROR.UNSUPPORTED_MODEL + ": " + modelName);
|
|
251
295
|
};
|
|
252
296
|
/**
|