Luis Sergio Faria Carneiro created CAMEL-22260:
--------------------------------------------------

             Summary: [camel-langchain4j-tools] Support for defining the 
function names
                 Key: CAMEL-22260
                 URL: https://issues.apache.org/jira/browse/CAMEL-22260
             Project: Camel
          Issue Type: Improvement
          Components: camel-langchain4j-tools
            Reporter: Luis Sergio Faria Carneiro


The langchain4j-tools component has a parameter name *description* which is 
used to generate a function name to be registered at the LLM.

The function name is the simple description defined 
[here|https://github.com/lsergio/camel/blob/main/components/camel-ai/camel-langchain4j-tools/src/main/java/org/apache/camel/component/langchain4j/tools/LangChain4jToolsEndpoint.java#L125].

However, LLMs might have restrictions on the function names. For example, 
Gemini function names length must not exceed 64 characters and have some 
limitations on what characters can be used. And those restrictions are 
reflected on the description.

So If I create a route like this:
{code:java}
- from:
    uri: "langchain4j-tools:demo"
    parameters:
        tags: demo
        description: Returns the address for a given zip code (city, state and 
neighborhood)
        parameter.zipcode: string
    steps:
    - log:
        message: Querying zip code ${headers.zipcode}${headers.zipcode} {code}
and try to use it with gemini-1.5-flash I get the error:
{code:java}
error": {
    "code": 400,
    "message": "* 
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.\n",
    "status": "INVALID_ARGUMENT"
  }
 {code}
So this forces me to to change the description.

The goal here is to support a new parameter, functionName, which could be used 
as follows:
{code:java}
- from:
    uri: "langchain4j-tools:demo"
    parameters:
        tags: demo
        description: Returns the address for a given zip code (city, state and 
neighborhood)
        functionName: ReturnAddressForZipCode
        parameter.zipcode: string
    steps:
    - log:
        message: Querying zip code ${headers.zipcode}${headers.zipcode} 
{code}
If no functionName is provided, we would still generate one from the 
description.

Some other cases which this fails are descriptions in languages that have 
non-ascii characters, like é, á, ã, ñ, in the description.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to