@blaxel/langgraph 0.2.49 → 0.2.50-preview.115
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/README.md +1 -1
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/model/cohere.js +185 -3
- package/dist/cjs/model/google-genai.js +75 -12
- package/dist/cjs/model.js +27 -1
- package/dist/cjs/telemetry.js +2 -3
- package/dist/cjs/types/model/google-genai.d.ts +20 -3
- package/dist/cjs/types/model/xai.d.ts +2 -1
- package/dist/cjs/types/tools.d.ts +6 -2
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/model/cohere.js +185 -3
- package/dist/esm/model/google-genai.js +74 -11
- package/dist/esm/model.js +27 -1
- package/dist/esm/telemetry.js +2 -3
- package/package.json +11 -10
- package/dist/cjs/model/google-genai/chat_models.js +0 -760
- package/dist/cjs/model/google-genai/embeddings.js +0 -111
- package/dist/cjs/model/google-genai/index.js +0 -18
- package/dist/cjs/model/google-genai/output_parsers.js +0 -51
- package/dist/cjs/model/google-genai/types.js +0 -2
- package/dist/cjs/model/google-genai/utils/common.js +0 -387
- package/dist/cjs/model/google-genai/utils/tools.js +0 -110
- package/dist/cjs/model/google-genai/utils/zod_to_genai_parameters.js +0 -46
- package/dist/cjs/types/model/google-genai/chat_models.d.ts +0 -557
- package/dist/cjs/types/model/google-genai/embeddings.d.ts +0 -94
- package/dist/cjs/types/model/google-genai/index.d.ts +0 -2
- package/dist/cjs/types/model/google-genai/output_parsers.d.ts +0 -20
- package/dist/cjs/types/model/google-genai/types.d.ts +0 -3
- package/dist/cjs/types/model/google-genai/utils/common.d.ts +0 -22
- package/dist/cjs/types/model/google-genai/utils/tools.d.ts +0 -10
- package/dist/cjs/types/model/google-genai/utils/zod_to_genai_parameters.d.ts +0 -13
- package/dist/esm/model/google-genai/chat_models.js +0 -756
- package/dist/esm/model/google-genai/embeddings.js +0 -107
- package/dist/esm/model/google-genai/index.js +0 -2
- package/dist/esm/model/google-genai/output_parsers.js +0 -47
- package/dist/esm/model/google-genai/types.js +0 -1
- package/dist/esm/model/google-genai/utils/common.js +0 -378
- package/dist/esm/model/google-genai/utils/tools.js +0 -107
- package/dist/esm/model/google-genai/utils/zod_to_genai_parameters.js +0 -41
package/dist/cjs/model/cohere.js
CHANGED
|
@@ -14,7 +14,9 @@ const createCohereFetcher = () => {
|
|
|
14
14
|
// Extract all fields from args
|
|
15
15
|
const { url, method, headers: argsHeaders, body, contentType, queryParameters, timeoutMs, withCredentials, abortSignal, requestType, responseType, duplex } = args;
|
|
16
16
|
// Build URL with query parameters
|
|
17
|
-
|
|
17
|
+
// Rewrite /v1/chat to /v2/chat for Cohere API v2 compatibility
|
|
18
|
+
let requestUrl = url.replace('/v1/chat', '/v2/chat');
|
|
19
|
+
const isV2Endpoint = requestUrl.includes('/v2/chat');
|
|
18
20
|
if (queryParameters) {
|
|
19
21
|
const params = new URLSearchParams();
|
|
20
22
|
Object.entries(queryParameters).forEach(([key, value]) => {
|
|
@@ -60,7 +62,77 @@ const createCohereFetcher = () => {
|
|
|
60
62
|
let requestBody;
|
|
61
63
|
if (body !== undefined) {
|
|
62
64
|
if (requestType === 'json' || !requestType) {
|
|
63
|
-
|
|
65
|
+
// Transform body for Cohere v2 API compatibility (only if using v2 endpoint)
|
|
66
|
+
let transformedBody = body;
|
|
67
|
+
if (isV2Endpoint && typeof body === 'object' && body !== null && !Array.isArray(body)) {
|
|
68
|
+
const bodyObj = body;
|
|
69
|
+
transformedBody = { ...bodyObj };
|
|
70
|
+
const transformedObj = transformedBody;
|
|
71
|
+
// Remove v1-only fields that are not supported in v2
|
|
72
|
+
const fieldsToRemove = ['chat_history'];
|
|
73
|
+
for (const field of fieldsToRemove) {
|
|
74
|
+
if (field in transformedObj) {
|
|
75
|
+
delete transformedObj[field];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Convert 'message' to 'messages' format if message exists and messages doesn't
|
|
79
|
+
if ('message' in transformedObj && !('messages' in transformedObj)) {
|
|
80
|
+
const message = transformedObj.message;
|
|
81
|
+
if (typeof message === 'string' && message.trim().length > 0) {
|
|
82
|
+
// Convert single message string to messages array format
|
|
83
|
+
transformedObj.messages = [
|
|
84
|
+
{
|
|
85
|
+
role: 'user',
|
|
86
|
+
content: message,
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
// Remove the old message field
|
|
91
|
+
delete transformedObj.message;
|
|
92
|
+
}
|
|
93
|
+
// Handle tool_results - v2 might use a different format, remove for now
|
|
94
|
+
if ('tool_results' in transformedObj) {
|
|
95
|
+
delete transformedObj.tool_results;
|
|
96
|
+
}
|
|
97
|
+
// Transform tools array to ensure each tool has a 'type' field (required by Cohere v2)
|
|
98
|
+
if ('tools' in transformedObj && Array.isArray(transformedObj.tools)) {
|
|
99
|
+
const tools = transformedObj.tools;
|
|
100
|
+
transformedObj.tools = tools.map((tool) => {
|
|
101
|
+
if (typeof tool === 'object' && tool !== null) {
|
|
102
|
+
const toolObj = tool;
|
|
103
|
+
// If tool already has 'type' field, keep it
|
|
104
|
+
if ('type' in toolObj) {
|
|
105
|
+
return toolObj;
|
|
106
|
+
}
|
|
107
|
+
// If tool has 'function' field (OpenAI format), wrap it with type
|
|
108
|
+
if ('function' in toolObj) {
|
|
109
|
+
return {
|
|
110
|
+
type: 'function',
|
|
111
|
+
function: toolObj.function,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
// If tool has name/description/parameters (direct format), wrap it
|
|
115
|
+
if ('name' in toolObj && ('description' in toolObj || 'parameters' in toolObj)) {
|
|
116
|
+
return {
|
|
117
|
+
type: 'function',
|
|
118
|
+
function: {
|
|
119
|
+
name: toolObj.name,
|
|
120
|
+
description: toolObj.description || '',
|
|
121
|
+
parameters: toolObj.parameters || toolObj.inputSchema || {},
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// Default: add type field
|
|
126
|
+
return {
|
|
127
|
+
type: 'function',
|
|
128
|
+
...toolObj,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return tool;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
requestBody = JSON.stringify(transformedBody);
|
|
64
136
|
}
|
|
65
137
|
else if (requestType === 'bytes' && body instanceof Uint8Array) {
|
|
66
138
|
// Create a new ArrayBuffer from the Uint8Array to avoid SharedArrayBuffer issues
|
|
@@ -73,7 +145,82 @@ const createCohereFetcher = () => {
|
|
|
73
145
|
requestBody = body;
|
|
74
146
|
}
|
|
75
147
|
else if (typeof body === 'string') {
|
|
76
|
-
|
|
148
|
+
// Parse and transform JSON strings (only if using v2 endpoint)
|
|
149
|
+
if (isV2Endpoint) {
|
|
150
|
+
try {
|
|
151
|
+
const parsed = JSON.parse(body);
|
|
152
|
+
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
|
153
|
+
const transformed = { ...parsed };
|
|
154
|
+
// Remove v1-only fields
|
|
155
|
+
if ('chat_history' in transformed) {
|
|
156
|
+
delete transformed.chat_history;
|
|
157
|
+
}
|
|
158
|
+
if ('tool_results' in transformed) {
|
|
159
|
+
delete transformed.tool_results;
|
|
160
|
+
}
|
|
161
|
+
// Convert 'message' to 'messages' format if message exists and messages doesn't
|
|
162
|
+
if ('message' in transformed && !('messages' in transformed)) {
|
|
163
|
+
const message = transformed.message;
|
|
164
|
+
if (typeof message === 'string' && message.trim().length > 0) {
|
|
165
|
+
transformed.messages = [
|
|
166
|
+
{
|
|
167
|
+
role: 'user',
|
|
168
|
+
content: message,
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
delete transformed.message;
|
|
173
|
+
}
|
|
174
|
+
// Transform tools array to ensure each tool has a 'type' field (required by Cohere v2)
|
|
175
|
+
if ('tools' in transformed && Array.isArray(transformed.tools)) {
|
|
176
|
+
const tools = transformed.tools;
|
|
177
|
+
transformed.tools = tools.map((tool) => {
|
|
178
|
+
if (typeof tool === 'object' && tool !== null) {
|
|
179
|
+
const toolObj = tool;
|
|
180
|
+
// If tool already has 'type' field, keep it
|
|
181
|
+
if ('type' in toolObj) {
|
|
182
|
+
return toolObj;
|
|
183
|
+
}
|
|
184
|
+
// If tool has 'function' field (OpenAI format), wrap it with type
|
|
185
|
+
if ('function' in toolObj) {
|
|
186
|
+
return {
|
|
187
|
+
type: 'function',
|
|
188
|
+
function: toolObj.function,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
// If tool has name/description/parameters (direct format), wrap it
|
|
192
|
+
if ('name' in toolObj && ('description' in toolObj || 'parameters' in toolObj)) {
|
|
193
|
+
return {
|
|
194
|
+
type: 'function',
|
|
195
|
+
function: {
|
|
196
|
+
name: toolObj.name,
|
|
197
|
+
description: toolObj.description || '',
|
|
198
|
+
parameters: toolObj.parameters || toolObj.inputSchema || {},
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
// Default: add type field
|
|
203
|
+
return {
|
|
204
|
+
type: 'function',
|
|
205
|
+
...toolObj,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return tool;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
requestBody = JSON.stringify(transformed);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
requestBody = body;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
requestBody = body;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
requestBody = body;
|
|
223
|
+
}
|
|
77
224
|
}
|
|
78
225
|
else {
|
|
79
226
|
requestBody = JSON.stringify(body);
|
|
@@ -126,6 +273,41 @@ const createCohereFetcher = () => {
|
|
|
126
273
|
else {
|
|
127
274
|
// Default to JSON
|
|
128
275
|
responseBody = await response.json();
|
|
276
|
+
// Transform v2 response format to v1 format for ChatCohere compatibility
|
|
277
|
+
if (isV2Endpoint && typeof responseBody === 'object' && responseBody !== null) {
|
|
278
|
+
const responseObj = responseBody;
|
|
279
|
+
if ('message' in responseObj && typeof responseObj.message === 'object' && responseObj.message !== null) {
|
|
280
|
+
const v2Message = responseObj.message;
|
|
281
|
+
// Extract text from content array
|
|
282
|
+
let text = '';
|
|
283
|
+
if (Array.isArray(v2Message.content)) {
|
|
284
|
+
const contentArray = v2Message.content;
|
|
285
|
+
// Find the text content block
|
|
286
|
+
const textBlock = contentArray.find((item) => item.type === 'text' && item.text);
|
|
287
|
+
if (textBlock && textBlock.text) {
|
|
288
|
+
text = textBlock.text;
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
// Fallback: join all text-like content
|
|
292
|
+
text = contentArray
|
|
293
|
+
.map((item) => item.text || item.thinking || '')
|
|
294
|
+
.filter(Boolean)
|
|
295
|
+
.join('\n');
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
else if (typeof v2Message.content === 'string') {
|
|
299
|
+
text = v2Message.content;
|
|
300
|
+
}
|
|
301
|
+
// Transform to v1-like format that ChatCohere expects
|
|
302
|
+
const transformedResponse = {
|
|
303
|
+
...responseObj,
|
|
304
|
+
text: text,
|
|
305
|
+
// Keep the original message structure in case ChatCohere needs it
|
|
306
|
+
message: responseObj.message,
|
|
307
|
+
};
|
|
308
|
+
responseBody = transformedResponse;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
129
311
|
}
|
|
130
312
|
// Return success response in the format CohereClient expects
|
|
131
313
|
return {
|
|
@@ -2,29 +2,92 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AuthenticatedChatGoogleGenerativeAI = void 0;
|
|
4
4
|
const core_1 = require("@blaxel/core");
|
|
5
|
-
const
|
|
5
|
+
const google_genai_1 = require("@langchain/google-genai");
|
|
6
|
+
const generative_ai_1 = require("@google/generative-ai");
|
|
6
7
|
/**
|
|
7
8
|
* Custom ChatGoogleGenerativeAI that ensures authentication before each request
|
|
9
|
+
* and supports custom headers without modifying the library code
|
|
8
10
|
*/
|
|
9
|
-
class AuthenticatedChatGoogleGenerativeAI extends
|
|
11
|
+
class AuthenticatedChatGoogleGenerativeAI extends google_genai_1.ChatGoogleGenerativeAI {
|
|
12
|
+
customHeaders;
|
|
13
|
+
constructorParams;
|
|
14
|
+
constructor(fields) {
|
|
15
|
+
super(fields);
|
|
16
|
+
// Store constructor parameters for recreating the client
|
|
17
|
+
this.constructorParams = {
|
|
18
|
+
apiKey: fields.apiKey,
|
|
19
|
+
apiVersion: fields.apiVersion,
|
|
20
|
+
baseUrl: fields.baseUrl,
|
|
21
|
+
model: fields.model,
|
|
22
|
+
safetySettings: fields.safetySettings,
|
|
23
|
+
stopSequences: fields.stopSequences,
|
|
24
|
+
maxOutputTokens: fields.maxOutputTokens,
|
|
25
|
+
temperature: fields.temperature,
|
|
26
|
+
topP: fields.topP,
|
|
27
|
+
topK: fields.topK,
|
|
28
|
+
json: fields.json,
|
|
29
|
+
thinkingConfig: fields.thinkingConfig,
|
|
30
|
+
};
|
|
31
|
+
this.customHeaders = fields.customHeaders;
|
|
32
|
+
// Initialize client with custom headers if provided
|
|
33
|
+
if (this.customHeaders) {
|
|
34
|
+
this.recreateClient();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Recreates the client with updated custom headers
|
|
39
|
+
* Uses type assertion to access the private client property
|
|
40
|
+
*/
|
|
41
|
+
recreateClient() {
|
|
42
|
+
const apiKey = this.constructorParams.apiKey || this.apiKey;
|
|
43
|
+
if (!apiKey)
|
|
44
|
+
return;
|
|
45
|
+
// Get the processed model name from the base class (it removes "models/" prefix)
|
|
46
|
+
const model = this.model || this.constructorParams.model.replace(/^models\//, "");
|
|
47
|
+
const modelParams = {
|
|
48
|
+
model,
|
|
49
|
+
safetySettings: this.constructorParams.safetySettings,
|
|
50
|
+
generationConfig: {
|
|
51
|
+
candidateCount: 1,
|
|
52
|
+
stopSequences: this.constructorParams.stopSequences,
|
|
53
|
+
maxOutputTokens: this.constructorParams.maxOutputTokens,
|
|
54
|
+
temperature: this.constructorParams.temperature,
|
|
55
|
+
topP: this.constructorParams.topP,
|
|
56
|
+
topK: this.constructorParams.topK,
|
|
57
|
+
...(this.constructorParams.json ? { responseMimeType: "application/json" } : {}),
|
|
58
|
+
...(this.constructorParams.thinkingConfig
|
|
59
|
+
? { thinkingConfig: this.constructorParams.thinkingConfig }
|
|
60
|
+
: {}),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
const requestOptions = {
|
|
64
|
+
apiVersion: this.constructorParams.apiVersion,
|
|
65
|
+
baseUrl: this.constructorParams.baseUrl,
|
|
66
|
+
customHeaders: this.customHeaders,
|
|
67
|
+
};
|
|
68
|
+
// Use type assertion to access private client property
|
|
69
|
+
this.client = new generative_ai_1.GoogleGenerativeAI(apiKey).getGenerativeModel(modelParams, requestOptions);
|
|
70
|
+
}
|
|
10
71
|
async _generate(messages, options, runManager) {
|
|
11
72
|
// Authenticate before making the request
|
|
12
73
|
await (0, core_1.authenticate)();
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.client = this.initClient();
|
|
74
|
+
// Update custom headers from settings
|
|
75
|
+
this.customHeaders = { ...core_1.settings.headers };
|
|
76
|
+
// Recreate client with updated headers
|
|
77
|
+
this.recreateClient();
|
|
18
78
|
return await super._generate(messages, options || {}, runManager);
|
|
19
79
|
}
|
|
20
80
|
async *_streamResponseChunks(messages, options, runManager) {
|
|
21
81
|
// Authenticate before making the request
|
|
22
82
|
await (0, core_1.authenticate)();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
yield* super._streamResponseChunks(messages, options
|
|
83
|
+
// Update custom headers from settings
|
|
84
|
+
this.customHeaders = { ...core_1.settings.headers };
|
|
85
|
+
// Recreate client with updated headers
|
|
86
|
+
this.recreateClient();
|
|
87
|
+
yield* super._streamResponseChunks(messages, options, runManager);
|
|
88
|
+
}
|
|
89
|
+
bindTools(tools, kwargs) {
|
|
90
|
+
return super.bindTools(tools, kwargs);
|
|
28
91
|
}
|
|
29
92
|
}
|
|
30
93
|
exports.AuthenticatedChatGoogleGenerativeAI = AuthenticatedChatGoogleGenerativeAI;
|
package/dist/cjs/model.js
CHANGED
|
@@ -6,9 +6,9 @@ const anthropic_1 = require("@langchain/anthropic");
|
|
|
6
6
|
const cohere_1 = require("@langchain/cohere");
|
|
7
7
|
const deepseek_1 = require("@langchain/deepseek");
|
|
8
8
|
const openai_1 = require("@langchain/openai");
|
|
9
|
+
const google_genai_js_1 = require("./model/google-genai.js");
|
|
9
10
|
const cohere_ai_1 = require("cohere-ai");
|
|
10
11
|
const cohere_js_1 = require("./model/cohere.js");
|
|
11
|
-
const google_genai_js_1 = require("./model/google-genai.js");
|
|
12
12
|
const xai_js_1 = require("./model/xai.js");
|
|
13
13
|
/**
|
|
14
14
|
* Creates a custom fetch function that adds dynamic headers to each request
|
|
@@ -23,6 +23,24 @@ const authenticatedFetch = () => {
|
|
|
23
23
|
...dynamicHeaders,
|
|
24
24
|
...(init?.headers || {}),
|
|
25
25
|
};
|
|
26
|
+
// Ensure Content-Type is set for JSON requests if body exists and Content-Type is not already set
|
|
27
|
+
if (init?.body && !headers['Content-Type'] && !headers['content-type']) {
|
|
28
|
+
// If body is an object, it will be serialized to JSON by fetch
|
|
29
|
+
// If body is a string, check if it looks like JSON
|
|
30
|
+
if (typeof init.body === 'string') {
|
|
31
|
+
const trimmed = init.body.trim();
|
|
32
|
+
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
33
|
+
headers['Content-Type'] = 'application/json';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// For non-string bodies (FormData, Blob, etc.), let fetch handle it
|
|
38
|
+
// For objects, assume JSON
|
|
39
|
+
if (typeof init.body === 'object' && !(init.body instanceof FormData) && !(init.body instanceof Blob)) {
|
|
40
|
+
headers['Content-Type'] = 'application/json';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
26
44
|
// Make the request with merged headers
|
|
27
45
|
return await fetch(input, {
|
|
28
46
|
...init,
|
|
@@ -63,6 +81,11 @@ const blModel = async (model, options) => {
|
|
|
63
81
|
});
|
|
64
82
|
}
|
|
65
83
|
else if (type === "cohere") {
|
|
84
|
+
// ChatCohere requires a custom client with fetcher for:
|
|
85
|
+
// 1. Dynamic authentication headers (settings.headers)
|
|
86
|
+
// 2. Custom environment URL (url)
|
|
87
|
+
// 3. URL rewriting (v1 -> v2) and body transformation for v2 compatibility
|
|
88
|
+
// @ts-ignore Error in langgraph
|
|
66
89
|
return new cohere_1.ChatCohere({
|
|
67
90
|
apiKey: "replaced",
|
|
68
91
|
model: modelData?.spec?.runtime?.model,
|
|
@@ -75,6 +98,7 @@ const blModel = async (model, options) => {
|
|
|
75
98
|
});
|
|
76
99
|
}
|
|
77
100
|
else if (type === "deepseek") {
|
|
101
|
+
// @ts-ignore Error in langgraph
|
|
78
102
|
return new deepseek_1.ChatDeepSeek({
|
|
79
103
|
apiKey: "replaced",
|
|
80
104
|
model: modelData?.spec?.runtime?.model,
|
|
@@ -87,9 +111,11 @@ const blModel = async (model, options) => {
|
|
|
87
111
|
});
|
|
88
112
|
}
|
|
89
113
|
else if (type === "anthropic") {
|
|
114
|
+
// @ts-ignore Error in langgraph
|
|
90
115
|
return new anthropic_1.ChatAnthropic({
|
|
91
116
|
anthropicApiUrl: url,
|
|
92
117
|
model: modelData?.spec?.runtime?.model,
|
|
118
|
+
apiKey: "replaced",
|
|
93
119
|
clientOptions: {
|
|
94
120
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
95
121
|
fetch: authenticatedFetch(),
|
package/dist/cjs/telemetry.js
CHANGED
|
@@ -35,16 +35,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
const RunnableModule = __importStar(require("@langchain/core/runnables"));
|
|
37
37
|
const ToolsModule = __importStar(require("@langchain/core/tools"));
|
|
38
|
+
const AgentsModule = __importStar(require("@langchain/core/agents"));
|
|
38
39
|
const VectorStoresModule = __importStar(require("@langchain/core/vectorstores"));
|
|
39
40
|
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
40
41
|
const instrumentation_langchain_1 = require("@traceloop/instrumentation-langchain");
|
|
41
|
-
const AgentsModule = __importStar(require("langchain/agents"));
|
|
42
|
-
const ChainsModule = __importStar(require("langchain/chains"));
|
|
43
42
|
const langchain = new instrumentation_langchain_1.LangChainInstrumentation();
|
|
44
43
|
langchain.manuallyInstrument({
|
|
44
|
+
// @ts-ignore - Type definitions may be incorrect, but the method accepts these parameters at runtime
|
|
45
45
|
runnablesModule: RunnableModule,
|
|
46
46
|
toolsModule: ToolsModule,
|
|
47
|
-
chainsModule: ChainsModule,
|
|
48
47
|
agentsModule: AgentsModule,
|
|
49
48
|
vectorStoreModule: VectorStoresModule,
|
|
50
49
|
});
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
|
|
2
|
+
import { BaseLanguageModelInput } from "@langchain/core/language_models/base";
|
|
2
3
|
import { BaseMessage } from "@langchain/core/messages";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
4
|
+
import { AIMessageChunk } from "@langchain/core/messages";
|
|
5
|
+
import { ChatResult, ChatGenerationChunk } from "@langchain/core/outputs";
|
|
6
|
+
import { Runnable } from "@langchain/core/runnables";
|
|
7
|
+
import { ChatGoogleGenerativeAI, GoogleGenerativeAIChatCallOptions, GoogleGenerativeAIChatInput } from "@langchain/google-genai";
|
|
8
|
+
type GoogleGenerativeAIToolType = NonNullable<GoogleGenerativeAIChatCallOptions["tools"]>[number];
|
|
5
9
|
/**
|
|
6
10
|
* Custom ChatGoogleGenerativeAI that ensures authentication before each request
|
|
11
|
+
* and supports custom headers without modifying the library code
|
|
7
12
|
*/
|
|
8
13
|
export declare class AuthenticatedChatGoogleGenerativeAI extends ChatGoogleGenerativeAI {
|
|
14
|
+
private customHeaders?;
|
|
15
|
+
private constructorParams;
|
|
16
|
+
constructor(fields: GoogleGenerativeAIChatInput & {
|
|
17
|
+
customHeaders?: Record<string, string>;
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Recreates the client with updated custom headers
|
|
21
|
+
* Uses type assertion to access the private client property
|
|
22
|
+
*/
|
|
23
|
+
private recreateClient;
|
|
9
24
|
_generate(messages: BaseMessage[], options?: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
|
|
10
|
-
_streamResponseChunks(messages: BaseMessage[], options
|
|
25
|
+
_streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
26
|
+
bindTools(tools: GoogleGenerativeAIToolType[], kwargs?: Partial<GoogleGenerativeAIChatCallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, GoogleGenerativeAIChatCallOptions>;
|
|
11
27
|
}
|
|
28
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Serialized } from "@langchain/core/load/serializable";
|
|
2
|
+
import { type LangSmithParams } from "@langchain/core/language_models/chat_models";
|
|
2
3
|
import { ChatOpenAI } from "@langchain/openai";
|
|
3
4
|
/**
|
|
4
5
|
* Extends the ChatOpenAI class to create a ChatXAI agent with additional configurations.
|
|
@@ -37,5 +38,5 @@ export declare class ChatXAI extends ChatOpenAI {
|
|
|
37
38
|
* @param options - Additional options for parameter retrieval.
|
|
38
39
|
* @returns An object containing LangChain parameters.
|
|
39
40
|
*/
|
|
40
|
-
getLsParams(options: unknown):
|
|
41
|
+
getLsParams(options: unknown): LangSmithParams;
|
|
41
42
|
}
|
|
@@ -3,9 +3,13 @@ export declare function blTool(name: string, options?: ToolOptions | number): Pr
|
|
|
3
3
|
[x: string]: any;
|
|
4
4
|
}, {
|
|
5
5
|
[x: string]: any;
|
|
6
|
-
}>,
|
|
6
|
+
}>, unknown, {
|
|
7
|
+
[x: string]: any;
|
|
8
|
+
}, unknown>[]>;
|
|
7
9
|
export declare function blTools(names: string[], ms?: number): Promise<import("@langchain/core/tools").DynamicStructuredTool<import("zod").ZodObject<any, import("zod").UnknownKeysParam, import("zod").ZodTypeAny, {
|
|
8
10
|
[x: string]: any;
|
|
9
11
|
}, {
|
|
10
12
|
[x: string]: any;
|
|
11
|
-
}>,
|
|
13
|
+
}>, unknown, {
|
|
14
|
+
[x: string]: any;
|
|
15
|
+
}, unknown>[]>;
|