@langchain/google-genai
Advanced tools
Comparing version 0.0.20 to 0.0.21
@@ -6,3 +6,3 @@ import { FunctionDeclarationsTool as GoogleGenerativeAIFunctionDeclarationsTool, GenerateContentRequest, SafetySetting, Part as GenerativeAIPart } from "@google/generative-ai"; | ||
import { BaseChatModel, LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models"; | ||
import { BaseLanguageModelCallOptions, BaseLanguageModelInput, StructuredOutputMethodOptions } from "@langchain/core/language_models/base"; | ||
import { BaseLanguageModelCallOptions, BaseLanguageModelInput, StructuredOutputMethodOptions, ToolDefinition } from "@langchain/core/language_models/base"; | ||
import { StructuredToolInterface } from "@langchain/core/tools"; | ||
@@ -164,3 +164,3 @@ import { Runnable } from "@langchain/core/runnables"; | ||
_llmType(): string; | ||
bindTools(tools: (StructuredToolInterface | Record<string, unknown>)[], kwargs?: Partial<GoogleGenerativeAIChatCallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, GoogleGenerativeAIChatCallOptions>; | ||
bindTools(tools: (StructuredToolInterface | Record<string, unknown> | ToolDefinition)[], kwargs?: Partial<GoogleGenerativeAIChatCallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, GoogleGenerativeAIChatCallOptions>; | ||
invocationParams(options?: this["ParsedCallOptions"]): Omit<GenerateContentRequest, "contents">; | ||
@@ -167,0 +167,0 @@ _generate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>; |
@@ -5,2 +5,3 @@ import { EnhancedGenerateContentResponse, Content, Part, type FunctionDeclarationsTool as GoogleGenerativeAIFunctionDeclarationsTool, POSSIBLE_ROLES } from "@google/generative-ai"; | ||
import { StructuredToolInterface } from "@langchain/core/tools"; | ||
import { ToolDefinition } from "@langchain/core/language_models/base"; | ||
export declare function getMessageAuthor(message: BaseMessage): string; | ||
@@ -23,2 +24,2 @@ /** | ||
}): ChatGenerationChunk | null; | ||
export declare function convertToGenerativeAITools(structuredTools: (StructuredToolInterface | Record<string, unknown>)[]): GoogleGenerativeAIFunctionDeclarationsTool[]; | ||
export declare function convertToGenerativeAITools(structuredTools: (StructuredToolInterface | Record<string, unknown> | ToolDefinition)[]): GoogleGenerativeAIFunctionDeclarationsTool[]; |
import { AIMessage, AIMessageChunk, ChatMessage, isBaseMessage, } from "@langchain/core/messages"; | ||
import { ChatGenerationChunk, } from "@langchain/core/outputs"; | ||
import { isStructuredTool } from "@langchain/core/utils/function_calling"; | ||
import { zodToGenerativeAIParameters } from "./zod_to_genai_parameters.js"; | ||
import { isOpenAITool, } from "@langchain/core/language_models/base"; | ||
import { jsonSchemaToGeminiParameters, zodToGenerativeAIParameters, } from "./zod_to_genai_parameters.js"; | ||
export function getMessageAuthor(message) { | ||
@@ -251,2 +252,10 @@ const type = message._getType(); | ||
} | ||
if (isOpenAITool(structuredTool)) { | ||
return { | ||
name: structuredTool.function.name, | ||
description: structuredTool.function.description ?? | ||
`A function available to call.`, | ||
parameters: jsonSchemaToGeminiParameters(structuredTool.function.parameters), | ||
}; | ||
} | ||
return structuredTool; | ||
@@ -253,0 +262,0 @@ }), |
@@ -13,1 +13,2 @@ import type { z } from "zod"; | ||
export declare function zodToGenerativeAIParameters(zodObj: z.ZodType<any>): GenerativeAIFunctionDeclarationSchema; | ||
export declare function jsonSchemaToGeminiParameters(schema: Record<string, any>): GenerativeAIFunctionDeclarationSchema; |
@@ -35,1 +35,11 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
} | ||
export function jsonSchemaToGeminiParameters( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
schema) { | ||
// Gemini doesn't accept either the $schema or additionalProperties | ||
// attributes, so we need to explicitly remove them. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const jsonSchema = removeAdditionalProperties(schema); | ||
const { $schema, ...rest } = jsonSchema; | ||
return rest; | ||
} |
{ | ||
"name": "@langchain/google-genai", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"description": "Sample integration for LangChain.js", | ||
@@ -39,3 +39,3 @@ "type": "module", | ||
"@google/generative-ai": "^0.7.0", | ||
"@langchain/core": ">=0.2.5 <0.3.0", | ||
"@langchain/core": ">=0.2.9 <0.3.0", | ||
"zod-to-json-schema": "^3.22.4" | ||
@@ -42,0 +42,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96049
2244