@langchain/google-common 0.2.16 → 0.2.18
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/utils/gemini.cjs +47 -1
- package/dist/utils/gemini.d.ts +2 -0
- package/dist/utils/gemini.js +46 -1
- package/package.json +1 -1
package/dist/utils/gemini.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MessageGeminiSafetyHandler = exports.DefaultGeminiSafetyHandler = void 0;
|
|
4
4
|
exports.normalizeSpeechConfig = normalizeSpeechConfig;
|
|
5
|
+
exports.normalizeMessageContentComplex = normalizeMessageContentComplex;
|
|
5
6
|
exports.getGeminiAPI = getGeminiAPI;
|
|
6
7
|
exports.validateGeminiParams = validateGeminiParams;
|
|
7
8
|
exports.isModelGemini = isModelGemini;
|
|
@@ -197,6 +198,49 @@ function normalizeSpeechConfig(config) {
|
|
|
197
198
|
}
|
|
198
199
|
return ret;
|
|
199
200
|
}
|
|
201
|
+
// Compatibility layer for other well known content block types
|
|
202
|
+
function normalizeMessageContentComplex(content) {
|
|
203
|
+
return content.map((c) => {
|
|
204
|
+
// OpenAI completions `input_audio`
|
|
205
|
+
if (c.type === "input_audio" &&
|
|
206
|
+
"input_audio" in c &&
|
|
207
|
+
typeof c.input_audio === "object") {
|
|
208
|
+
const { format, data } = c.input_audio;
|
|
209
|
+
if (format === "wav") {
|
|
210
|
+
return {
|
|
211
|
+
type: "audio",
|
|
212
|
+
source_type: "base64",
|
|
213
|
+
mime_type: "audio/wav",
|
|
214
|
+
data,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// OpenAI completions `image_url`
|
|
219
|
+
if (c.type === "image_url" &&
|
|
220
|
+
"image_url" in c &&
|
|
221
|
+
typeof c.image_url === "object") {
|
|
222
|
+
const { url } = c.image_url;
|
|
223
|
+
return {
|
|
224
|
+
type: "image",
|
|
225
|
+
source_type: "url",
|
|
226
|
+
url,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
// OpenAI completions `file`
|
|
230
|
+
if (c.type === "file" &&
|
|
231
|
+
"file" in c &&
|
|
232
|
+
typeof c.file === "object" &&
|
|
233
|
+
"file_data" in c.file) {
|
|
234
|
+
const { file_data } = c.file;
|
|
235
|
+
return {
|
|
236
|
+
type: "file",
|
|
237
|
+
source_type: "base64",
|
|
238
|
+
data: file_data,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
return c;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
200
244
|
function getGeminiAPI(config) {
|
|
201
245
|
function messageContentText(content) {
|
|
202
246
|
if (content?.text && content?.text.length > 0) {
|
|
@@ -444,8 +488,10 @@ function getGeminiAPI(config) {
|
|
|
444
488
|
},
|
|
445
489
|
]
|
|
446
490
|
: content;
|
|
491
|
+
// Normalize the content to use standard format
|
|
492
|
+
const normalizedContent = normalizeMessageContentComplex(messageContent);
|
|
447
493
|
// Get all of the parts, even those that don't correctly resolve
|
|
448
|
-
const allParts = await messageContentComplexToParts(
|
|
494
|
+
const allParts = await messageContentComplexToParts(normalizedContent);
|
|
449
495
|
// Remove any invalid parts
|
|
450
496
|
const parts = allParts.reduce((acc, val) => {
|
|
451
497
|
if (val) {
|
package/dist/utils/gemini.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MessageContentComplex } from "@langchain/core/messages";
|
|
1
2
|
import { GoogleLLMResponse, GoogleAIModelParams, GenerateContentResponseData, GoogleAISafetyHandler, GoogleAIAPI, GeminiAPIConfig, GoogleSpeechConfig, GoogleSpeechConfigSimplified } from "../types.js";
|
|
2
3
|
export interface FunctionCall {
|
|
3
4
|
name: string;
|
|
@@ -40,6 +41,7 @@ export declare class MessageGeminiSafetyHandler extends DefaultGeminiSafetyHandl
|
|
|
40
41
|
handleData(response: GoogleLLMResponse, data: GenerateContentResponseData): GenerateContentResponseData;
|
|
41
42
|
}
|
|
42
43
|
export declare function normalizeSpeechConfig(config: GoogleSpeechConfig | GoogleSpeechConfigSimplified | undefined): GoogleSpeechConfig | undefined;
|
|
44
|
+
export declare function normalizeMessageContentComplex(content: MessageContentComplex[]): MessageContentComplex[];
|
|
43
45
|
export declare function getGeminiAPI(config?: GeminiAPIConfig): GoogleAIAPI;
|
|
44
46
|
export declare function validateGeminiParams(params: GoogleAIModelParams): void;
|
|
45
47
|
export declare function isModelGemini(modelName: string): boolean;
|
package/dist/utils/gemini.js
CHANGED
|
@@ -187,6 +187,49 @@ export function normalizeSpeechConfig(config) {
|
|
|
187
187
|
}
|
|
188
188
|
return ret;
|
|
189
189
|
}
|
|
190
|
+
// Compatibility layer for other well known content block types
|
|
191
|
+
export function normalizeMessageContentComplex(content) {
|
|
192
|
+
return content.map((c) => {
|
|
193
|
+
// OpenAI completions `input_audio`
|
|
194
|
+
if (c.type === "input_audio" &&
|
|
195
|
+
"input_audio" in c &&
|
|
196
|
+
typeof c.input_audio === "object") {
|
|
197
|
+
const { format, data } = c.input_audio;
|
|
198
|
+
if (format === "wav") {
|
|
199
|
+
return {
|
|
200
|
+
type: "audio",
|
|
201
|
+
source_type: "base64",
|
|
202
|
+
mime_type: "audio/wav",
|
|
203
|
+
data,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// OpenAI completions `image_url`
|
|
208
|
+
if (c.type === "image_url" &&
|
|
209
|
+
"image_url" in c &&
|
|
210
|
+
typeof c.image_url === "object") {
|
|
211
|
+
const { url } = c.image_url;
|
|
212
|
+
return {
|
|
213
|
+
type: "image",
|
|
214
|
+
source_type: "url",
|
|
215
|
+
url,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
// OpenAI completions `file`
|
|
219
|
+
if (c.type === "file" &&
|
|
220
|
+
"file" in c &&
|
|
221
|
+
typeof c.file === "object" &&
|
|
222
|
+
"file_data" in c.file) {
|
|
223
|
+
const { file_data } = c.file;
|
|
224
|
+
return {
|
|
225
|
+
type: "file",
|
|
226
|
+
source_type: "base64",
|
|
227
|
+
data: file_data,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
return c;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
190
233
|
export function getGeminiAPI(config) {
|
|
191
234
|
function messageContentText(content) {
|
|
192
235
|
if (content?.text && content?.text.length > 0) {
|
|
@@ -434,8 +477,10 @@ export function getGeminiAPI(config) {
|
|
|
434
477
|
},
|
|
435
478
|
]
|
|
436
479
|
: content;
|
|
480
|
+
// Normalize the content to use standard format
|
|
481
|
+
const normalizedContent = normalizeMessageContentComplex(messageContent);
|
|
437
482
|
// Get all of the parts, even those that don't correctly resolve
|
|
438
|
-
const allParts = await messageContentComplexToParts(
|
|
483
|
+
const allParts = await messageContentComplexToParts(normalizedContent);
|
|
439
484
|
// Remove any invalid parts
|
|
440
485
|
const parts = allParts.reduce((acc, val) => {
|
|
441
486
|
if (val) {
|