@langchain/google-common 0.2.3 → 0.2.4
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 +1 -1
- package/dist/chat_models.js +2 -2
- package/dist/utils/common.cjs +1 -1
- package/dist/utils/common.js +2 -2
- package/dist/utils/gemini.cjs +1 -1
- package/dist/utils/gemini.js +2 -2
- package/dist/utils/zod_to_gemini_parameters.cjs +5 -7
- package/dist/utils/zod_to_gemini_parameters.d.ts +2 -1
- package/dist/utils/zod_to_gemini_parameters.js +3 -5
- package/package.json +3 -3
package/dist/chat_models.cjs
CHANGED
|
@@ -369,7 +369,7 @@ class ChatGoogleBase extends chat_models_1.BaseChatModel {
|
|
|
369
369
|
let outputParser;
|
|
370
370
|
let tools;
|
|
371
371
|
if (isZodSchema(schema)) {
|
|
372
|
-
const jsonSchema = (0, zod_to_gemini_parameters_js_1.
|
|
372
|
+
const jsonSchema = (0, zod_to_gemini_parameters_js_1.schemaToGeminiParameters)(schema);
|
|
373
373
|
tools = [
|
|
374
374
|
{
|
|
375
375
|
functionDeclarations: [
|
package/dist/chat_models.js
CHANGED
|
@@ -10,7 +10,7 @@ import { AbstractGoogleLLMConnection } from "./connection.js";
|
|
|
10
10
|
import { DefaultGeminiSafetyHandler, getGeminiAPI } from "./utils/gemini.js";
|
|
11
11
|
import { ApiKeyGoogleAuth } from "./auth.js";
|
|
12
12
|
import { ensureParams } from "./utils/failed_handler.js";
|
|
13
|
-
import {
|
|
13
|
+
import { schemaToGeminiParameters } from "./utils/zod_to_gemini_parameters.js";
|
|
14
14
|
export class ChatConnection extends AbstractGoogleLLMConnection {
|
|
15
15
|
constructor(fields, caller, client, streaming) {
|
|
16
16
|
super(fields, caller, client, streaming);
|
|
@@ -365,7 +365,7 @@ export class ChatGoogleBase extends BaseChatModel {
|
|
|
365
365
|
let outputParser;
|
|
366
366
|
let tools;
|
|
367
367
|
if (isZodSchema(schema)) {
|
|
368
|
-
const jsonSchema =
|
|
368
|
+
const jsonSchema = schemaToGeminiParameters(schema);
|
|
369
369
|
tools = [
|
|
370
370
|
{
|
|
371
371
|
functionDeclarations: [
|
package/dist/utils/common.cjs
CHANGED
|
@@ -69,7 +69,7 @@ function convertToGeminiTools(tools) {
|
|
|
69
69
|
geminiTools[functionDeclarationsIndex].functionDeclarations.push(...funcs);
|
|
70
70
|
}
|
|
71
71
|
else if ((0, function_calling_1.isLangChainTool)(tool)) {
|
|
72
|
-
const jsonSchema = (0, zod_to_gemini_parameters_js_1.
|
|
72
|
+
const jsonSchema = (0, zod_to_gemini_parameters_js_1.schemaToGeminiParameters)(tool.schema);
|
|
73
73
|
geminiTools[functionDeclarationsIndex].functionDeclarations.push({
|
|
74
74
|
name: tool.name,
|
|
75
75
|
description: tool.description ?? `A function available to call.`,
|
package/dist/utils/common.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isOpenAITool } from "@langchain/core/language_models/base";
|
|
|
2
2
|
import { isLangChainTool } from "@langchain/core/utils/function_calling";
|
|
3
3
|
import { isModelGemini, isModelGemma, validateGeminiParams } from "./gemini.js";
|
|
4
4
|
import { GeminiToolAttributes, } from "../types.js";
|
|
5
|
-
import { jsonSchemaToGeminiParameters,
|
|
5
|
+
import { jsonSchemaToGeminiParameters, schemaToGeminiParameters, } from "./zod_to_gemini_parameters.js";
|
|
6
6
|
import { isModelClaude, validateClaudeParams } from "./anthropic.js";
|
|
7
7
|
export function copyAIModelParams(params, options) {
|
|
8
8
|
return copyAIModelParamsInto(params, options, {});
|
|
@@ -65,7 +65,7 @@ export function convertToGeminiTools(tools) {
|
|
|
65
65
|
geminiTools[functionDeclarationsIndex].functionDeclarations.push(...funcs);
|
|
66
66
|
}
|
|
67
67
|
else if (isLangChainTool(tool)) {
|
|
68
|
-
const jsonSchema =
|
|
68
|
+
const jsonSchema = schemaToGeminiParameters(tool.schema);
|
|
69
69
|
geminiTools[functionDeclarationsIndex].functionDeclarations.push({
|
|
70
70
|
name: tool.name,
|
|
71
71
|
description: tool.description ?? `A function available to call.`,
|
package/dist/utils/gemini.cjs
CHANGED
|
@@ -994,7 +994,7 @@ function getGeminiAPI(config) {
|
|
|
994
994
|
}
|
|
995
995
|
}
|
|
996
996
|
function structuredToolToFunctionDeclaration(tool) {
|
|
997
|
-
const jsonSchema = (0, zod_to_gemini_parameters_js_1.
|
|
997
|
+
const jsonSchema = (0, zod_to_gemini_parameters_js_1.schemaToGeminiParameters)(tool.schema);
|
|
998
998
|
return {
|
|
999
999
|
name: tool.name,
|
|
1000
1000
|
description: tool.description ?? `A function available to call.`,
|
package/dist/utils/gemini.js
CHANGED
|
@@ -5,7 +5,7 @@ import { isLangChainTool } from "@langchain/core/utils/function_calling";
|
|
|
5
5
|
import { concat } from "@langchain/core/utils/stream";
|
|
6
6
|
import { GoogleAISafetyError } from "./safety.js";
|
|
7
7
|
import { GeminiSearchToolAttributes, } from "../types.js";
|
|
8
|
-
import {
|
|
8
|
+
import { schemaToGeminiParameters } from "./zod_to_gemini_parameters.js";
|
|
9
9
|
export class DefaultGeminiSafetyHandler {
|
|
10
10
|
constructor(settings) {
|
|
11
11
|
Object.defineProperty(this, "errorFinish", {
|
|
@@ -989,7 +989,7 @@ export function getGeminiAPI(config) {
|
|
|
989
989
|
}
|
|
990
990
|
}
|
|
991
991
|
function structuredToolToFunctionDeclaration(tool) {
|
|
992
|
-
const jsonSchema =
|
|
992
|
+
const jsonSchema = schemaToGeminiParameters(tool.schema);
|
|
993
993
|
return {
|
|
994
994
|
name: tool.name,
|
|
995
995
|
description: tool.description ?? `A function available to call.`,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.jsonSchemaToGeminiParameters = exports.
|
|
4
|
+
exports.jsonSchemaToGeminiParameters = exports.schemaToGeminiParameters = exports.removeAdditionalProperties = void 0;
|
|
5
|
+
const types_1 = require("@langchain/core/utils/types");
|
|
5
6
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
6
7
|
function removeAdditionalProperties(
|
|
7
8
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -26,17 +27,14 @@ obj) {
|
|
|
26
27
|
return obj;
|
|
27
28
|
}
|
|
28
29
|
exports.removeAdditionalProperties = removeAdditionalProperties;
|
|
29
|
-
function
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
-
zodObj) {
|
|
30
|
+
function schemaToGeminiParameters(schema) {
|
|
32
31
|
// Gemini doesn't accept either the $schema or additionalProperties
|
|
33
32
|
// attributes, so we need to explicitly remove them.
|
|
34
|
-
|
|
35
|
-
const jsonSchema = removeAdditionalProperties((0, zod_to_json_schema_1.zodToJsonSchema)(zodObj));
|
|
33
|
+
const jsonSchema = removeAdditionalProperties((0, types_1.isZodSchema)(schema) ? (0, zod_to_json_schema_1.zodToJsonSchema)(schema) : schema);
|
|
36
34
|
const { $schema, ...rest } = jsonSchema;
|
|
37
35
|
return rest;
|
|
38
36
|
}
|
|
39
|
-
exports.
|
|
37
|
+
exports.schemaToGeminiParameters = schemaToGeminiParameters;
|
|
40
38
|
function jsonSchemaToGeminiParameters(
|
|
41
39
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
40
|
schema) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
|
+
import { type JsonSchema7Type } from "zod-to-json-schema";
|
|
2
3
|
import { GeminiFunctionSchema, GeminiJsonSchema } from "../types.js";
|
|
3
4
|
export declare function removeAdditionalProperties(obj: Record<string, any>): GeminiJsonSchema;
|
|
4
|
-
export declare function
|
|
5
|
+
export declare function schemaToGeminiParameters<RunOutput extends Record<string, any> = Record<string, any>>(schema: z.ZodType<RunOutput> | z.ZodEffects<z.ZodType<RunOutput>> | JsonSchema7Type): GeminiFunctionSchema;
|
|
5
6
|
export declare function jsonSchemaToGeminiParameters(schema: Record<string, any>): GeminiFunctionSchema;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { isZodSchema } from "@langchain/core/utils/types";
|
|
2
3
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
4
|
export function removeAdditionalProperties(
|
|
4
5
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -22,13 +23,10 @@ obj) {
|
|
|
22
23
|
}
|
|
23
24
|
return obj;
|
|
24
25
|
}
|
|
25
|
-
export function
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
-
zodObj) {
|
|
26
|
+
export function schemaToGeminiParameters(schema) {
|
|
28
27
|
// Gemini doesn't accept either the $schema or additionalProperties
|
|
29
28
|
// attributes, so we need to explicitly remove them.
|
|
30
|
-
|
|
31
|
-
const jsonSchema = removeAdditionalProperties(zodToJsonSchema(zodObj));
|
|
29
|
+
const jsonSchema = removeAdditionalProperties(isZodSchema(schema) ? zodToJsonSchema(schema) : schema);
|
|
32
30
|
const { $schema, ...rest } = jsonSchema;
|
|
33
31
|
return rest;
|
|
34
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/google-common",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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": "
|
|
43
|
+
"@langchain/core": "0.3.44",
|
|
44
44
|
"@langchain/scripts": ">=0.1.0 <0.2.0",
|
|
45
45
|
"@swc/core": "^1.3.90",
|
|
46
46
|
"@swc/jest": "^0.2.29",
|
|
@@ -138,4 +138,4 @@
|
|
|
138
138
|
"experimental/utils/media_core.d.ts",
|
|
139
139
|
"experimental/utils/media_core.d.cts"
|
|
140
140
|
]
|
|
141
|
-
}
|
|
141
|
+
}
|