Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error:  Invalid argument provided to Gemini: 400 * GenerateContentRequest.tools[0].function_declarations[0].name #471

Closed
Nandhan-augment opened this issue Sep 3, 2024 · 1 comment
Assignees

Comments

@Nandhan-augment
Copy link

Nandhan-augment commented Sep 3, 2024

### 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

Affected Version: 1.0.10
Working Version: 1.0.8

Package Information:

langchain==0.2.15
langchain-community==0.2.14
langchain-core==0.2.36
langchain-google-genai==1.0.10
langchain-text-splitters==0.2.2
langchainplus-sdk==0.0.20
langserve==0.2.2
langsmith==0.1.107

@langcarl langcarl bot added the investigate label Sep 3, 2024
@langcarl langcarl bot assigned efriis Sep 3, 2024
@lkuligin
Copy link
Collaborator

lkuligin commented Sep 4, 2024

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'}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants