Skip to content

Gemini and function calling: function call may be discarded. #2499

Open
@GregoireW

Description

@GregoireW

Bug description

This is linked to the PR #2029 where I try to fix this.

The gemini can respond multiple part, some containing test, some tool call. A response can be like:

part 1: message: " I understand what you want to do, I will check ..."
part 2: function call
part 3: message "if it is not enough you will need to check yourself .... "

Today, the response is processed by spring-ai in a way that function are executed only if all part of the response are function call.

It seems it is ok to switch the code

boolean isFunctionCall = candidate.getContent().getPartsList().stream().allMatch(Part::hasFunctionCall);
to use 'anyMatch' instead of 'allMatch' to check for function call in the response. As long there is a function call in the response, it should be executed.

Also, the response send back to the system is filtered, I think the response should send back all part returned by the API (

)

Environment

Spring-ai 1.0.0-M6
Gemini api (2.0 flash)

Steps to reproduce

Use springAI with a gemini model, add the tool "CurrentWeatherService" and prompt:

The procedure can be either to check the temperature for a city and then if the temperature you will need to update the fan speed from 0-100 depending on the temperature 0-30. Explain the procedure is more clean word and process it for the city Tokyo

It should trigger a response with 2 parts: 1 small message and 1 function call.

Expected behavior

SpringAI should execute function if there is one in a part of the response.

Also, the return should contains all the generation and all the part. Currently in the event of I push a prompt, genAI ask for a function call, the prompt with the function execution is pushed, only the last generation is send back, which means if we continue the chat, some data are missing.

Minimal Complete Reproducible example

Use springAI with a gemini model, add the tool "CurrentWeatherService" and prompt:

The procedure can be either to check the temperature for a city and then if the temperature you will need to update the fan speed from 0-100 depending on the temperature 0-30. Explain the procedure is more clean word and process it for the city Tokyo

It should trigger a response with 2 parts: 1 small message and 1 function call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions