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

[Bug]: The number of function response parts should be equal to number of function call parts of the function call turn #1736

Open
1 task done
lgbaeza opened this issue Feb 12, 2025 · 1 comment
Assignees

Comments

@lgbaeza
Copy link

lgbaeza commented Feb 12, 2025

File Name

gemini/function-calling/sql-talk-app/app.py

What happened?

This error appears when the BigQuery dataset contains multiple tables, basically because there is one part response for each table, leading to having more function parts in the response that in the function call definition.

I tested replacing the get_table function for a get_tables that handles several tables. I think I had a different code base, but Im sharing what I did as a sample

get_table_func = FunctionDeclaration(
    name="get_tables",
    description="Obtiene información sobre las tablas, incluida la descripción, el esquema y la cantidad de filas que ayudarán a responder la pregunta del usuario. Utilice siempre el nombre completo del conjunto de datos y de las tablas.",
    parameters={
        "type": "object",
        "properties": {
            "tables": {
                "type": "array",
                "description": "List of tables with informatioin in BQ",
                "items": {
                    "type": "object",
                    "properties": {
                        "table_id": {
                            "type": "string",
                            "description": "ID del Dataset del que se recuperarán las tablas",
                        },
                        "description": {
                            "type": "string",
                            "description": "Description of the table",
                        }
                    },
                    "required": [
                        "table_id",
                    ],
                }
            }
        }
    },
)

And the function implementation

        if response.function_call.name == "get_tables":
            api_responses = []
            processed_tables = None #Handles all tables in an array
            for table in params["tables"]:  # repeat for each table
                table_id = table["table_id"]
                ftable_id = f"{BIGQUERY_PROJECT_ID}.{BIGQUERY_DATASET_ID}.{table_id}"
                api_response = client.get_table(ftable_id)
                api_response = api_response.to_api_repr()
                api_responses.append(api_response)

                if processed_tables is None:
                    processed_tables = [
                        str([
                            str(api_response.get("description", "")),
                            str(
                                [
                                    column["name"] + ":" + column.get("description", "No description")
                                    for column in api_response["schema"]["fields"]
                                    if "description" in column
                                ]
                            )
                        ])
                    ]
                else:
                    try:
                        processed_tables.append(
                            str([
                                str(api_response.get("description", "")),
                                str(
                                    [
                                        column["name"] + ":" + column.get("description", "No description")
                                        for column in api_response["schema"]["fields"]
                                        if "description" in column
                                    ]
                                )
                            ])
                        )
                    except Exception as e:
                        print(e)
            
            # Return all tables in the function response
            api_requests_and_responses.append(
                [
                    response.function_call.name,
                    params,
                    str( processed_tables )
                ]
            )

            api_response = api_responses
                
            api_response = str( api_response)

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct
@koverholt
Copy link
Member

Thanks for the info and sample code!

Do you have an example of a input prompt that causes the sample app to error out like this with parallel function calls? Since the sample app uses the thelook_ecommerce sample data with multiple tables, I'd like to see if this is something we can fix with function calling modes or simpler logic so that we can keep this tutorial app as simple as possible.

@koverholt koverholt self-assigned this Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants