@langchain/google-genai
Advanced tools
Comparing version 0.0.24 to 0.0.25
@@ -1,2 +0,2 @@ | ||
import { FunctionDeclarationsTool as GoogleGenerativeAIFunctionDeclarationsTool, GenerateContentRequest, SafetySetting, Part as GenerativeAIPart } from "@google/generative-ai"; | ||
import { GenerateContentRequest, SafetySetting, Part as GenerativeAIPart } from "@google/generative-ai"; | ||
import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager"; | ||
@@ -6,6 +6,6 @@ import { AIMessageChunk, BaseMessage } from "@langchain/core/messages"; | ||
import { BaseChatModel, type BaseChatModelCallOptions, type LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models"; | ||
import { BaseLanguageModelInput, StructuredOutputMethodOptions, ToolDefinition } from "@langchain/core/language_models/base"; | ||
import { StructuredToolInterface } from "@langchain/core/tools"; | ||
import { Runnable, RunnableToolLike } from "@langchain/core/runnables"; | ||
import { BaseLanguageModelInput, StructuredOutputMethodOptions } from "@langchain/core/language_models/base"; | ||
import { Runnable } from "@langchain/core/runnables"; | ||
import type { z } from "zod"; | ||
import { GoogleGenerativeAIToolType } from "./types.js"; | ||
export type BaseMessageExamplePair = { | ||
@@ -16,3 +16,3 @@ input: BaseMessage; | ||
export interface GoogleGenerativeAIChatCallOptions extends BaseChatModelCallOptions { | ||
tools?: StructuredToolInterface[] | GoogleGenerativeAIFunctionDeclarationsTool[]; | ||
tools?: GoogleGenerativeAIToolType[]; | ||
/** | ||
@@ -169,3 +169,3 @@ * Whether or not to include usage data, like token counts | ||
_llmType(): string; | ||
bindTools(tools: (StructuredToolInterface | Record<string, unknown> | ToolDefinition | RunnableToolLike)[], kwargs?: Partial<GoogleGenerativeAIChatCallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, GoogleGenerativeAIChatCallOptions>; | ||
bindTools(tools: GoogleGenerativeAIToolType[], kwargs?: Partial<GoogleGenerativeAIChatCallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, GoogleGenerativeAIChatCallOptions>; | ||
invocationParams(options?: this["ParsedCallOptions"]): Omit<GenerateContentRequest, "contents">; | ||
@@ -172,0 +172,0 @@ _generate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>; |
import { EnhancedGenerateContentResponse, Content, Part, type FunctionDeclarationsTool as GoogleGenerativeAIFunctionDeclarationsTool, POSSIBLE_ROLES } from "@google/generative-ai"; | ||
import { BaseMessage, UsageMetadata } from "@langchain/core/messages"; | ||
import { ChatGenerationChunk, ChatResult } from "@langchain/core/outputs"; | ||
import { StructuredToolInterface } from "@langchain/core/tools"; | ||
import { ToolDefinition } from "@langchain/core/language_models/base"; | ||
import { RunnableToolLike } from "@langchain/core/runnables"; | ||
import { GoogleGenerativeAIToolType } from "../types.js"; | ||
export declare function getMessageAuthor(message: BaseMessage): string; | ||
@@ -24,2 +22,2 @@ /** | ||
}): ChatGenerationChunk | null; | ||
export declare function convertToGenerativeAITools(structuredTools: (StructuredToolInterface | Record<string, unknown> | ToolDefinition | RunnableToolLike)[]): GoogleGenerativeAIFunctionDeclarationsTool[]; | ||
export declare function convertToGenerativeAITools(tools: GoogleGenerativeAIToolType[]): 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 { isOpenAITool, } from "@langchain/core/language_models/base"; | ||
import { isLangChainTool } from "@langchain/core/utils/function_calling"; | ||
import { isOpenAITool } from "@langchain/core/language_models/base"; | ||
import { jsonSchemaToGeminiParameters, zodToGenerativeAIParameters, } from "./zod_to_genai_parameters.js"; | ||
@@ -240,27 +240,26 @@ export function getMessageAuthor(message) { | ||
} | ||
export function convertToGenerativeAITools(structuredTools) { | ||
if (structuredTools.every((tool) => "functionDeclarations" in tool && | ||
export function convertToGenerativeAITools(tools) { | ||
if (tools.every((tool) => "functionDeclarations" in tool && | ||
Array.isArray(tool.functionDeclarations))) { | ||
return structuredTools; | ||
return tools; | ||
} | ||
return [ | ||
{ | ||
functionDeclarations: structuredTools.map((structuredTool) => { | ||
if (isStructuredTool(structuredTool)) { | ||
const jsonSchema = zodToGenerativeAIParameters(structuredTool.schema); | ||
functionDeclarations: tools.map((tool) => { | ||
if (isLangChainTool(tool)) { | ||
const jsonSchema = zodToGenerativeAIParameters(tool.schema); | ||
return { | ||
name: structuredTool.name, | ||
description: structuredTool.description, | ||
name: tool.name, | ||
description: tool.description, | ||
parameters: jsonSchema, | ||
}; | ||
} | ||
if (isOpenAITool(structuredTool)) { | ||
if (isOpenAITool(tool)) { | ||
return { | ||
name: structuredTool.function.name, | ||
description: structuredTool.function.description ?? | ||
`A function available to call.`, | ||
parameters: jsonSchemaToGeminiParameters(structuredTool.function.parameters), | ||
name: tool.function.name, | ||
description: tool.function.description ?? `A function available to call.`, | ||
parameters: jsonSchemaToGeminiParameters(tool.function.parameters), | ||
}; | ||
} | ||
return structuredTool; | ||
return tool; | ||
}), | ||
@@ -267,0 +266,0 @@ }, |
{ | ||
"name": "@langchain/google-genai", | ||
"version": "0.0.24", | ||
"description": "Sample integration for LangChain.js", | ||
"version": "0.0.25", | ||
"description": "Google Generative AI integration for LangChain.js", | ||
"type": "module", | ||
@@ -39,3 +39,3 @@ "engines": { | ||
"@google/generative-ai": "^0.7.0", | ||
"@langchain/core": ">=0.2.16 <0.3.0", | ||
"@langchain/core": ">=0.2.21 <0.3.0", | ||
"zod-to-json-schema": "^3.22.4" | ||
@@ -64,3 +64,3 @@ }, | ||
"prettier": "^2.8.3", | ||
"release-it": "^15.10.1", | ||
"release-it": "^17.6.0", | ||
"rollup": "^4.5.2", | ||
@@ -67,0 +67,0 @@ "ts-jest": "^29.1.0", |
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
28
2285
96928