Cómo optimizar las llamadas a función

La llamada a función te permite crear aplicaciones y agentes basados en Gemini que pueden interactuar con información y servicios en tiempo real, como bases de datos, sistemas de administración de relaciones con clientes y repositorios de documentos. Esto mejora la capacidad de tu aplicación para proporcionar respuestas pertinentes y contextuales.

Con el ajuste fino supervisado, puedes usar tu propio conjunto de datos de ajuste para mejorar la precisión general de las respuestas basadas en llamadas a funciones de tu aplicación.

Formato del conjunto de datos de ajuste

El fileUri de tu conjunto de datos de ajuste fino puede ser el URI de un archivo en un bucket de Cloud Storage o una URL HTTP o HTTPS disponible públicamente.

Para ver el ejemplo de formato genérico, consulta el ejemplo de conjunto de datos para Gemini.

En las siguientes secciones, se presentan ejemplos de conjuntos de datos de llamadas a funciones para usar en la creación de un trabajo de ajuste para las llamadas a funciones.

Ajusta la función de llamadas para generar texto

A continuación, se muestra un ejemplo de un conjunto de datos para ajustar la llamada a función para generar una sola respuesta de texto.

{
  "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"
              }
            }
          }
        }
      ]
    }
  ]
}

Ajusta la llamada a función para admitir una sesión de chat

A continuación, se muestra un ejemplo de un conjunto de datos para ajustar la llamada a función para admitir una sesión de chat.

{
  "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"
              }
            }
          }
        }
      ]
    }
  ]
}

Ajusta la llamada a función paralela

El siguiente es un ejemplo de un conjunto de datos para ajustar la llamada a función paralela.

{
  "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"
              }
            }
          }
        }
      ]
    }
  ]
}

¿Qué sigue?