@langchain/google-common 0.2.5 → 0.2.6
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/connection.cjs +17 -3
- package/dist/connection.d.ts +4 -1
- package/dist/connection.js +17 -3
- package/dist/experimental/media.cjs +5 -14
- package/dist/experimental/media.d.ts +2 -2
- package/dist/experimental/media.js +5 -14
- package/dist/utils/gemini.cjs +14 -7
- package/dist/utils/gemini.js +14 -7
- package/package.json +2 -2
package/dist/connection.cjs
CHANGED
|
@@ -114,17 +114,17 @@ class GoogleHostConnection extends GoogleConnection {
|
|
|
114
114
|
writable: true,
|
|
115
115
|
value: void 0
|
|
116
116
|
});
|
|
117
|
-
Object.defineProperty(this, "
|
|
117
|
+
Object.defineProperty(this, "_apiVersion", {
|
|
118
118
|
enumerable: true,
|
|
119
119
|
configurable: true,
|
|
120
120
|
writable: true,
|
|
121
|
-
value:
|
|
121
|
+
value: void 0
|
|
122
122
|
});
|
|
123
123
|
this.caller = caller;
|
|
124
124
|
this.platformType = fields?.platformType;
|
|
125
125
|
this._endpoint = fields?.endpoint;
|
|
126
126
|
this._location = fields?.location;
|
|
127
|
-
this.
|
|
127
|
+
this._apiVersion = fields?.apiVersion;
|
|
128
128
|
this.client = client;
|
|
129
129
|
}
|
|
130
130
|
get platform() {
|
|
@@ -133,6 +133,12 @@ class GoogleHostConnection extends GoogleConnection {
|
|
|
133
133
|
get computedPlatformType() {
|
|
134
134
|
return "gcp";
|
|
135
135
|
}
|
|
136
|
+
get computedApiVersion() {
|
|
137
|
+
return "v1";
|
|
138
|
+
}
|
|
139
|
+
get apiVersion() {
|
|
140
|
+
return this._apiVersion ?? this.computedApiVersion;
|
|
141
|
+
}
|
|
136
142
|
get location() {
|
|
137
143
|
return this._location ?? this.computedLocation;
|
|
138
144
|
}
|
|
@@ -238,6 +244,14 @@ class GoogleAIConnection extends GoogleHostConnection {
|
|
|
238
244
|
return "gcp";
|
|
239
245
|
}
|
|
240
246
|
}
|
|
247
|
+
get computedApiVersion() {
|
|
248
|
+
switch (this.platform) {
|
|
249
|
+
case "gai":
|
|
250
|
+
return "v1beta";
|
|
251
|
+
default:
|
|
252
|
+
return "v1";
|
|
253
|
+
}
|
|
254
|
+
}
|
|
241
255
|
get computedLocation() {
|
|
242
256
|
switch (this.apiName) {
|
|
243
257
|
case "google":
|
package/dist/connection.d.ts
CHANGED
|
@@ -25,10 +25,12 @@ export declare abstract class GoogleHostConnection<CallOptions extends AsyncCall
|
|
|
25
25
|
platformType: GooglePlatformType | undefined;
|
|
26
26
|
_endpoint: string | undefined;
|
|
27
27
|
_location: string | undefined;
|
|
28
|
-
|
|
28
|
+
_apiVersion: string | undefined;
|
|
29
29
|
constructor(fields: GoogleConnectionParams<AuthOptions> | undefined, caller: AsyncCaller, client: GoogleAbstractedClient, streaming?: boolean);
|
|
30
30
|
get platform(): GooglePlatformType;
|
|
31
31
|
get computedPlatformType(): GooglePlatformType;
|
|
32
|
+
get computedApiVersion(): string;
|
|
33
|
+
get apiVersion(): string;
|
|
32
34
|
get location(): string;
|
|
33
35
|
get computedLocation(): string;
|
|
34
36
|
get endpoint(): string;
|
|
@@ -52,6 +54,7 @@ export declare abstract class GoogleAIConnection<CallOptions extends AsyncCaller
|
|
|
52
54
|
get api(): GoogleAIAPI;
|
|
53
55
|
get isApiKey(): boolean;
|
|
54
56
|
get computedPlatformType(): GooglePlatformType;
|
|
57
|
+
get computedApiVersion(): string;
|
|
55
58
|
get computedLocation(): string;
|
|
56
59
|
abstract buildUrlMethod(): Promise<string>;
|
|
57
60
|
buildUrlGenerativeLanguage(): Promise<string>;
|
package/dist/connection.js
CHANGED
|
@@ -110,17 +110,17 @@ export class GoogleHostConnection extends GoogleConnection {
|
|
|
110
110
|
writable: true,
|
|
111
111
|
value: void 0
|
|
112
112
|
});
|
|
113
|
-
Object.defineProperty(this, "
|
|
113
|
+
Object.defineProperty(this, "_apiVersion", {
|
|
114
114
|
enumerable: true,
|
|
115
115
|
configurable: true,
|
|
116
116
|
writable: true,
|
|
117
|
-
value:
|
|
117
|
+
value: void 0
|
|
118
118
|
});
|
|
119
119
|
this.caller = caller;
|
|
120
120
|
this.platformType = fields?.platformType;
|
|
121
121
|
this._endpoint = fields?.endpoint;
|
|
122
122
|
this._location = fields?.location;
|
|
123
|
-
this.
|
|
123
|
+
this._apiVersion = fields?.apiVersion;
|
|
124
124
|
this.client = client;
|
|
125
125
|
}
|
|
126
126
|
get platform() {
|
|
@@ -129,6 +129,12 @@ export class GoogleHostConnection extends GoogleConnection {
|
|
|
129
129
|
get computedPlatformType() {
|
|
130
130
|
return "gcp";
|
|
131
131
|
}
|
|
132
|
+
get computedApiVersion() {
|
|
133
|
+
return "v1";
|
|
134
|
+
}
|
|
135
|
+
get apiVersion() {
|
|
136
|
+
return this._apiVersion ?? this.computedApiVersion;
|
|
137
|
+
}
|
|
132
138
|
get location() {
|
|
133
139
|
return this._location ?? this.computedLocation;
|
|
134
140
|
}
|
|
@@ -232,6 +238,14 @@ export class GoogleAIConnection extends GoogleHostConnection {
|
|
|
232
238
|
return "gcp";
|
|
233
239
|
}
|
|
234
240
|
}
|
|
241
|
+
get computedApiVersion() {
|
|
242
|
+
switch (this.platform) {
|
|
243
|
+
case "gai":
|
|
244
|
+
return "v1beta";
|
|
245
|
+
default:
|
|
246
|
+
return "v1";
|
|
247
|
+
}
|
|
248
|
+
}
|
|
235
249
|
get computedLocation() {
|
|
236
250
|
switch (this.apiName) {
|
|
237
251
|
case "google":
|
|
@@ -328,14 +328,8 @@ class AIStudioMediaBlob extends media_core_js_1.MediaBlob {
|
|
|
328
328
|
}
|
|
329
329
|
exports.AIStudioMediaBlob = AIStudioMediaBlob;
|
|
330
330
|
class AIStudioFileUploadConnection extends GoogleMultipartUploadConnection {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
Object.defineProperty(this, "apiVersion", {
|
|
334
|
-
enumerable: true,
|
|
335
|
-
configurable: true,
|
|
336
|
-
writable: true,
|
|
337
|
-
value: "v1beta"
|
|
338
|
-
});
|
|
331
|
+
get computedApiVersion() {
|
|
332
|
+
return "v1beta";
|
|
339
333
|
}
|
|
340
334
|
async buildUrl() {
|
|
341
335
|
return `https://generativelanguage.googleapis.com/upload/${this.apiVersion}/files`;
|
|
@@ -357,15 +351,12 @@ class AIStudioFileDownloadConnection extends GoogleDownloadConnection {
|
|
|
357
351
|
writable: true,
|
|
358
352
|
value: void 0
|
|
359
353
|
});
|
|
360
|
-
Object.defineProperty(this, "apiVersion", {
|
|
361
|
-
enumerable: true,
|
|
362
|
-
configurable: true,
|
|
363
|
-
writable: true,
|
|
364
|
-
value: "v1beta"
|
|
365
|
-
});
|
|
366
354
|
this.method = fields.method;
|
|
367
355
|
this.name = fields.name;
|
|
368
356
|
}
|
|
357
|
+
get computedApiVersion() {
|
|
358
|
+
return "v1beta";
|
|
359
|
+
}
|
|
369
360
|
buildMethod() {
|
|
370
361
|
return this.method;
|
|
371
362
|
}
|
|
@@ -166,7 +166,7 @@ export interface AIStudioFileConnectionParams {
|
|
|
166
166
|
export interface AIStudioFileUploadConnectionParams<AuthOptions> extends GoogleUploadConnectionParams<AuthOptions>, AIStudioFileConnectionParams {
|
|
167
167
|
}
|
|
168
168
|
export declare class AIStudioFileUploadConnection<AuthOptions> extends GoogleMultipartUploadConnection<AsyncCallerCallOptions, AIStudioFileSaveResponse, AuthOptions> {
|
|
169
|
-
|
|
169
|
+
get computedApiVersion(): string;
|
|
170
170
|
buildUrl(): Promise<string>;
|
|
171
171
|
}
|
|
172
172
|
export interface AIStudioFileDownloadConnectionParams<AuthOptions> extends AIStudioFileConnectionParams, GoogleConnectionParams<AuthOptions> {
|
|
@@ -176,8 +176,8 @@ export interface AIStudioFileDownloadConnectionParams<AuthOptions> extends AIStu
|
|
|
176
176
|
export declare class AIStudioFileDownloadConnection<ResponseType extends GoogleResponse, AuthOptions> extends GoogleDownloadConnection<AsyncCallerCallOptions, ResponseType, AuthOptions> {
|
|
177
177
|
method: GoogleAbstractedClientOpsMethod;
|
|
178
178
|
name: string;
|
|
179
|
-
apiVersion: string;
|
|
180
179
|
constructor(fields: AIStudioFileDownloadConnectionParams<AuthOptions>, caller: AsyncCaller, client: GoogleAbstractedClient);
|
|
180
|
+
get computedApiVersion(): string;
|
|
181
181
|
buildMethod(): GoogleAbstractedClientOpsMethod;
|
|
182
182
|
buildUrl(): Promise<string>;
|
|
183
183
|
}
|
|
@@ -315,14 +315,8 @@ export class AIStudioMediaBlob extends MediaBlob {
|
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
export class AIStudioFileUploadConnection extends GoogleMultipartUploadConnection {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
Object.defineProperty(this, "apiVersion", {
|
|
321
|
-
enumerable: true,
|
|
322
|
-
configurable: true,
|
|
323
|
-
writable: true,
|
|
324
|
-
value: "v1beta"
|
|
325
|
-
});
|
|
318
|
+
get computedApiVersion() {
|
|
319
|
+
return "v1beta";
|
|
326
320
|
}
|
|
327
321
|
async buildUrl() {
|
|
328
322
|
return `https://generativelanguage.googleapis.com/upload/${this.apiVersion}/files`;
|
|
@@ -343,15 +337,12 @@ export class AIStudioFileDownloadConnection extends GoogleDownloadConnection {
|
|
|
343
337
|
writable: true,
|
|
344
338
|
value: void 0
|
|
345
339
|
});
|
|
346
|
-
Object.defineProperty(this, "apiVersion", {
|
|
347
|
-
enumerable: true,
|
|
348
|
-
configurable: true,
|
|
349
|
-
writable: true,
|
|
350
|
-
value: "v1beta"
|
|
351
|
-
});
|
|
352
340
|
this.method = fields.method;
|
|
353
341
|
this.name = fields.name;
|
|
354
342
|
}
|
|
343
|
+
get computedApiVersion() {
|
|
344
|
+
return "v1beta";
|
|
345
|
+
}
|
|
355
346
|
buildMethod() {
|
|
356
347
|
return this.method;
|
|
357
348
|
}
|
package/dist/utils/gemini.cjs
CHANGED
|
@@ -651,12 +651,9 @@ function getGeminiAPI(config) {
|
|
|
651
651
|
if (!data) {
|
|
652
652
|
return {};
|
|
653
653
|
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
candidates_token_count: data.usageMetadata?.candidatesTokenCount,
|
|
658
|
-
total_token_count: data.usageMetadata?.totalTokenCount,
|
|
659
|
-
},
|
|
654
|
+
const finish_reason = data.candidates[0]?.finishReason;
|
|
655
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
656
|
+
const ret = {
|
|
660
657
|
safety_ratings: data.candidates[0]?.safetyRatings?.map((rating) => ({
|
|
661
658
|
category: rating.category,
|
|
662
659
|
probability: rating.probability,
|
|
@@ -666,11 +663,21 @@ function getGeminiAPI(config) {
|
|
|
666
663
|
})),
|
|
667
664
|
citation_metadata: data.candidates[0]?.citationMetadata,
|
|
668
665
|
grounding_metadata: data.candidates[0]?.groundingMetadata,
|
|
669
|
-
finish_reason
|
|
666
|
+
finish_reason,
|
|
670
667
|
finish_message: data.candidates[0]?.finishMessage,
|
|
671
668
|
avgLogprobs: data.candidates[0]?.avgLogprobs,
|
|
672
669
|
logprobs: candidateToLogprobs(data.candidates[0]),
|
|
673
670
|
};
|
|
671
|
+
// Only add the usage_metadata on the last chunk
|
|
672
|
+
// sent while streaming (see issue 8102).
|
|
673
|
+
if (typeof finish_reason === "string") {
|
|
674
|
+
ret.usage_metadata = {
|
|
675
|
+
prompt_token_count: data.usageMetadata?.promptTokenCount,
|
|
676
|
+
candidates_token_count: data.usageMetadata?.candidatesTokenCount,
|
|
677
|
+
total_token_count: data.usageMetadata?.totalTokenCount,
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
return ret;
|
|
674
681
|
}
|
|
675
682
|
function responseToChatGeneration(response) {
|
|
676
683
|
return new outputs_1.ChatGenerationChunk({
|
package/dist/utils/gemini.js
CHANGED
|
@@ -646,12 +646,9 @@ export function getGeminiAPI(config) {
|
|
|
646
646
|
if (!data) {
|
|
647
647
|
return {};
|
|
648
648
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
candidates_token_count: data.usageMetadata?.candidatesTokenCount,
|
|
653
|
-
total_token_count: data.usageMetadata?.totalTokenCount,
|
|
654
|
-
},
|
|
649
|
+
const finish_reason = data.candidates[0]?.finishReason;
|
|
650
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
651
|
+
const ret = {
|
|
655
652
|
safety_ratings: data.candidates[0]?.safetyRatings?.map((rating) => ({
|
|
656
653
|
category: rating.category,
|
|
657
654
|
probability: rating.probability,
|
|
@@ -661,11 +658,21 @@ export function getGeminiAPI(config) {
|
|
|
661
658
|
})),
|
|
662
659
|
citation_metadata: data.candidates[0]?.citationMetadata,
|
|
663
660
|
grounding_metadata: data.candidates[0]?.groundingMetadata,
|
|
664
|
-
finish_reason
|
|
661
|
+
finish_reason,
|
|
665
662
|
finish_message: data.candidates[0]?.finishMessage,
|
|
666
663
|
avgLogprobs: data.candidates[0]?.avgLogprobs,
|
|
667
664
|
logprobs: candidateToLogprobs(data.candidates[0]),
|
|
668
665
|
};
|
|
666
|
+
// Only add the usage_metadata on the last chunk
|
|
667
|
+
// sent while streaming (see issue 8102).
|
|
668
|
+
if (typeof finish_reason === "string") {
|
|
669
|
+
ret.usage_metadata = {
|
|
670
|
+
prompt_token_count: data.usageMetadata?.promptTokenCount,
|
|
671
|
+
candidates_token_count: data.usageMetadata?.candidatesTokenCount,
|
|
672
|
+
total_token_count: data.usageMetadata?.totalTokenCount,
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
return ret;
|
|
669
676
|
}
|
|
670
677
|
function responseToChatGeneration(response) {
|
|
671
678
|
return new ChatGenerationChunk({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/google-common",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Core types and classes for Google services.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@jest/globals": "^29.5.0",
|
|
43
|
-
"@langchain/core": "0.3.
|
|
43
|
+
"@langchain/core": "0.3.53",
|
|
44
44
|
"@langchain/scripts": ">=0.1.0 <0.2.0",
|
|
45
45
|
"@swc/core": "^1.3.90",
|
|
46
46
|
"@swc/jest": "^0.2.29",
|