Open Nandhan-augment opened 2 weeks ago
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)
returns
[{'name': 'valid_function_name', 'args': {'__arg1': 'foo_bar'}, 'id': '8a0fa7d2-1f65-489e-b6a3-e89527594aee', 'type': 'tool_call'}]
### 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: