You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Description:
In version 1.0.10 of the langchain-google-genai package, there is an error when using Gemini tools. The error message returned is:
Error: Invalid argument provided to Gemini: 400 * GenerateContentRequest.tools[0].function_declarations[0].name: Invalid function name. Must start with a letter or an underscore. Must be alphameric (a-z, A-Z, 0-9), underscores (_), dots (.) or dashes (-), with a maximum length of 64.
Relevant Code Snippet:
from pydantic import BaseModel, Field
from langchain.tools import BaseTool
class MyCustomTool(BaseTool):
name = "valid_function_name" # Name follows the correct conventions
description = "This is a custom tool for Gemini."
args_schema: Type[BaseModel] = MyCustomToolInput
def _run(self):
# Tool logic
pass
first, you should be importing from langchain_core.tools import BaseTool afaik
can you share a full snippet with reproducible error, please?
this runs fine on my end:
from pydantic import BaseModel, Field
from langchain_core.tools import BaseTool
from typing import Type
class MyCustomTool(BaseTool):
name = "valid_function_name" # Name follows the correct conventions
description = "This is a custom tool for Gemini."
args_schema: Type[BaseModel] = {}
def _run(self):
# Tool logic
pass
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.documents import Document
from langchain_core.pydantic_v1 import BaseModel, Field
from typing import Optional
llm = ChatGoogleGenerativeAI(
model='gemini-1.5-pro-001',
google_api_key="XXX")
llm1 = llm.bind_tools([MyCustomTool()])
res = llm1.invoke("test tool")
print(res.tool_calls)
### Description:
In version 1.0.10 of the
langchain-google-genai
package, there is an error when using Gemini tools. The error message returned is:Error: Invalid argument provided to Gemini: 400 * GenerateContentRequest.tools[0].function_declarations[0].name: Invalid function name. Must start with a letter or an underscore. Must be alphameric (a-z, A-Z, 0-9), underscores (_), dots (.) or dashes (-), with a maximum length of 64.
Relevant Code Snippet:
Affected Version: 1.0.10
Working Version: 1.0.8
Package Information:
The text was updated successfully, but these errors were encountered: