借助函数调用,您可以创建基于 Gemini 的应用和代理,这些应用和代理可以与实时信息和服务(例如数据库、客户关系管理系统和文档库)进行交互。这有助于提升应用提供相关且符合上下文的回答的能力。
借助监督式微调,您可以使用自己的微调数据集来提高应用基于函数调用的回答的整体准确性。
支持的模型
以下 Gemini 模型支持函数调用调优:
gemini-2.0-flash-001
调参数据集格式
微调数据集的 fileUri
可以是 Cloud Storage 存储分区中文件的 URI,也可以是公开可用的 HTTP 或 HTTPS 网址。
如需查看通用格式示例,请参阅 适用于 Gemini 的数据集示例。
以下部分提供了函数调用数据集示例,供您在为函数调用创建调优作业时使用。
调整函数调用以生成文本
以下是用于调整使用函数调用生成单个文本回答的数据集示例。
{
"system_instruction": {
"role": "system",
"parts": [
{
"text": "You are an assistant that helps users find the best product for them."
}
]
},
"contents": [
{
"role": "user",
"parts": [
{
"text": "Do you have the White Pixel 8 Pro 128GB in stock in the US?"
}
]
},
{
"role": "model",
"parts": [
{
"functionCall": {
"name": "get_product_sku",
"args": {
"product_name": "Pixel 8 Pro 128GB"
}
}
}
]
}
],
"tools": [
{
"functionDeclarations": [
{
"name": "get_product_sku",
"description": "Get the available inventory for a Google products, e.g: Pixel phones, Pixel Watches, Google Home etc",
"parameters": {
"type": "OBJECT",
"properties": {
"product_name": {
"type": "STRING",
"description": "Product name",
"enum": [
"Pixel 8 Pro 128GB",
"Pixel 8 Pro 256GB",
"Pixel 8 Pro 512GB",
"Pixel 8 Pro 1TB"
]
}
}
}
},
{
"name": "get_store_location",
"description": "Get the location of the closest store",
"parameters": {
"type": "OBJECT",
"properties": {
"location": {
"type": "STRING",
"description": "Location"
}
}
}
}
]
}
]
}
调整函数调用以支持聊天会话
以下是用于调优函数调用以支持聊天会话的数据集示例。
{
"system_instruction": {
"role": "system",
"parts": [
{
"text": "You are an assistant that helps users find the best product for them."
}
]
},
"contents": [
{
"role": "user",
"parts": [
{
"text": "Do you have the Porcelain Pixel 8 Pro 128GB in stock in the US?"
}
]
},
{
"role": "model",
"parts": [
{
"functionCall": {
"name": "get_product_sku",
"args": {
"product_name": "Pixel 8 Pro 128GB"
}
}
}
]
},
{
"parts": [
{
"functionResponse": {
"name": "get_product_sku",
"response": {
"output": "True"
}
}
}
]
},
{
"role": "model",
"parts": [
{
"text": "Yes, we have the Porcelain Pixel 8 Pro 128GB in stock in the US."
}
]
}
],
"tools": [
{
"functionDeclarations": [
{
"name": "get_product_sku",
"description": "Get the available inventory for a Google products, e.g: Pixel phones, Pixel Watches, Google Home etc",
"parameters": {
"type": "OBJECT",
"properties": {
"product_name": {
"type": "STRING",
"description": "Product name",
"enum": [
"Pixel 8 Pro 128GB",
"Pixel 8 Pro 256GB",
"Pixel 8 Pro 512GB",
"Pixel 8 Pro 1TB"
]
}
}
}
},
{
"name": "get_store_location",
"description": "Get the location of the closest store",
"parameters": {
"type": "OBJECT",
"properties": {
"location": {
"type": "STRING",
"description": "Location"
}
}
}
}
]
}
]
}
调整并行函数调用
以下是用于调优并行函数调用的数据集示例。
{
"system_instruction": {
"role": "system",
"parts": [
{
"text": "You are an assistant that helps users find the best product for them."
}
]
},
"contents": [
{
"role": "user",
"parts": [
{
"text": "Where is the closest Google Store to Mountain View, CA that has Pixel 8 Pro 128GB in stock?"
}
]
},
{
"role": "model",
"parts": [
{
"functionCall": {
"name": "get_product_sku",
"args": {
"product_name": "Pixel 8 Pro 128GB"
}
}
},
{
"functionCall": {
"name": "get_store_location",
"args": {
"location": "Mountain View, CA"
}
}
}
]
}
],
"tools": [
{
"functionDeclarations": [
{
"name": "get_product_sku",
"description": "Get the available inventory for a Google products, e.g: Pixel phones, Pixel Watches, Google Home etc",
"parameters": {
"type": "OBJECT",
"properties": {
"product_name": {
"type": "STRING",
"description": "Product name",
"enum": [
"Pixel 8 Pro 128GB",
"Pixel 8 Pro 256GB",
"Pixel 8 Pro 512GB",
"Pixel 8 Pro 1TB"
]
}
}
}
},
{
"name": "get_store_location",
"description": "Get the location of the closest store",
"parameters": {
"type": "OBJECT",
"properties": {
"location": {
"type": "STRING",
"description": "Location"
}
}
}
}
]
}
]
}
后续步骤
- 如需了解如何创建调优作业以及如何测试经过调优的模型,请参阅使用监督式微调来调优 Gemini 模型。
- 如需了解 Gemini 模型调优,请参阅调优简介。
- 如需了解函数调用,请参阅函数调用简介。