@langchain/google-genai 0.2.2 → 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 +2 -4
- package/dist/chat_models.js +3 -5
- package/dist/utils/common.cjs +2 -1
- package/dist/utils/common.js +3 -2
- package/dist/utils/zod_to_genai_parameters.cjs +5 -6
- package/dist/utils/zod_to_genai_parameters.d.ts +2 -1
- package/dist/utils/zod_to_genai_parameters.js +3 -4
- package/package.json +2 -2
package/dist/chat_models.cjs
CHANGED
|
@@ -756,7 +756,7 @@ class ChatGoogleGenerativeAI extends chat_models_1.BaseChatModel {
|
|
|
756
756
|
let functionName = name ?? "extract";
|
|
757
757
|
let tools;
|
|
758
758
|
if ((0, types_1.isZodSchema)(schema)) {
|
|
759
|
-
const jsonSchema = (0, zod_to_genai_parameters_js_1.
|
|
759
|
+
const jsonSchema = (0, zod_to_genai_parameters_js_1.schemaToGenerativeAIParameters)(schema);
|
|
760
760
|
tools = [
|
|
761
761
|
{
|
|
762
762
|
functionDeclarations: [
|
|
@@ -806,9 +806,7 @@ class ChatGoogleGenerativeAI extends chat_models_1.BaseChatModel {
|
|
|
806
806
|
});
|
|
807
807
|
}
|
|
808
808
|
else {
|
|
809
|
-
const jsonSchema = (0,
|
|
810
|
-
? (0, zod_to_genai_parameters_js_1.zodToGenerativeAIParameters)(schema)
|
|
811
|
-
: (0, zod_to_genai_parameters_js_1.removeAdditionalProperties)(schema);
|
|
809
|
+
const jsonSchema = (0, zod_to_genai_parameters_js_1.schemaToGenerativeAIParameters)(schema);
|
|
812
810
|
llm = this.bind({
|
|
813
811
|
responseSchema: jsonSchema,
|
|
814
812
|
});
|
package/dist/chat_models.js
CHANGED
|
@@ -4,7 +4,7 @@ import { BaseChatModel, } from "@langchain/core/language_models/chat_models";
|
|
|
4
4
|
import { RunnablePassthrough, RunnableSequence, } from "@langchain/core/runnables";
|
|
5
5
|
import { isZodSchema } from "@langchain/core/utils/types";
|
|
6
6
|
import { JsonOutputParser, } from "@langchain/core/output_parsers";
|
|
7
|
-
import {
|
|
7
|
+
import { schemaToGenerativeAIParameters, removeAdditionalProperties, } from "./utils/zod_to_genai_parameters.js";
|
|
8
8
|
import { convertBaseMessagesToContent, convertResponseContentToChatGenerationChunk, mapGenerateContentResultToChatResult, } from "./utils/common.js";
|
|
9
9
|
import { GoogleGenerativeAIToolsOutputParser } from "./output_parsers.js";
|
|
10
10
|
import { convertToolsToGenAI } from "./utils/tools.js";
|
|
@@ -753,7 +753,7 @@ export class ChatGoogleGenerativeAI extends BaseChatModel {
|
|
|
753
753
|
let functionName = name ?? "extract";
|
|
754
754
|
let tools;
|
|
755
755
|
if (isZodSchema(schema)) {
|
|
756
|
-
const jsonSchema =
|
|
756
|
+
const jsonSchema = schemaToGenerativeAIParameters(schema);
|
|
757
757
|
tools = [
|
|
758
758
|
{
|
|
759
759
|
functionDeclarations: [
|
|
@@ -803,9 +803,7 @@ export class ChatGoogleGenerativeAI extends BaseChatModel {
|
|
|
803
803
|
});
|
|
804
804
|
}
|
|
805
805
|
else {
|
|
806
|
-
const jsonSchema =
|
|
807
|
-
? zodToGenerativeAIParameters(schema)
|
|
808
|
-
: removeAdditionalProperties(schema);
|
|
806
|
+
const jsonSchema = schemaToGenerativeAIParameters(schema);
|
|
809
807
|
llm = this.bind({
|
|
810
808
|
responseSchema: jsonSchema,
|
|
811
809
|
});
|
package/dist/utils/common.cjs
CHANGED
|
@@ -30,6 +30,7 @@ function convertAuthorToRole(author) {
|
|
|
30
30
|
* Note: Gemini currently is not supporting system messages
|
|
31
31
|
* we will convert them to human messages and merge with following
|
|
32
32
|
* */
|
|
33
|
+
case "supervisor":
|
|
33
34
|
case "ai":
|
|
34
35
|
case "model": // getMessageAuthor returns message.name. code ex.: return message.name ?? type;
|
|
35
36
|
return "model";
|
|
@@ -389,7 +390,7 @@ function convertToGenerativeAITools(tools) {
|
|
|
389
390
|
{
|
|
390
391
|
functionDeclarations: tools.map((tool) => {
|
|
391
392
|
if ((0, function_calling_1.isLangChainTool)(tool)) {
|
|
392
|
-
const jsonSchema = (0, zod_to_genai_parameters_js_1.
|
|
393
|
+
const jsonSchema = (0, zod_to_genai_parameters_js_1.schemaToGenerativeAIParameters)(tool.schema);
|
|
393
394
|
if (jsonSchema.type === "object" &&
|
|
394
395
|
"properties" in jsonSchema &&
|
|
395
396
|
Object.keys(jsonSchema.properties).length === 0) {
|
package/dist/utils/common.js
CHANGED
|
@@ -3,7 +3,7 @@ import { ChatGenerationChunk, } from "@langchain/core/outputs";
|
|
|
3
3
|
import { isLangChainTool } from "@langchain/core/utils/function_calling";
|
|
4
4
|
import { isOpenAITool } from "@langchain/core/language_models/base";
|
|
5
5
|
import { v4 as uuidv4 } from "uuid";
|
|
6
|
-
import { jsonSchemaToGeminiParameters,
|
|
6
|
+
import { jsonSchemaToGeminiParameters, schemaToGenerativeAIParameters, } from "./zod_to_genai_parameters.js";
|
|
7
7
|
export function getMessageAuthor(message) {
|
|
8
8
|
const type = message._getType();
|
|
9
9
|
if (ChatMessage.isInstance(message)) {
|
|
@@ -26,6 +26,7 @@ export function convertAuthorToRole(author) {
|
|
|
26
26
|
* Note: Gemini currently is not supporting system messages
|
|
27
27
|
* we will convert them to human messages and merge with following
|
|
28
28
|
* */
|
|
29
|
+
case "supervisor":
|
|
29
30
|
case "ai":
|
|
30
31
|
case "model": // getMessageAuthor returns message.name. code ex.: return message.name ?? type;
|
|
31
32
|
return "model";
|
|
@@ -380,7 +381,7 @@ export function convertToGenerativeAITools(tools) {
|
|
|
380
381
|
{
|
|
381
382
|
functionDeclarations: tools.map((tool) => {
|
|
382
383
|
if (isLangChainTool(tool)) {
|
|
383
|
-
const jsonSchema =
|
|
384
|
+
const jsonSchema = schemaToGenerativeAIParameters(tool.schema);
|
|
384
385
|
if (jsonSchema.type === "object" &&
|
|
385
386
|
"properties" in jsonSchema &&
|
|
386
387
|
Object.keys(jsonSchema.properties).length === 0) {
|
|
@@ -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.schemaToGenerativeAIParameters = 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
|
|
@@ -32,16 +33,14 @@ obj) {
|
|
|
32
33
|
return obj;
|
|
33
34
|
}
|
|
34
35
|
exports.removeAdditionalProperties = removeAdditionalProperties;
|
|
35
|
-
function
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
zodObj) {
|
|
36
|
+
function schemaToGenerativeAIParameters(schema) {
|
|
38
37
|
// GenerativeAI doesn't accept either the $schema or additionalProperties
|
|
39
38
|
// attributes, so we need to explicitly remove them.
|
|
40
|
-
const jsonSchema = removeAdditionalProperties((0, zod_to_json_schema_1.zodToJsonSchema)(
|
|
39
|
+
const jsonSchema = removeAdditionalProperties((0, types_1.isZodSchema)(schema) ? (0, zod_to_json_schema_1.zodToJsonSchema)(schema) : schema);
|
|
41
40
|
const { $schema, ...rest } = jsonSchema;
|
|
42
41
|
return rest;
|
|
43
42
|
}
|
|
44
|
-
exports.
|
|
43
|
+
exports.schemaToGenerativeAIParameters = schemaToGenerativeAIParameters;
|
|
45
44
|
function jsonSchemaToGeminiParameters(
|
|
46
45
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
46
|
schema) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
2
|
import { type FunctionDeclarationSchema as GenerativeAIFunctionDeclarationSchema, type SchemaType as FunctionDeclarationSchemaType } from "@google/generative-ai";
|
|
3
|
+
import { type JsonSchema7Type } from "zod-to-json-schema";
|
|
3
4
|
export interface GenerativeAIJsonSchema extends Record<string, unknown> {
|
|
4
5
|
properties?: Record<string, GenerativeAIJsonSchema>;
|
|
5
6
|
type: FunctionDeclarationSchemaType;
|
|
@@ -9,5 +10,5 @@ export interface GenerativeAIJsonSchemaDirty extends GenerativeAIJsonSchema {
|
|
|
9
10
|
additionalProperties?: boolean;
|
|
10
11
|
}
|
|
11
12
|
export declare function removeAdditionalProperties(obj: Record<string, any>): GenerativeAIJsonSchema;
|
|
12
|
-
export declare function
|
|
13
|
+
export declare function schemaToGenerativeAIParameters<RunOutput extends Record<string, any> = Record<string, any>>(schema: z.ZodType<RunOutput> | z.ZodEffects<z.ZodType<RunOutput>> | JsonSchema7Type): GenerativeAIFunctionDeclarationSchema;
|
|
13
14
|
export declare function jsonSchemaToGeminiParameters(schema: Record<string, any>): GenerativeAIFunctionDeclarationSchema;
|
|
@@ -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
|
|
@@ -28,12 +29,10 @@ obj) {
|
|
|
28
29
|
}
|
|
29
30
|
return obj;
|
|
30
31
|
}
|
|
31
|
-
export function
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
-
zodObj) {
|
|
32
|
+
export function schemaToGenerativeAIParameters(schema) {
|
|
34
33
|
// GenerativeAI doesn't accept either the $schema or additionalProperties
|
|
35
34
|
// attributes, so we need to explicitly remove them.
|
|
36
|
-
const jsonSchema = removeAdditionalProperties(zodToJsonSchema(
|
|
35
|
+
const jsonSchema = removeAdditionalProperties(isZodSchema(schema) ? zodToJsonSchema(schema) : schema);
|
|
37
36
|
const { $schema, ...rest } = jsonSchema;
|
|
38
37
|
return rest;
|
|
39
38
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/google-genai",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Google Generative AI integration for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"jest": "^29.5.0",
|
|
65
65
|
"jest-environment-node": "^29.6.4",
|
|
66
66
|
"prettier": "^2.8.3",
|
|
67
|
-
"release-it": "^
|
|
67
|
+
"release-it": "^18.1.2",
|
|
68
68
|
"rollup": "^4.5.2",
|
|
69
69
|
"ts-jest": "^29.1.0",
|
|
70
70
|
"typescript": "<5.2.0",
|