@lumenchain/langchain-gigachat 0.0.1 → 0.0.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 +11 -3
- package/dist/chat_models.d.ts +2 -2
- package/dist/chat_models.js +11 -3
- package/dist/embeddings.cjs +6 -1
- package/dist/embeddings.d.ts +1 -1
- package/dist/embeddings.js +6 -1
- package/package.json +14 -15
package/dist/chat_models.cjs
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.GigaChat = void 0;
|
|
4
4
|
const messages_1 = require("@langchain/core/messages");
|
|
5
5
|
const chat_models_1 = require("@langchain/core/language_models/chat_models");
|
|
6
|
-
const gigachat_1 = require("gigachat");
|
|
6
|
+
const gigachat_1 = require("@lumenchain/gigachat");
|
|
7
7
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
8
8
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
9
9
|
const runnables_1 = require("@langchain/core/runnables");
|
|
@@ -371,6 +371,11 @@ class GigaChat extends chat_models_1.BaseChatModel {
|
|
|
371
371
|
verbose: fields?.verbose,
|
|
372
372
|
flags: fields?.flags,
|
|
373
373
|
httpsAgent: fields?.httpsAgent,
|
|
374
|
+
requestId: fields?.requestId,
|
|
375
|
+
clientId: fields?.clientId,
|
|
376
|
+
customHeaders: fields?.customHeaders,
|
|
377
|
+
sessionId: fields?.sessionId,
|
|
378
|
+
dangerouslyAllowBrowser: fields?.dangerouslyAllowBrowser
|
|
374
379
|
};
|
|
375
380
|
this.clientConfig = removeEmpty(this.clientConfig);
|
|
376
381
|
this._client = new gigachat_1.GigaChat(this.clientConfig);
|
|
@@ -379,7 +384,7 @@ class GigaChat extends chat_models_1.BaseChatModel {
|
|
|
379
384
|
return "giga-chat-model";
|
|
380
385
|
}
|
|
381
386
|
bindTools(tools, kwargs) {
|
|
382
|
-
return this.
|
|
387
|
+
return this.withConfig({
|
|
383
388
|
tools: this.formatStructuredToolToGigaChat(tools),
|
|
384
389
|
...kwargs,
|
|
385
390
|
});
|
|
@@ -402,7 +407,7 @@ class GigaChat extends chat_models_1.BaseChatModel {
|
|
|
402
407
|
return {
|
|
403
408
|
name: tool.name,
|
|
404
409
|
description: tool.description,
|
|
405
|
-
parameters: (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema),
|
|
410
|
+
parameters: (0, types_1.isZodSchema)(tool.schema) ? (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema) : tool.schema,
|
|
406
411
|
};
|
|
407
412
|
}
|
|
408
413
|
throw new Error(`Unknown tool type passed to GigaChat: ${JSON.stringify(tool, null, 2)}`);
|
|
@@ -413,6 +418,8 @@ class GigaChat extends chat_models_1.BaseChatModel {
|
|
|
413
418
|
if (llmOutput && llmOutput.usage) {
|
|
414
419
|
acc.usage.completion_tokens += llmOutput.usage.completion_tokens ?? 0;
|
|
415
420
|
acc.usage.prompt_tokens += llmOutput.usage.prompt_tokens ?? 0;
|
|
421
|
+
acc.usage.precached_prompt_tokens +=
|
|
422
|
+
llmOutput.usage.precached_prompt_tokens ?? 0;
|
|
416
423
|
acc.usage.total_tokens += llmOutput.usage.total_tokens ?? 0;
|
|
417
424
|
}
|
|
418
425
|
return acc;
|
|
@@ -420,6 +427,7 @@ class GigaChat extends chat_models_1.BaseChatModel {
|
|
|
420
427
|
usage: {
|
|
421
428
|
completion_tokens: 0,
|
|
422
429
|
prompt_tokens: 0,
|
|
430
|
+
precached_prompt_tokens: 0,
|
|
423
431
|
total_tokens: 0,
|
|
424
432
|
},
|
|
425
433
|
});
|
package/dist/chat_models.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AIMessageChunk, type BaseMessage } from "@langchain/core/messages";
|
|
2
2
|
import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
|
|
3
3
|
import { BaseChatModel, BaseChatModelCallOptions, type BaseChatModelParams, BindToolsInput, LangSmithParams } from "@langchain/core/language_models/chat_models";
|
|
4
|
-
import { FunctionCall, Function as _Function, Message, Chat, ChatFunctionCall, Usage, ChatCompletion, ChatCompletionChunk, WithXHeaders } from "gigachat/interfaces";
|
|
5
|
-
import { GigaChat as GigaChatClient, GigaChatClientConfig } from "gigachat";
|
|
4
|
+
import { FunctionCall, Function as _Function, Message, Chat, ChatFunctionCall, Usage, ChatCompletion, ChatCompletionChunk, WithXHeaders } from "@lumenchain/gigachat/interfaces";
|
|
5
|
+
import { GigaChat as GigaChatClient, GigaChatClientConfig } from "@lumenchain/gigachat";
|
|
6
6
|
import { Runnable } from "@langchain/core/runnables";
|
|
7
7
|
import { BaseLanguageModelInput, StructuredOutputMethodOptions } from "@langchain/core/language_models/base";
|
|
8
8
|
import { ChatGenerationChunk, ChatResult } from "@langchain/core/outputs";
|
package/dist/chat_models.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AIMessage, AIMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessageChunk, HumanMessageChunk, isAIMessage, SystemMessageChunk, } from "@langchain/core/messages";
|
|
2
2
|
import { BaseChatModel, } from "@langchain/core/language_models/chat_models";
|
|
3
|
-
import { GigaChat as GigaChatClient } from "gigachat";
|
|
3
|
+
import { GigaChat as GigaChatClient, } from "@lumenchain/gigachat";
|
|
4
4
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
5
5
|
import { isLangChainTool } from "@langchain/core/utils/function_calling";
|
|
6
6
|
import { RunnablePassthrough, RunnableSequence, } from "@langchain/core/runnables";
|
|
@@ -368,6 +368,11 @@ export class GigaChat extends BaseChatModel {
|
|
|
368
368
|
verbose: fields?.verbose,
|
|
369
369
|
flags: fields?.flags,
|
|
370
370
|
httpsAgent: fields?.httpsAgent,
|
|
371
|
+
requestId: fields?.requestId,
|
|
372
|
+
clientId: fields?.clientId,
|
|
373
|
+
customHeaders: fields?.customHeaders,
|
|
374
|
+
sessionId: fields?.sessionId,
|
|
375
|
+
dangerouslyAllowBrowser: fields?.dangerouslyAllowBrowser
|
|
371
376
|
};
|
|
372
377
|
this.clientConfig = removeEmpty(this.clientConfig);
|
|
373
378
|
this._client = new GigaChatClient(this.clientConfig);
|
|
@@ -376,7 +381,7 @@ export class GigaChat extends BaseChatModel {
|
|
|
376
381
|
return "giga-chat-model";
|
|
377
382
|
}
|
|
378
383
|
bindTools(tools, kwargs) {
|
|
379
|
-
return this.
|
|
384
|
+
return this.withConfig({
|
|
380
385
|
tools: this.formatStructuredToolToGigaChat(tools),
|
|
381
386
|
...kwargs,
|
|
382
387
|
});
|
|
@@ -399,7 +404,7 @@ export class GigaChat extends BaseChatModel {
|
|
|
399
404
|
return {
|
|
400
405
|
name: tool.name,
|
|
401
406
|
description: tool.description,
|
|
402
|
-
parameters: zodToJsonSchema(tool.schema),
|
|
407
|
+
parameters: isZodSchema(tool.schema) ? zodToJsonSchema(tool.schema) : tool.schema,
|
|
403
408
|
};
|
|
404
409
|
}
|
|
405
410
|
throw new Error(`Unknown tool type passed to GigaChat: ${JSON.stringify(tool, null, 2)}`);
|
|
@@ -410,6 +415,8 @@ export class GigaChat extends BaseChatModel {
|
|
|
410
415
|
if (llmOutput && llmOutput.usage) {
|
|
411
416
|
acc.usage.completion_tokens += llmOutput.usage.completion_tokens ?? 0;
|
|
412
417
|
acc.usage.prompt_tokens += llmOutput.usage.prompt_tokens ?? 0;
|
|
418
|
+
acc.usage.precached_prompt_tokens +=
|
|
419
|
+
llmOutput.usage.precached_prompt_tokens ?? 0;
|
|
413
420
|
acc.usage.total_tokens += llmOutput.usage.total_tokens ?? 0;
|
|
414
421
|
}
|
|
415
422
|
return acc;
|
|
@@ -417,6 +424,7 @@ export class GigaChat extends BaseChatModel {
|
|
|
417
424
|
usage: {
|
|
418
425
|
completion_tokens: 0,
|
|
419
426
|
prompt_tokens: 0,
|
|
427
|
+
precached_prompt_tokens: 0,
|
|
420
428
|
total_tokens: 0,
|
|
421
429
|
},
|
|
422
430
|
});
|
package/dist/embeddings.cjs
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.GigaChatEmbeddings = void 0;
|
|
4
4
|
const embeddings_1 = require("@langchain/core/embeddings");
|
|
5
5
|
const chunk_array_1 = require("@langchain/core/utils/chunk_array");
|
|
6
|
-
const gigachat_1 = require("gigachat");
|
|
6
|
+
const gigachat_1 = require("@lumenchain/gigachat");
|
|
7
7
|
function removeEmpty(obj) {
|
|
8
8
|
const newObj = {};
|
|
9
9
|
for (const key in obj) {
|
|
@@ -89,6 +89,11 @@ class GigaChatEmbeddings extends embeddings_1.Embeddings {
|
|
|
89
89
|
verbose: fields?.verbose,
|
|
90
90
|
flags: fields?.flags,
|
|
91
91
|
httpsAgent: fields?.httpsAgent,
|
|
92
|
+
requestId: fields?.requestId,
|
|
93
|
+
clientId: fields?.clientId,
|
|
94
|
+
customHeaders: fields?.customHeaders,
|
|
95
|
+
sessionId: fields?.sessionId,
|
|
96
|
+
dangerouslyAllowBrowser: fields?.dangerouslyAllowBrowser
|
|
92
97
|
};
|
|
93
98
|
this.clientConfig = removeEmpty(this.clientConfig);
|
|
94
99
|
this._client = new gigachat_1.GigaChat(this.clientConfig);
|
package/dist/embeddings.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Embeddings, type EmbeddingsParams } from "@langchain/core/embeddings";
|
|
2
|
-
import { GigaChat, GigaChatClientConfig } from "gigachat";
|
|
2
|
+
import { GigaChat, GigaChatClientConfig } from "@lumenchain/gigachat";
|
|
3
3
|
/**
|
|
4
4
|
* Interface for GigachatEmbeddings parameters. Extends EmbeddingsParams and
|
|
5
5
|
* defines additional parameters specific to the GigaChat embeddings class.
|
package/dist/embeddings.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Embeddings } from "@langchain/core/embeddings";
|
|
2
2
|
import { chunkArray } from "@langchain/core/utils/chunk_array";
|
|
3
|
-
import { GigaChat } from "gigachat";
|
|
3
|
+
import { GigaChat } from "@lumenchain/gigachat";
|
|
4
4
|
function removeEmpty(obj) {
|
|
5
5
|
const newObj = {};
|
|
6
6
|
for (const key in obj) {
|
|
@@ -86,6 +86,11 @@ export class GigaChatEmbeddings extends Embeddings {
|
|
|
86
86
|
verbose: fields?.verbose,
|
|
87
87
|
flags: fields?.flags,
|
|
88
88
|
httpsAgent: fields?.httpsAgent,
|
|
89
|
+
requestId: fields?.requestId,
|
|
90
|
+
clientId: fields?.clientId,
|
|
91
|
+
customHeaders: fields?.customHeaders,
|
|
92
|
+
sessionId: fields?.sessionId,
|
|
93
|
+
dangerouslyAllowBrowser: fields?.dangerouslyAllowBrowser
|
|
89
94
|
};
|
|
90
95
|
this.clientConfig = removeEmpty(this.clientConfig);
|
|
91
96
|
this._client = new GigaChat(this.clientConfig);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumenchain/langchain-gigachat",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "GigaChat integration for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"types": "./index.d.ts",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/micasa-acerman/langchainjs"
|
|
14
14
|
},
|
|
15
15
|
"packageManager": "yarn@3.4.1",
|
|
16
|
-
"homepage": "https://github.com/
|
|
16
|
+
"homepage": "https://github.com/micasa-acerman/langchainjs/tree/main/libs/langchain-gigachat",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "yarn turbo:command build:internal --filter=langchain-gigachat",
|
|
19
19
|
"build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking",
|
|
@@ -28,9 +28,16 @@
|
|
|
28
28
|
"test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
|
|
29
29
|
"test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
|
|
30
30
|
"format": "prettier --config .prettierrc --write \"src\"",
|
|
31
|
-
"format:check": "prettier --config .prettierrc --check \"src\""
|
|
31
|
+
"format:check": "prettier --config .prettierrc --check \"src\"",
|
|
32
|
+
"release:whoami": "npm whoami --registry=https://registry.npmjs.org/",
|
|
33
|
+
"release:version:patch": "npm version patch --no-git-tag-version",
|
|
34
|
+
"release:version:minor": "npm version minor --no-git-tag-version",
|
|
35
|
+
"release:version:major": "npm version major --no-git-tag-version",
|
|
36
|
+
"release:pack": "npm pack --dry-run --ignore-scripts",
|
|
37
|
+
"release:publish": "npm publish --access public --ignore-scripts --registry=https://registry.npmjs.org/",
|
|
38
|
+
"release:verify": "npm view @lumenchain/langchain-gigachat version --registry=https://registry.npmjs.org/"
|
|
32
39
|
},
|
|
33
|
-
"author": "Mikelarg",
|
|
40
|
+
"author": "Mikelarg, Mrikaev K.",
|
|
34
41
|
"license": "MIT",
|
|
35
42
|
"keywords": [
|
|
36
43
|
"llm",
|
|
@@ -46,7 +53,7 @@
|
|
|
46
53
|
"vectorstores"
|
|
47
54
|
],
|
|
48
55
|
"dependencies": {
|
|
49
|
-
"gigachat": "^0.0.
|
|
56
|
+
"@lumenchain/gigachat": "^0.0.1",
|
|
50
57
|
"uuid": "^11.0.5",
|
|
51
58
|
"zod": "^3.23.8",
|
|
52
59
|
"zod-to-json-schema": "^3.23.5"
|
|
@@ -114,15 +121,7 @@
|
|
|
114
121
|
"./package.json": "./package.json"
|
|
115
122
|
},
|
|
116
123
|
"files": [
|
|
117
|
-
"dist/
|
|
118
|
-
"dist/chat_models.d.ts",
|
|
119
|
-
"dist/chat_models.js",
|
|
120
|
-
"dist/embeddings.cjs",
|
|
121
|
-
"dist/embeddings.d.ts",
|
|
122
|
-
"dist/embeddings.js",
|
|
123
|
-
"dist/index.cjs",
|
|
124
|
-
"dist/index.d.ts",
|
|
125
|
-
"dist/index.js",
|
|
124
|
+
"dist/",
|
|
126
125
|
"chat_models.cjs",
|
|
127
126
|
"chat_models.js",
|
|
128
127
|
"chat_models.d.ts",
|