@langchain/google-genai 0.2.2 → 0.2.3

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.
@@ -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.zodToGenerativeAIParameters)(schema);
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, types_1.isZodSchema)(schema)
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
  });
@@ -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 { zodToGenerativeAIParameters, removeAdditionalProperties, } from "./utils/zod_to_genai_parameters.js";
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 = zodToGenerativeAIParameters(schema);
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 = isZodSchema(schema)
807
- ? zodToGenerativeAIParameters(schema)
808
- : removeAdditionalProperties(schema);
806
+ const jsonSchema = schemaToGenerativeAIParameters(schema);
809
807
  llm = this.bind({
810
808
  responseSchema: jsonSchema,
811
809
  });
@@ -389,7 +389,7 @@ function convertToGenerativeAITools(tools) {
389
389
  {
390
390
  functionDeclarations: tools.map((tool) => {
391
391
  if ((0, function_calling_1.isLangChainTool)(tool)) {
392
- const jsonSchema = (0, zod_to_genai_parameters_js_1.zodToGenerativeAIParameters)(tool.schema);
392
+ const jsonSchema = (0, zod_to_genai_parameters_js_1.schemaToGenerativeAIParameters)(tool.schema);
393
393
  if (jsonSchema.type === "object" &&
394
394
  "properties" in jsonSchema &&
395
395
  Object.keys(jsonSchema.properties).length === 0) {
@@ -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, zodToGenerativeAIParameters, } from "./zod_to_genai_parameters.js";
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)) {
@@ -380,7 +380,7 @@ export function convertToGenerativeAITools(tools) {
380
380
  {
381
381
  functionDeclarations: tools.map((tool) => {
382
382
  if (isLangChainTool(tool)) {
383
- const jsonSchema = zodToGenerativeAIParameters(tool.schema);
383
+ const jsonSchema = schemaToGenerativeAIParameters(tool.schema);
384
384
  if (jsonSchema.type === "object" &&
385
385
  "properties" in jsonSchema &&
386
386
  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.zodToGenerativeAIParameters = exports.removeAdditionalProperties = void 0;
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 zodToGenerativeAIParameters(
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)(zodObj));
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.zodToGenerativeAIParameters = zodToGenerativeAIParameters;
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 zodToGenerativeAIParameters(zodObj: z.ZodType<any>): GenerativeAIFunctionDeclarationSchema;
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 zodToGenerativeAIParameters(
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(zodObj));
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.2",
3
+ "version": "0.2.3",
4
4
  "description": "Google Generative AI integration for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@jest/globals": "^29.5.0",
47
- "@langchain/core": "workspace:*",
47
+ "@langchain/core": "0.3.44",
48
48
  "@langchain/scripts": ">=0.1.0 <0.2.0",
49
49
  "@langchain/standard-tests": "0.0.0",
50
50
  "@swc/core": "^1.3.90",
@@ -92,4 +92,4 @@
92
92
  "index.d.ts",
93
93
  "index.d.cts"
94
94
  ]
95
- }
95
+ }