@langchain/google-common 0.2.12 → 0.2.13
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/auth.cjs +12 -4
- package/dist/auth.d.ts +1 -0
- package/dist/auth.js +9 -1
- package/dist/chat_models.cjs +6 -0
- package/dist/chat_models.d.ts +2 -1
- package/dist/chat_models.js +6 -0
- package/dist/connection.cjs +7 -2
- package/dist/connection.js +7 -2
- package/dist/llms.cjs +1 -1
- package/dist/llms.js +1 -1
- package/dist/types.d.ts +59 -0
- package/dist/utils/anthropic.cjs +3 -4
- package/dist/utils/common.cjs +12 -10
- package/dist/utils/common.js +6 -3
- package/dist/utils/failed_handler.cjs +2 -3
- package/dist/utils/gemini.cjs +112 -11
- package/dist/utils/gemini.d.ts +2 -1
- package/dist/utils/gemini.js +106 -6
- package/dist/utils/stream.cjs +12 -12
- package/dist/utils/stream.d.ts +1 -1
- package/dist/utils/stream.js +9 -9
- package/dist/utils/zod_to_gemini_parameters.cjs +4 -5
- package/package.json +4 -4
package/dist/auth.cjs
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ApiKeyGoogleAuth = exports.GoogleAbstractedFetchClient = void 0;
|
|
4
|
+
exports.aiPlatformScope = aiPlatformScope;
|
|
5
|
+
exports.ensureAuthOptionScopes = ensureAuthOptionScopes;
|
|
4
6
|
const stream_js_1 = require("./utils/stream.cjs");
|
|
5
7
|
class GoogleAbstractedFetchClient {
|
|
8
|
+
constructor() {
|
|
9
|
+
Object.defineProperty(this, "_fetch", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: fetch
|
|
14
|
+
});
|
|
15
|
+
}
|
|
6
16
|
async _buildData(res, opts) {
|
|
7
17
|
switch (opts.responseType) {
|
|
8
18
|
case "json":
|
|
@@ -32,7 +42,7 @@ class GoogleAbstractedFetchClient {
|
|
|
32
42
|
fetchOptions.body = JSON.stringify(opts.data);
|
|
33
43
|
}
|
|
34
44
|
}
|
|
35
|
-
const res = await
|
|
45
|
+
const res = await this._fetch(url, fetchOptions);
|
|
36
46
|
if (!res.ok) {
|
|
37
47
|
const resText = await res.text();
|
|
38
48
|
const error = new Error(`Google request failed with status code ${res.status}: ${resText}`);
|
|
@@ -94,7 +104,6 @@ function aiPlatformScope(platform) {
|
|
|
94
104
|
return ["https://www.googleapis.com/auth/cloud-platform"];
|
|
95
105
|
}
|
|
96
106
|
}
|
|
97
|
-
exports.aiPlatformScope = aiPlatformScope;
|
|
98
107
|
function ensureAuthOptionScopes(authOption, scopeProperty, scopesOrPlatform) {
|
|
99
108
|
// If the property is already set, return it
|
|
100
109
|
if (authOption && Object.hasOwn(authOption, scopeProperty)) {
|
|
@@ -109,4 +118,3 @@ function ensureAuthOptionScopes(authOption, scopeProperty, scopesOrPlatform) {
|
|
|
109
118
|
...(authOption ?? {}),
|
|
110
119
|
};
|
|
111
120
|
}
|
|
112
|
-
exports.ensureAuthOptionScopes = ensureAuthOptionScopes;
|
package/dist/auth.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare abstract class GoogleAbstractedFetchClient implements GoogleAbstr
|
|
|
17
17
|
abstract get clientType(): string;
|
|
18
18
|
abstract getProjectId(): Promise<string>;
|
|
19
19
|
abstract request(opts: GoogleAbstractedClientOps): unknown;
|
|
20
|
+
_fetch: typeof fetch;
|
|
20
21
|
_buildData(res: Response, opts: GoogleAbstractedClientOps): Promise<any>;
|
|
21
22
|
_request(url: string | undefined, opts: GoogleAbstractedClientOps, additionalHeaders: Record<string, string>): Promise<{
|
|
22
23
|
data: any;
|
package/dist/auth.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { ReadableJsonStream } from "./utils/stream.js";
|
|
2
2
|
export class GoogleAbstractedFetchClient {
|
|
3
|
+
constructor() {
|
|
4
|
+
Object.defineProperty(this, "_fetch", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true,
|
|
8
|
+
value: fetch
|
|
9
|
+
});
|
|
10
|
+
}
|
|
3
11
|
async _buildData(res, opts) {
|
|
4
12
|
switch (opts.responseType) {
|
|
5
13
|
case "json":
|
|
@@ -29,7 +37,7 @@ export class GoogleAbstractedFetchClient {
|
|
|
29
37
|
fetchOptions.body = JSON.stringify(opts.data);
|
|
30
38
|
}
|
|
31
39
|
}
|
|
32
|
-
const res = await
|
|
40
|
+
const res = await this._fetch(url, fetchOptions);
|
|
33
41
|
if (!res.ok) {
|
|
34
42
|
const resText = await res.text();
|
|
35
43
|
const error = new Error(`Google request failed with status code ${res.status}: ${resText}`);
|
package/dist/chat_models.cjs
CHANGED
|
@@ -224,6 +224,12 @@ class ChatGoogleBase extends chat_models_1.BaseChatModel {
|
|
|
224
224
|
writable: true,
|
|
225
225
|
value: void 0
|
|
226
226
|
});
|
|
227
|
+
Object.defineProperty(this, "speechConfig", {
|
|
228
|
+
enumerable: true,
|
|
229
|
+
configurable: true,
|
|
230
|
+
writable: true,
|
|
231
|
+
value: void 0
|
|
232
|
+
});
|
|
227
233
|
Object.defineProperty(this, "streamUsage", {
|
|
228
234
|
enumerable: true,
|
|
229
235
|
configurable: true,
|
package/dist/chat_models.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { BaseLanguageModelInput, StructuredOutputMethodOptions } from "@langchai
|
|
|
7
7
|
import { Runnable } from "@langchain/core/runnables";
|
|
8
8
|
import { AsyncCaller } from "@langchain/core/utils/async_caller";
|
|
9
9
|
import { InteropZodType } from "@langchain/core/utils/types";
|
|
10
|
-
import { GoogleAIBaseLLMInput, GoogleAIModelParams, GoogleAISafetySetting, GoogleConnectionParams, GooglePlatformType, GoogleAIBaseLanguageModelCallOptions, GoogleAIAPI, GoogleAIAPIParams, GoogleSearchToolSetting } from "./types.js";
|
|
10
|
+
import { GoogleAIBaseLLMInput, GoogleAIModelParams, GoogleAISafetySetting, GoogleConnectionParams, GooglePlatformType, GoogleAIBaseLanguageModelCallOptions, GoogleAIAPI, GoogleAIAPIParams, GoogleSearchToolSetting, GoogleSpeechConfig } from "./types.js";
|
|
11
11
|
import { AbstractGoogleLLMConnection } from "./connection.js";
|
|
12
12
|
import { GoogleAbstractedClient } from "./auth.js";
|
|
13
13
|
import type { GoogleBaseLLMInput, GoogleAISafetyHandler, GoogleAISafetyParams, GoogleAIToolType, GeminiAPIConfig, GoogleAIModelModality } from "./types.js";
|
|
@@ -52,6 +52,7 @@ export declare abstract class ChatGoogleBase<AuthOptions> extends BaseChatModel<
|
|
|
52
52
|
responseModalities?: GoogleAIModelModality[];
|
|
53
53
|
convertSystemMessageToHumanContent: boolean | undefined;
|
|
54
54
|
safetyHandler: GoogleAISafetyHandler;
|
|
55
|
+
speechConfig: GoogleSpeechConfig;
|
|
55
56
|
streamUsage: boolean;
|
|
56
57
|
streaming: boolean;
|
|
57
58
|
protected connection: ChatConnection<AuthOptions>;
|
package/dist/chat_models.js
CHANGED
|
@@ -220,6 +220,12 @@ export class ChatGoogleBase extends BaseChatModel {
|
|
|
220
220
|
writable: true,
|
|
221
221
|
value: void 0
|
|
222
222
|
});
|
|
223
|
+
Object.defineProperty(this, "speechConfig", {
|
|
224
|
+
enumerable: true,
|
|
225
|
+
configurable: true,
|
|
226
|
+
writable: true,
|
|
227
|
+
value: void 0
|
|
228
|
+
});
|
|
223
229
|
Object.defineProperty(this, "streamUsage", {
|
|
224
230
|
enumerable: true,
|
|
225
231
|
configurable: true,
|
package/dist/connection.cjs
CHANGED
|
@@ -219,7 +219,7 @@ class GoogleAIConnection extends GoogleHostConnection {
|
|
|
219
219
|
this.model = this.modelName;
|
|
220
220
|
this._apiName = fields?.apiName;
|
|
221
221
|
this.apiConfig = {
|
|
222
|
-
safetyHandler: fields?.safetyHandler,
|
|
222
|
+
safetyHandler: fields?.safetyHandler, // For backwards compatibility
|
|
223
223
|
...fields?.apiConfig,
|
|
224
224
|
};
|
|
225
225
|
}
|
|
@@ -282,7 +282,12 @@ class GoogleAIConnection extends GoogleHostConnection {
|
|
|
282
282
|
get computedLocation() {
|
|
283
283
|
switch (this.apiName) {
|
|
284
284
|
case "google":
|
|
285
|
-
|
|
285
|
+
if (this.modelName.startsWith("gemini-2.5-flash-lite")) {
|
|
286
|
+
return "global";
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
return super.computedLocation;
|
|
290
|
+
}
|
|
286
291
|
case "anthropic":
|
|
287
292
|
return "us-east5";
|
|
288
293
|
default:
|
package/dist/connection.js
CHANGED
|
@@ -213,7 +213,7 @@ export class GoogleAIConnection extends GoogleHostConnection {
|
|
|
213
213
|
this.model = this.modelName;
|
|
214
214
|
this._apiName = fields?.apiName;
|
|
215
215
|
this.apiConfig = {
|
|
216
|
-
safetyHandler: fields?.safetyHandler,
|
|
216
|
+
safetyHandler: fields?.safetyHandler, // For backwards compatibility
|
|
217
217
|
...fields?.apiConfig,
|
|
218
218
|
};
|
|
219
219
|
}
|
|
@@ -276,7 +276,12 @@ export class GoogleAIConnection extends GoogleHostConnection {
|
|
|
276
276
|
get computedLocation() {
|
|
277
277
|
switch (this.apiName) {
|
|
278
278
|
case "google":
|
|
279
|
-
|
|
279
|
+
if (this.modelName.startsWith("gemini-2.5-flash-lite")) {
|
|
280
|
+
return "global";
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
return super.computedLocation;
|
|
284
|
+
}
|
|
280
285
|
case "anthropic":
|
|
281
286
|
return "us-east5";
|
|
282
287
|
default:
|
package/dist/llms.cjs
CHANGED
package/dist/llms.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -94,6 +94,56 @@ export interface GoogleThinkingConfig {
|
|
|
94
94
|
thinkingBudget?: number;
|
|
95
95
|
includeThoughts?: boolean;
|
|
96
96
|
}
|
|
97
|
+
export type GooglePrebuiltVoiceName = string;
|
|
98
|
+
export interface GooglePrebuiltVoiceConfig {
|
|
99
|
+
voiceName: GooglePrebuiltVoiceName;
|
|
100
|
+
}
|
|
101
|
+
export interface GoogleVoiceConfig {
|
|
102
|
+
prebuiltVoiceConfig: GooglePrebuiltVoiceConfig;
|
|
103
|
+
}
|
|
104
|
+
export interface GoogleSpeakerVoiceConfig {
|
|
105
|
+
speaker: string;
|
|
106
|
+
voiceConfig: GoogleVoiceConfig;
|
|
107
|
+
}
|
|
108
|
+
export interface GoogleMultiSpeakerVoiceConfig {
|
|
109
|
+
speakerVoiceConfigs: GoogleSpeakerVoiceConfig[];
|
|
110
|
+
}
|
|
111
|
+
export interface GoogleSpeechConfigSingle {
|
|
112
|
+
voiceConfig: GoogleVoiceConfig;
|
|
113
|
+
languageCode?: string;
|
|
114
|
+
}
|
|
115
|
+
export interface GoogleSpeechConfigMulti {
|
|
116
|
+
multiSpeakerVoiceConfig: GoogleMultiSpeakerVoiceConfig;
|
|
117
|
+
languageCode?: string;
|
|
118
|
+
}
|
|
119
|
+
export type GoogleSpeechConfig = GoogleSpeechConfigSingle | GoogleSpeechConfigMulti;
|
|
120
|
+
/**
|
|
121
|
+
* A simplified version of the GoogleSpeakerVoiceConfig
|
|
122
|
+
*/
|
|
123
|
+
export interface GoogleSpeechSpeakerName {
|
|
124
|
+
speaker: string;
|
|
125
|
+
name: GooglePrebuiltVoiceName;
|
|
126
|
+
}
|
|
127
|
+
export type GoogleSpeechVoice = GooglePrebuiltVoiceName | GoogleSpeechSpeakerName | GoogleSpeechSpeakerName[];
|
|
128
|
+
export interface GoogleSpeechVoiceLanguage {
|
|
129
|
+
voice: GoogleSpeechVoice;
|
|
130
|
+
languageCode: string;
|
|
131
|
+
}
|
|
132
|
+
export interface GoogleSpeechVoicesLanguage {
|
|
133
|
+
voices: GoogleSpeechVoice;
|
|
134
|
+
languageCode: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* A simplified way to represent the voice (or voices) and language code.
|
|
138
|
+
* "voice" and "voices" are semantically the same, we're not enforcing
|
|
139
|
+
* that one is an array and one isn't.
|
|
140
|
+
*/
|
|
141
|
+
export type GoogleSpeechSimplifiedLanguage = GoogleSpeechVoiceLanguage | GoogleSpeechVoicesLanguage;
|
|
142
|
+
/**
|
|
143
|
+
* A simplified way to represent the voices.
|
|
144
|
+
* It can either be the voice (or voices), or the voice or voices with language configuration
|
|
145
|
+
*/
|
|
146
|
+
export type GoogleSpeechConfigSimplified = GoogleSpeechVoice | GoogleSpeechSimplifiedLanguage;
|
|
97
147
|
export interface GoogleAIModelParams {
|
|
98
148
|
/** Model to use */
|
|
99
149
|
model?: string;
|
|
@@ -209,6 +259,13 @@ export interface GoogleAIModelParams {
|
|
|
209
259
|
* The modalities of the response.
|
|
210
260
|
*/
|
|
211
261
|
responseModalities?: GoogleAIModelModality[];
|
|
262
|
+
/**
|
|
263
|
+
* Speech generation configuration.
|
|
264
|
+
* You can use either Google's definition of the speech configuration,
|
|
265
|
+
* or a simplified version we've defined (which can be as simple
|
|
266
|
+
* as the name of a pre-defined voice).
|
|
267
|
+
*/
|
|
268
|
+
speechConfig?: GoogleSpeechConfig | GoogleSpeechConfigSimplified;
|
|
212
269
|
}
|
|
213
270
|
export type GoogleAIToolType = BindToolsInput | GeminiTool;
|
|
214
271
|
/**
|
|
@@ -268,6 +325,7 @@ export interface GoogleRawResponse extends GoogleResponse {
|
|
|
268
325
|
}
|
|
269
326
|
export interface GeminiPartBase {
|
|
270
327
|
thought?: boolean;
|
|
328
|
+
thoughtSignature?: string;
|
|
271
329
|
}
|
|
272
330
|
export interface GeminiVideoMetadata {
|
|
273
331
|
fps?: number;
|
|
@@ -453,6 +511,7 @@ export interface GeminiGenerationConfig {
|
|
|
453
511
|
logprobs?: number;
|
|
454
512
|
responseModalities?: GoogleAIModelModality[];
|
|
455
513
|
thinkingConfig?: GoogleThinkingConfig;
|
|
514
|
+
speechConfig?: GoogleSpeechConfig;
|
|
456
515
|
}
|
|
457
516
|
export interface GeminiRequest {
|
|
458
517
|
contents?: GeminiContent[];
|
package/dist/utils/anthropic.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getAnthropicAPI = getAnthropicAPI;
|
|
4
|
+
exports.validateClaudeParams = validateClaudeParams;
|
|
5
|
+
exports.isModelClaude = isModelClaude;
|
|
4
6
|
const outputs_1 = require("@langchain/core/outputs");
|
|
5
7
|
const messages_1 = require("@langchain/core/messages");
|
|
6
8
|
function getAnthropicAPI(config) {
|
|
@@ -815,12 +817,9 @@ function getAnthropicAPI(config) {
|
|
|
815
817
|
formatData,
|
|
816
818
|
};
|
|
817
819
|
}
|
|
818
|
-
exports.getAnthropicAPI = getAnthropicAPI;
|
|
819
820
|
function validateClaudeParams(_params) {
|
|
820
821
|
// FIXME - validate the parameters
|
|
821
822
|
}
|
|
822
|
-
exports.validateClaudeParams = validateClaudeParams;
|
|
823
823
|
function isModelClaude(modelName) {
|
|
824
824
|
return modelName.toLowerCase().startsWith("claude");
|
|
825
825
|
}
|
|
826
|
-
exports.isModelClaude = isModelClaude;
|
package/dist/utils/common.cjs
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.copyAIModelParams = copyAIModelParams;
|
|
4
|
+
exports.convertToGeminiTools = convertToGeminiTools;
|
|
5
|
+
exports.copyAIModelParamsInto = copyAIModelParamsInto;
|
|
6
|
+
exports.modelToFamily = modelToFamily;
|
|
7
|
+
exports.modelToPublisher = modelToPublisher;
|
|
8
|
+
exports.validateModelParams = validateModelParams;
|
|
9
|
+
exports.copyAndValidateModelParamsInto = copyAndValidateModelParamsInto;
|
|
4
10
|
const base_1 = require("@langchain/core/language_models/base");
|
|
5
11
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
6
12
|
const gemini_js_1 = require("./gemini.cjs");
|
|
@@ -10,7 +16,6 @@ const anthropic_js_1 = require("./anthropic.cjs");
|
|
|
10
16
|
function copyAIModelParams(params, options) {
|
|
11
17
|
return copyAIModelParamsInto(params, options, {});
|
|
12
18
|
}
|
|
13
|
-
exports.copyAIModelParams = copyAIModelParams;
|
|
14
19
|
function processToolChoice(toolChoice, allowedFunctionNames) {
|
|
15
20
|
if (!toolChoice) {
|
|
16
21
|
if (allowedFunctionNames) {
|
|
@@ -90,7 +95,6 @@ function convertToGeminiTools(tools) {
|
|
|
90
95
|
});
|
|
91
96
|
return geminiTools;
|
|
92
97
|
}
|
|
93
|
-
exports.convertToGeminiTools = convertToGeminiTools;
|
|
94
98
|
function reasoningEffortToReasoningTokens(_modelName, effort) {
|
|
95
99
|
if (effort === undefined) {
|
|
96
100
|
return undefined;
|
|
@@ -98,9 +102,11 @@ function reasoningEffortToReasoningTokens(_modelName, effort) {
|
|
|
98
102
|
const maxEffort = 24 * 1024; // Max for Gemini 2.5 Flash
|
|
99
103
|
switch (effort) {
|
|
100
104
|
case "low":
|
|
101
|
-
|
|
105
|
+
// Defined as 1k by https://ai.google.dev/gemini-api/docs/openai#thinking
|
|
106
|
+
return 1024;
|
|
102
107
|
case "medium":
|
|
103
|
-
|
|
108
|
+
// Defined as 8k by https://ai.google.dev/gemini-api/docs/openai#thinking
|
|
109
|
+
return 8 * 1024;
|
|
104
110
|
case "high":
|
|
105
111
|
return maxEffort;
|
|
106
112
|
default:
|
|
@@ -159,6 +165,7 @@ function copyAIModelParamsInto(params, options, target) {
|
|
|
159
165
|
options?.responseModalities ??
|
|
160
166
|
params?.responseModalities ??
|
|
161
167
|
target?.responseModalities;
|
|
168
|
+
ret.speechConfig = (0, gemini_js_1.normalizeSpeechConfig)(options?.speechConfig ?? params?.speechConfig ?? target?.speechConfig);
|
|
162
169
|
ret.streaming = options?.streaming ?? params?.streaming ?? target?.streaming;
|
|
163
170
|
const toolChoice = processToolChoice(options?.tool_choice, options?.allowed_function_names);
|
|
164
171
|
if (toolChoice) {
|
|
@@ -175,7 +182,6 @@ function copyAIModelParamsInto(params, options, target) {
|
|
|
175
182
|
}
|
|
176
183
|
return ret;
|
|
177
184
|
}
|
|
178
|
-
exports.copyAIModelParamsInto = copyAIModelParamsInto;
|
|
179
185
|
function modelToFamily(modelName) {
|
|
180
186
|
if (!modelName) {
|
|
181
187
|
return null;
|
|
@@ -193,7 +199,6 @@ function modelToFamily(modelName) {
|
|
|
193
199
|
return null;
|
|
194
200
|
}
|
|
195
201
|
}
|
|
196
|
-
exports.modelToFamily = modelToFamily;
|
|
197
202
|
function modelToPublisher(modelName) {
|
|
198
203
|
const family = modelToFamily(modelName);
|
|
199
204
|
switch (family) {
|
|
@@ -207,7 +212,6 @@ function modelToPublisher(modelName) {
|
|
|
207
212
|
return "unknown";
|
|
208
213
|
}
|
|
209
214
|
}
|
|
210
|
-
exports.modelToPublisher = modelToPublisher;
|
|
211
215
|
function validateModelParams(params) {
|
|
212
216
|
const testParams = params ?? {};
|
|
213
217
|
const model = testParams.model ?? testParams.modelName;
|
|
@@ -221,10 +225,8 @@ function validateModelParams(params) {
|
|
|
221
225
|
throw new Error(`Unable to verify model params: ${JSON.stringify(params)}`);
|
|
222
226
|
}
|
|
223
227
|
}
|
|
224
|
-
exports.validateModelParams = validateModelParams;
|
|
225
228
|
function copyAndValidateModelParamsInto(params, target) {
|
|
226
229
|
copyAIModelParamsInto(params, undefined, target);
|
|
227
230
|
validateModelParams(target);
|
|
228
231
|
return target;
|
|
229
232
|
}
|
|
230
|
-
exports.copyAndValidateModelParamsInto = copyAndValidateModelParamsInto;
|
package/dist/utils/common.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isOpenAITool } from "@langchain/core/language_models/base";
|
|
2
2
|
import { isLangChainTool } from "@langchain/core/utils/function_calling";
|
|
3
|
-
import { isModelGemini, isModelGemma, validateGeminiParams } from "./gemini.js";
|
|
3
|
+
import { isModelGemini, isModelGemma, normalizeSpeechConfig, validateGeminiParams, } from "./gemini.js";
|
|
4
4
|
import { GeminiToolAttributes, } from "../types.js";
|
|
5
5
|
import { jsonSchemaToGeminiParameters, schemaToGeminiParameters, } from "./zod_to_gemini_parameters.js";
|
|
6
6
|
import { isModelClaude, validateClaudeParams } from "./anthropic.js";
|
|
@@ -93,9 +93,11 @@ function reasoningEffortToReasoningTokens(_modelName, effort) {
|
|
|
93
93
|
const maxEffort = 24 * 1024; // Max for Gemini 2.5 Flash
|
|
94
94
|
switch (effort) {
|
|
95
95
|
case "low":
|
|
96
|
-
|
|
96
|
+
// Defined as 1k by https://ai.google.dev/gemini-api/docs/openai#thinking
|
|
97
|
+
return 1024;
|
|
97
98
|
case "medium":
|
|
98
|
-
|
|
99
|
+
// Defined as 8k by https://ai.google.dev/gemini-api/docs/openai#thinking
|
|
100
|
+
return 8 * 1024;
|
|
99
101
|
case "high":
|
|
100
102
|
return maxEffort;
|
|
101
103
|
default:
|
|
@@ -154,6 +156,7 @@ export function copyAIModelParamsInto(params, options, target) {
|
|
|
154
156
|
options?.responseModalities ??
|
|
155
157
|
params?.responseModalities ??
|
|
156
158
|
target?.responseModalities;
|
|
159
|
+
ret.speechConfig = normalizeSpeechConfig(options?.speechConfig ?? params?.speechConfig ?? target?.speechConfig);
|
|
157
160
|
ret.streaming = options?.streaming ?? params?.streaming ?? target?.streaming;
|
|
158
161
|
const toolChoice = processToolChoice(options?.tool_choice, options?.allowed_function_names);
|
|
159
162
|
if (toolChoice) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.failedAttemptHandler = failedAttemptHandler;
|
|
4
|
+
exports.ensureParams = ensureParams;
|
|
4
5
|
const STATUS_NO_RETRY = [
|
|
5
6
|
400,
|
|
6
7
|
401,
|
|
@@ -26,7 +27,6 @@ function failedAttemptHandler(error) {
|
|
|
26
27
|
throw error;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
exports.failedAttemptHandler = failedAttemptHandler;
|
|
30
30
|
function ensureParams(params) {
|
|
31
31
|
const base = params ?? {};
|
|
32
32
|
return {
|
|
@@ -34,4 +34,3 @@ function ensureParams(params) {
|
|
|
34
34
|
...base,
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
exports.ensureParams = ensureParams;
|
package/dist/utils/gemini.cjs
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MessageGeminiSafetyHandler = exports.DefaultGeminiSafetyHandler = void 0;
|
|
4
|
+
exports.normalizeSpeechConfig = normalizeSpeechConfig;
|
|
5
|
+
exports.getGeminiAPI = getGeminiAPI;
|
|
6
|
+
exports.validateGeminiParams = validateGeminiParams;
|
|
7
|
+
exports.isModelGemini = isModelGemini;
|
|
8
|
+
exports.isModelGemma = isModelGemma;
|
|
4
9
|
const uuid_1 = require("uuid");
|
|
5
10
|
const messages_1 = require("@langchain/core/messages");
|
|
6
11
|
const outputs_1 = require("@langchain/core/outputs");
|
|
7
12
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
8
13
|
const stream_1 = require("@langchain/core/utils/stream");
|
|
9
|
-
const safety_js_1 = require("./safety.cjs");
|
|
10
14
|
const types_js_1 = require("../types.cjs");
|
|
15
|
+
const safety_js_1 = require("./safety.cjs");
|
|
11
16
|
const zod_to_gemini_parameters_js_1 = require("./zod_to_gemini_parameters.cjs");
|
|
12
17
|
class DefaultGeminiSafetyHandler {
|
|
13
18
|
constructor(settings) {
|
|
@@ -125,6 +130,73 @@ const extractMimeType = (str) => {
|
|
|
125
130
|
}
|
|
126
131
|
return null;
|
|
127
132
|
};
|
|
133
|
+
function normalizeSpeechConfig(config) {
|
|
134
|
+
function isSpeechConfig(config) {
|
|
135
|
+
return (typeof config === "object" &&
|
|
136
|
+
(Object.hasOwn(config, "voiceConfig") ||
|
|
137
|
+
Object.hasOwn(config, "multiSpeakerVoiceConfig")));
|
|
138
|
+
}
|
|
139
|
+
function hasLanguage(config) {
|
|
140
|
+
return typeof config === "object" && Object.hasOwn(config, "languageCode");
|
|
141
|
+
}
|
|
142
|
+
function hasVoice(config) {
|
|
143
|
+
return Object.hasOwn(config, "voice");
|
|
144
|
+
}
|
|
145
|
+
if (typeof config === "undefined") {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
// If this is already a GoogleSpeechConfig, just return it
|
|
149
|
+
if (isSpeechConfig(config)) {
|
|
150
|
+
return config;
|
|
151
|
+
}
|
|
152
|
+
let languageCode;
|
|
153
|
+
let voice;
|
|
154
|
+
if (hasLanguage(config)) {
|
|
155
|
+
languageCode = config.languageCode;
|
|
156
|
+
voice = hasVoice(config) ? config.voice : config.voices;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
languageCode = undefined;
|
|
160
|
+
voice = config;
|
|
161
|
+
}
|
|
162
|
+
let ret;
|
|
163
|
+
if (typeof voice === "string") {
|
|
164
|
+
// They just provided the prebuilt voice configuration name. Use it.
|
|
165
|
+
ret = {
|
|
166
|
+
voiceConfig: {
|
|
167
|
+
prebuiltVoiceConfig: {
|
|
168
|
+
voiceName: voice,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
// This is multi-speaker, so we have speaker/name pairs
|
|
175
|
+
// If we have just one (why?), turn it into an array for the moment
|
|
176
|
+
const voices = Array.isArray(voice)
|
|
177
|
+
? voice
|
|
178
|
+
: [voice];
|
|
179
|
+
// Go through all the speaker/name pairs and turn this into the voice config array
|
|
180
|
+
const speakerVoiceConfigs = voices.map((v) => ({
|
|
181
|
+
speaker: v.speaker,
|
|
182
|
+
voiceConfig: {
|
|
183
|
+
prebuiltVoiceConfig: {
|
|
184
|
+
voiceName: v.name,
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
}));
|
|
188
|
+
// Create the multi-speaker voice configuration
|
|
189
|
+
ret = {
|
|
190
|
+
multiSpeakerVoiceConfig: {
|
|
191
|
+
speakerVoiceConfigs,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
if (languageCode) {
|
|
196
|
+
ret.languageCode = languageCode;
|
|
197
|
+
}
|
|
198
|
+
return ret;
|
|
199
|
+
}
|
|
128
200
|
function getGeminiAPI(config) {
|
|
129
201
|
function messageContentText(content) {
|
|
130
202
|
if (content?.text && content?.text.length > 0) {
|
|
@@ -425,6 +497,15 @@ function getGeminiAPI(config) {
|
|
|
425
497
|
toolParts = messageKwargsToParts(message.additional_kwargs);
|
|
426
498
|
}
|
|
427
499
|
const parts = [...contentParts, ...toolParts];
|
|
500
|
+
const signatures = message?.additional_kwargs?.signatures ?? [];
|
|
501
|
+
if (signatures.length === parts.length) {
|
|
502
|
+
for (let co = 0; co < signatures.length; co += 1) {
|
|
503
|
+
const signature = signatures[co];
|
|
504
|
+
if (signature && signature.length > 0) {
|
|
505
|
+
parts[co].thoughtSignature = signature;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
428
509
|
return [
|
|
429
510
|
{
|
|
430
511
|
role,
|
|
@@ -518,12 +599,32 @@ function getGeminiAPI(config) {
|
|
|
518
599
|
text: part.text,
|
|
519
600
|
};
|
|
520
601
|
}
|
|
521
|
-
function
|
|
602
|
+
function inlineDataPartToMessageContentImage(part) {
|
|
522
603
|
return {
|
|
523
604
|
type: "image_url",
|
|
524
605
|
image_url: `data:${part.inlineData.mimeType};base64,${part.inlineData.data}`,
|
|
525
606
|
};
|
|
526
607
|
}
|
|
608
|
+
function inlineDataPartToMessageContentMedia(part
|
|
609
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
610
|
+
) {
|
|
611
|
+
return {
|
|
612
|
+
type: "media",
|
|
613
|
+
mimeType: part.inlineData.mimeType,
|
|
614
|
+
data: part.inlineData.data,
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
function inlineDataPartToMessageContent(part
|
|
618
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
619
|
+
) {
|
|
620
|
+
const mimeType = part?.inlineData?.mimeType ?? "";
|
|
621
|
+
if (mimeType.startsWith("image")) {
|
|
622
|
+
return inlineDataPartToMessageContentImage(part);
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
return inlineDataPartToMessageContentMedia(part);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
527
628
|
function fileDataPartToMessageContent(part) {
|
|
528
629
|
return {
|
|
529
630
|
type: "image_url",
|
|
@@ -1013,6 +1114,9 @@ function getGeminiAPI(config) {
|
|
|
1013
1114
|
const parts = responseToParts(response);
|
|
1014
1115
|
return partsToBaseMessageChunkFields(parts);
|
|
1015
1116
|
}
|
|
1117
|
+
function partsToSignatures(parts) {
|
|
1118
|
+
return parts.map((part) => part?.thoughtSignature ?? "");
|
|
1119
|
+
}
|
|
1016
1120
|
function partsToBaseMessageChunkFields(parts) {
|
|
1017
1121
|
const fields = {
|
|
1018
1122
|
content: partsToMessageContent(parts),
|
|
@@ -1020,6 +1124,7 @@ function getGeminiAPI(config) {
|
|
|
1020
1124
|
tool_calls: [],
|
|
1021
1125
|
invalid_tool_calls: [],
|
|
1022
1126
|
};
|
|
1127
|
+
fields.additional_kwargs = {};
|
|
1023
1128
|
const rawTools = partsToToolsRaw(parts);
|
|
1024
1129
|
if (rawTools.length > 0) {
|
|
1025
1130
|
const tools = toolsRawToTools(rawTools);
|
|
@@ -1048,10 +1153,9 @@ function getGeminiAPI(config) {
|
|
|
1048
1153
|
});
|
|
1049
1154
|
}
|
|
1050
1155
|
}
|
|
1051
|
-
fields.additional_kwargs =
|
|
1052
|
-
tool_calls: tools,
|
|
1053
|
-
};
|
|
1156
|
+
fields.additional_kwargs.tool_calls = tools;
|
|
1054
1157
|
}
|
|
1158
|
+
fields.additional_kwargs.signatures = partsToSignatures(parts);
|
|
1055
1159
|
return fields;
|
|
1056
1160
|
}
|
|
1057
1161
|
function responseToBaseMessage(response) {
|
|
@@ -1089,7 +1193,7 @@ function getGeminiAPI(config) {
|
|
|
1089
1193
|
const parts = await messageContentToParts(input);
|
|
1090
1194
|
const contents = [
|
|
1091
1195
|
{
|
|
1092
|
-
role: "user",
|
|
1196
|
+
role: "user", // Required by Vertex AI
|
|
1093
1197
|
parts,
|
|
1094
1198
|
},
|
|
1095
1199
|
];
|
|
@@ -1141,6 +1245,7 @@ function getGeminiAPI(config) {
|
|
|
1141
1245
|
stopSequences: parameters.stopSequences,
|
|
1142
1246
|
responseMimeType: parameters.responseMimeType,
|
|
1143
1247
|
responseModalities: parameters.responseModalities,
|
|
1248
|
+
speechConfig: normalizeSpeechConfig(parameters.speechConfig),
|
|
1144
1249
|
};
|
|
1145
1250
|
// Add the logprobs if explicitly set
|
|
1146
1251
|
if (typeof parameters.logprobs !== "undefined") {
|
|
@@ -1316,7 +1421,6 @@ function getGeminiAPI(config) {
|
|
|
1316
1421
|
formatData,
|
|
1317
1422
|
};
|
|
1318
1423
|
}
|
|
1319
|
-
exports.getGeminiAPI = getGeminiAPI;
|
|
1320
1424
|
function validateGeminiParams(params) {
|
|
1321
1425
|
if (params.maxOutputTokens && params.maxOutputTokens < 0) {
|
|
1322
1426
|
throw new Error("`maxOutputTokens` must be a positive integer");
|
|
@@ -1342,12 +1446,9 @@ function validateGeminiParams(params) {
|
|
|
1342
1446
|
throw new Error("`topK` must be a positive integer");
|
|
1343
1447
|
}
|
|
1344
1448
|
}
|
|
1345
|
-
exports.validateGeminiParams = validateGeminiParams;
|
|
1346
1449
|
function isModelGemini(modelName) {
|
|
1347
1450
|
return modelName.toLowerCase().startsWith("gemini");
|
|
1348
1451
|
}
|
|
1349
|
-
exports.isModelGemini = isModelGemini;
|
|
1350
1452
|
function isModelGemma(modelName) {
|
|
1351
1453
|
return modelName.toLowerCase().startsWith("gemma");
|
|
1352
1454
|
}
|
|
1353
|
-
exports.isModelGemma = isModelGemma;
|
package/dist/utils/gemini.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { GoogleLLMResponse, GoogleAIModelParams, GenerateContentResponseData, GoogleAISafetyHandler, GoogleAIAPI, GeminiAPIConfig, GoogleSpeechConfig, GoogleSpeechConfigSimplified } from "../types.js";
|
|
2
2
|
export interface FunctionCall {
|
|
3
3
|
name: string;
|
|
4
4
|
arguments: string;
|
|
@@ -39,6 +39,7 @@ export declare class MessageGeminiSafetyHandler extends DefaultGeminiSafetyHandl
|
|
|
39
39
|
setMessage(data: GenerateContentResponseData): GenerateContentResponseData;
|
|
40
40
|
handleData(response: GoogleLLMResponse, data: GenerateContentResponseData): GenerateContentResponseData;
|
|
41
41
|
}
|
|
42
|
+
export declare function normalizeSpeechConfig(config: GoogleSpeechConfig | GoogleSpeechConfigSimplified | undefined): GoogleSpeechConfig | undefined;
|
|
42
43
|
export declare function getGeminiAPI(config?: GeminiAPIConfig): GoogleAIAPI;
|
|
43
44
|
export declare function validateGeminiParams(params: GoogleAIModelParams): void;
|
|
44
45
|
export declare function isModelGemini(modelName: string): boolean;
|
package/dist/utils/gemini.js
CHANGED
|
@@ -3,8 +3,8 @@ import { AIMessage, AIMessageChunk, isAIMessage, parseBase64DataUrl, isDataConte
|
|
|
3
3
|
import { ChatGenerationChunk, } from "@langchain/core/outputs";
|
|
4
4
|
import { isLangChainTool } from "@langchain/core/utils/function_calling";
|
|
5
5
|
import { concat } from "@langchain/core/utils/stream";
|
|
6
|
-
import { GoogleAISafetyError } from "./safety.js";
|
|
7
6
|
import { GeminiSearchToolAttributes, } from "../types.js";
|
|
7
|
+
import { GoogleAISafetyError } from "./safety.js";
|
|
8
8
|
import { schemaToGeminiParameters } from "./zod_to_gemini_parameters.js";
|
|
9
9
|
export class DefaultGeminiSafetyHandler {
|
|
10
10
|
constructor(settings) {
|
|
@@ -120,6 +120,73 @@ const extractMimeType = (str) => {
|
|
|
120
120
|
}
|
|
121
121
|
return null;
|
|
122
122
|
};
|
|
123
|
+
export function normalizeSpeechConfig(config) {
|
|
124
|
+
function isSpeechConfig(config) {
|
|
125
|
+
return (typeof config === "object" &&
|
|
126
|
+
(Object.hasOwn(config, "voiceConfig") ||
|
|
127
|
+
Object.hasOwn(config, "multiSpeakerVoiceConfig")));
|
|
128
|
+
}
|
|
129
|
+
function hasLanguage(config) {
|
|
130
|
+
return typeof config === "object" && Object.hasOwn(config, "languageCode");
|
|
131
|
+
}
|
|
132
|
+
function hasVoice(config) {
|
|
133
|
+
return Object.hasOwn(config, "voice");
|
|
134
|
+
}
|
|
135
|
+
if (typeof config === "undefined") {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
// If this is already a GoogleSpeechConfig, just return it
|
|
139
|
+
if (isSpeechConfig(config)) {
|
|
140
|
+
return config;
|
|
141
|
+
}
|
|
142
|
+
let languageCode;
|
|
143
|
+
let voice;
|
|
144
|
+
if (hasLanguage(config)) {
|
|
145
|
+
languageCode = config.languageCode;
|
|
146
|
+
voice = hasVoice(config) ? config.voice : config.voices;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
languageCode = undefined;
|
|
150
|
+
voice = config;
|
|
151
|
+
}
|
|
152
|
+
let ret;
|
|
153
|
+
if (typeof voice === "string") {
|
|
154
|
+
// They just provided the prebuilt voice configuration name. Use it.
|
|
155
|
+
ret = {
|
|
156
|
+
voiceConfig: {
|
|
157
|
+
prebuiltVoiceConfig: {
|
|
158
|
+
voiceName: voice,
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// This is multi-speaker, so we have speaker/name pairs
|
|
165
|
+
// If we have just one (why?), turn it into an array for the moment
|
|
166
|
+
const voices = Array.isArray(voice)
|
|
167
|
+
? voice
|
|
168
|
+
: [voice];
|
|
169
|
+
// Go through all the speaker/name pairs and turn this into the voice config array
|
|
170
|
+
const speakerVoiceConfigs = voices.map((v) => ({
|
|
171
|
+
speaker: v.speaker,
|
|
172
|
+
voiceConfig: {
|
|
173
|
+
prebuiltVoiceConfig: {
|
|
174
|
+
voiceName: v.name,
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
}));
|
|
178
|
+
// Create the multi-speaker voice configuration
|
|
179
|
+
ret = {
|
|
180
|
+
multiSpeakerVoiceConfig: {
|
|
181
|
+
speakerVoiceConfigs,
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
if (languageCode) {
|
|
186
|
+
ret.languageCode = languageCode;
|
|
187
|
+
}
|
|
188
|
+
return ret;
|
|
189
|
+
}
|
|
123
190
|
export function getGeminiAPI(config) {
|
|
124
191
|
function messageContentText(content) {
|
|
125
192
|
if (content?.text && content?.text.length > 0) {
|
|
@@ -420,6 +487,15 @@ export function getGeminiAPI(config) {
|
|
|
420
487
|
toolParts = messageKwargsToParts(message.additional_kwargs);
|
|
421
488
|
}
|
|
422
489
|
const parts = [...contentParts, ...toolParts];
|
|
490
|
+
const signatures = message?.additional_kwargs?.signatures ?? [];
|
|
491
|
+
if (signatures.length === parts.length) {
|
|
492
|
+
for (let co = 0; co < signatures.length; co += 1) {
|
|
493
|
+
const signature = signatures[co];
|
|
494
|
+
if (signature && signature.length > 0) {
|
|
495
|
+
parts[co].thoughtSignature = signature;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
423
499
|
return [
|
|
424
500
|
{
|
|
425
501
|
role,
|
|
@@ -513,12 +589,32 @@ export function getGeminiAPI(config) {
|
|
|
513
589
|
text: part.text,
|
|
514
590
|
};
|
|
515
591
|
}
|
|
516
|
-
function
|
|
592
|
+
function inlineDataPartToMessageContentImage(part) {
|
|
517
593
|
return {
|
|
518
594
|
type: "image_url",
|
|
519
595
|
image_url: `data:${part.inlineData.mimeType};base64,${part.inlineData.data}`,
|
|
520
596
|
};
|
|
521
597
|
}
|
|
598
|
+
function inlineDataPartToMessageContentMedia(part
|
|
599
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
600
|
+
) {
|
|
601
|
+
return {
|
|
602
|
+
type: "media",
|
|
603
|
+
mimeType: part.inlineData.mimeType,
|
|
604
|
+
data: part.inlineData.data,
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
function inlineDataPartToMessageContent(part
|
|
608
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
609
|
+
) {
|
|
610
|
+
const mimeType = part?.inlineData?.mimeType ?? "";
|
|
611
|
+
if (mimeType.startsWith("image")) {
|
|
612
|
+
return inlineDataPartToMessageContentImage(part);
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
return inlineDataPartToMessageContentMedia(part);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
522
618
|
function fileDataPartToMessageContent(part) {
|
|
523
619
|
return {
|
|
524
620
|
type: "image_url",
|
|
@@ -1008,6 +1104,9 @@ export function getGeminiAPI(config) {
|
|
|
1008
1104
|
const parts = responseToParts(response);
|
|
1009
1105
|
return partsToBaseMessageChunkFields(parts);
|
|
1010
1106
|
}
|
|
1107
|
+
function partsToSignatures(parts) {
|
|
1108
|
+
return parts.map((part) => part?.thoughtSignature ?? "");
|
|
1109
|
+
}
|
|
1011
1110
|
function partsToBaseMessageChunkFields(parts) {
|
|
1012
1111
|
const fields = {
|
|
1013
1112
|
content: partsToMessageContent(parts),
|
|
@@ -1015,6 +1114,7 @@ export function getGeminiAPI(config) {
|
|
|
1015
1114
|
tool_calls: [],
|
|
1016
1115
|
invalid_tool_calls: [],
|
|
1017
1116
|
};
|
|
1117
|
+
fields.additional_kwargs = {};
|
|
1018
1118
|
const rawTools = partsToToolsRaw(parts);
|
|
1019
1119
|
if (rawTools.length > 0) {
|
|
1020
1120
|
const tools = toolsRawToTools(rawTools);
|
|
@@ -1043,10 +1143,9 @@ export function getGeminiAPI(config) {
|
|
|
1043
1143
|
});
|
|
1044
1144
|
}
|
|
1045
1145
|
}
|
|
1046
|
-
fields.additional_kwargs =
|
|
1047
|
-
tool_calls: tools,
|
|
1048
|
-
};
|
|
1146
|
+
fields.additional_kwargs.tool_calls = tools;
|
|
1049
1147
|
}
|
|
1148
|
+
fields.additional_kwargs.signatures = partsToSignatures(parts);
|
|
1050
1149
|
return fields;
|
|
1051
1150
|
}
|
|
1052
1151
|
function responseToBaseMessage(response) {
|
|
@@ -1084,7 +1183,7 @@ export function getGeminiAPI(config) {
|
|
|
1084
1183
|
const parts = await messageContentToParts(input);
|
|
1085
1184
|
const contents = [
|
|
1086
1185
|
{
|
|
1087
|
-
role: "user",
|
|
1186
|
+
role: "user", // Required by Vertex AI
|
|
1088
1187
|
parts,
|
|
1089
1188
|
},
|
|
1090
1189
|
];
|
|
@@ -1136,6 +1235,7 @@ export function getGeminiAPI(config) {
|
|
|
1136
1235
|
stopSequences: parameters.stopSequences,
|
|
1137
1236
|
responseMimeType: parameters.responseMimeType,
|
|
1138
1237
|
responseModalities: parameters.responseModalities,
|
|
1238
|
+
speechConfig: normalizeSpeechConfig(parameters.speechConfig),
|
|
1139
1239
|
};
|
|
1140
1240
|
// Add the logprobs if explicitly set
|
|
1141
1241
|
if (typeof parameters.logprobs !== "undefined") {
|
package/dist/utils/stream.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReadableSseJsonStream = exports.SseJsonStream = exports.ReadableSseStream = exports.SseStream = exports.ReadableJsonStream = exports.ReadableAbstractStream = exports.ComplexJsonStream = exports.JsonStream =
|
|
3
|
+
exports.ReadableSseJsonStream = exports.SseJsonStream = exports.ReadableSseStream = exports.SseStream = exports.ReadableJsonStream = exports.ReadableAbstractStream = exports.ComplexJsonStream = exports.JsonStream = void 0;
|
|
4
|
+
exports.complexValue = complexValue;
|
|
5
|
+
exports.simpleValue = simpleValue;
|
|
4
6
|
function complexValue(value) {
|
|
5
7
|
if (value === null || typeof value === "undefined") {
|
|
6
8
|
// I dunno what to put here. An error, probably
|
|
@@ -36,7 +38,6 @@ function complexValue(value) {
|
|
|
36
38
|
};
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
|
-
exports.complexValue = complexValue;
|
|
40
41
|
function simpleValue(val) {
|
|
41
42
|
if (val && typeof val === "object" && !Array.isArray(val)) {
|
|
42
43
|
// eslint-disable-next-line no-prototype-builtins
|
|
@@ -77,7 +78,6 @@ function simpleValue(val) {
|
|
|
77
78
|
return val;
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
|
-
exports.simpleValue = simpleValue;
|
|
81
81
|
class JsonStream {
|
|
82
82
|
constructor() {
|
|
83
83
|
Object.defineProperty(this, "_buffer", {
|
|
@@ -304,19 +304,19 @@ class ReadableAbstractStream {
|
|
|
304
304
|
get streamDone() {
|
|
305
305
|
return this.baseStream.streamDone;
|
|
306
306
|
}
|
|
307
|
+
// Should be a ReadableStream, but the Gaxios Readable stream isn't.
|
|
308
|
+
// But both should support async iterators, so make sure of that.
|
|
309
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
307
310
|
async run(body) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
while (!isDone) {
|
|
311
|
-
const { value, done } = await reader.read();
|
|
312
|
-
if (!done) {
|
|
311
|
+
if (typeof body[Symbol.asyncIterator] === "function") {
|
|
312
|
+
for await (const value of body) {
|
|
313
313
|
const svalue = this.decoder.decode(value, { stream: true });
|
|
314
314
|
this.appendBuffer(svalue);
|
|
315
315
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
316
|
+
this.closeBuffer();
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
throw Error("Stream must implement async iterator.");
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
}
|
package/dist/utils/stream.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ export declare class ReadableAbstractStream implements AbstractStream {
|
|
|
96
96
|
closeBuffer(): void;
|
|
97
97
|
nextChunk(): Promise<any>;
|
|
98
98
|
get streamDone(): boolean;
|
|
99
|
-
run(body:
|
|
99
|
+
run(body: any): Promise<void>;
|
|
100
100
|
}
|
|
101
101
|
export declare class ReadableJsonStream extends ReadableAbstractStream {
|
|
102
102
|
constructor(body: ReadableStream | null);
|
package/dist/utils/stream.js
CHANGED
|
@@ -297,19 +297,19 @@ export class ReadableAbstractStream {
|
|
|
297
297
|
get streamDone() {
|
|
298
298
|
return this.baseStream.streamDone;
|
|
299
299
|
}
|
|
300
|
+
// Should be a ReadableStream, but the Gaxios Readable stream isn't.
|
|
301
|
+
// But both should support async iterators, so make sure of that.
|
|
302
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
300
303
|
async run(body) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
while (!isDone) {
|
|
304
|
-
const { value, done } = await reader.read();
|
|
305
|
-
if (!done) {
|
|
304
|
+
if (typeof body[Symbol.asyncIterator] === "function") {
|
|
305
|
+
for await (const value of body) {
|
|
306
306
|
const svalue = this.decoder.decode(value, { stream: true });
|
|
307
307
|
this.appendBuffer(svalue);
|
|
308
308
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
309
|
+
this.closeBuffer();
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
throw Error("Stream must implement async iterator.");
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.adjustObjectType = adjustObjectType;
|
|
5
|
+
exports.removeAdditionalProperties = removeAdditionalProperties;
|
|
6
|
+
exports.schemaToGeminiParameters = schemaToGeminiParameters;
|
|
7
|
+
exports.jsonSchemaToGeminiParameters = jsonSchemaToGeminiParameters;
|
|
5
8
|
const types_1 = require("@langchain/core/utils/types");
|
|
6
9
|
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
7
10
|
/* eslint-disable no-param-reassign */
|
|
@@ -38,7 +41,6 @@ obj
|
|
|
38
41
|
}
|
|
39
42
|
return obj;
|
|
40
43
|
}
|
|
41
|
-
exports.adjustObjectType = adjustObjectType;
|
|
42
44
|
/* eslint-enable no-param-reassign */
|
|
43
45
|
function removeAdditionalProperties(
|
|
44
46
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -63,7 +65,6 @@ obj) {
|
|
|
63
65
|
}
|
|
64
66
|
return obj;
|
|
65
67
|
}
|
|
66
|
-
exports.removeAdditionalProperties = removeAdditionalProperties;
|
|
67
68
|
function schemaToGeminiParameters(schema) {
|
|
68
69
|
// Gemini doesn't accept either the $schema or additionalProperties
|
|
69
70
|
// attributes, so we need to explicitly remove them.
|
|
@@ -73,7 +74,6 @@ function schemaToGeminiParameters(schema) {
|
|
|
73
74
|
const { $schema, ...rest } = jsonSchema;
|
|
74
75
|
return rest;
|
|
75
76
|
}
|
|
76
|
-
exports.schemaToGeminiParameters = schemaToGeminiParameters;
|
|
77
77
|
function jsonSchemaToGeminiParameters(
|
|
78
78
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
79
|
schema) {
|
|
@@ -84,4 +84,3 @@ schema) {
|
|
|
84
84
|
const { $schema, ...rest } = jsonSchema;
|
|
85
85
|
return rest;
|
|
86
86
|
}
|
|
87
|
-
exports.jsonSchemaToGeminiParameters = jsonSchemaToGeminiParameters;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/google-common",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"description": "Core types and classes for Google services.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"build": "yarn turbo:command build:internal --filter=@langchain/google-common",
|
|
18
18
|
"build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking",
|
|
19
19
|
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
|
|
20
|
-
"lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
|
|
20
|
+
"lint:dpdm": "dpdm --skip-dynamic-imports circular --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
|
|
21
21
|
"lint": "yarn lint:eslint && yarn lint:dpdm",
|
|
22
22
|
"lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
|
|
23
23
|
"clean": "rm -rf .turbo dist/",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
48
48
|
"@typescript-eslint/parser": "^6.12.0",
|
|
49
49
|
"dotenv": "^16.3.1",
|
|
50
|
-
"dpdm": "^3.
|
|
50
|
+
"dpdm": "^3.14.0",
|
|
51
51
|
"eslint": "^8.33.0",
|
|
52
52
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
53
53
|
"eslint-config-prettier": "^8.6.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"release-it": "^18.1.2",
|
|
61
61
|
"rollup": "^4.5.2",
|
|
62
62
|
"ts-jest": "^29.1.0",
|
|
63
|
-
"typescript": "
|
|
63
|
+
"typescript": "~5.8.3",
|
|
64
64
|
"zod": "^3.22.4"
|
|
65
65
|
},
|
|
66
66
|
"publishConfig": {
|