谷歌的Gemini模型能否自动调用具有复杂参数的函数?

我正在使用谷歌的gemini-1.5-pro-002模型来构建一个聊天机器人。该模型部署在VertexAI上。我需要机器人能够自动调用函数。如果函数参数是简单的类型,如字符串或整数,它可以正常工作。但当我尝试使用复杂类型时,遇到了问题。

以下请求无法工作:

curl -X POST \  -H "Authorization: Bearer $(gcloud auth print-access-token)" \  -H "Content-Type: application/json" \https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/publishers/google/models/${MODEL_ID}:generateContent \-d '{    "contents": [        {            "role": "user",            "parts": [                {                    "text": "Search for German people with the last name of Greene"                }            ]        }    ],    "tools": [        {            "functionDeclarations": [                {                    "name": "SearchPlugin_SearchPerson",                    "description": "Find a person given a search request",                    "parameters": {                        "type": "object",                        "properties": {                            "search_request": {                                "type": "object",                                "properties": {                                    "first_name": {                                        "type": "string",                                        "description": "The person first_name"                                    },                                    "last_name": {                                        "type": "string",                                        "description": "The person last_name"                                    },                                    "nationality": {                                        "type": "string",                                        "description": "The person nationality"                                    }                                }                            }                        },                        "required": [                            "search_request"                        ]                    }                }            ]        }    ]}'

Gemini的回复是

{    "candidates": [        {            "content": {                "role": "model",                "parts": [                    {                        "functionCall": {                            "name": "SearchPlugin_SearchPerson",                            "args": {                                "search_request": "unknown"                            }                        }                    }                ]            },            "finishReason": "STOP"        }    ],    "usageMetadata": {        "promptTokenCount": 54,        "candidatesTokenCount": 9,        "totalTokenCount": 63    },    "modelVersion": "gemini-1.5-pro-002"}

如果我这样定义工具,Gemini可以正确使用它:

{    "functionDeclarations": [        {            "name": "SearchPlugin_SearchPerson",            "description": "Find a person given a search request.",            "parameters": {                "type": "object",                "properties": {                    "first_name": {                        "type": "string",                        "description": "The person first_name."                    },                    "last_name": {                        "type": "string",                        "description": "The person last_name."                    },                    "nationality": {                        "type": "string",                        "description": "The person nationality."                    }                },                "required": [                    "last_name"                ]            }        }    ]}

Gemini能否调用具有复杂参数的函数?


回答:

关于你的问题Can Gemini call functions with complex parameters?,答案是肯定的。但在当前阶段,结果取决于模型。

当我用几个模型测试你展示的请求体时,我注意到结果取决于模型。似乎在当前阶段(2024年9月30日),得到了以下结果。因此,作为当前的解决方案,如果你想直接使用你展示的请求体,可以考虑将模型从gemini-1.5-pro-002更改为其他模型吗?

结果

模型 结果
gemini-1.5-pro 失败
gemini-1.5-pro-001 失败
gemini-1.5-pro-latest 失败
gemini-1.5-pro-exp-0827 失败
gemini-1.5-pro-002 失败
gemini-1.5-flash 成功
gemini-1.5-flash-001 成功
gemini-1.5-flash-latest 成功
gemini-1.5-flash-8b-exp-0827 失败
gemini-1.5-flash-002 失败
gemini-1.5-flash-8b-exp-0924 成功

失败:从你的请求体中得到了"search_request": "unknown"成功:从你的请求体中得到了"search_request": {"last_name": "Greene","nationality": "German"}

注意事项:

  • Gemini现在正在成长中。因此,我相信这个结果会在未来的更新中得到更新。例如,目前的成功结果在更新中也可能会发生变化。所以,请将这个答案视为2024年9月30日的情况。

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注