Menyesuaikan panggilan fungsi

Panggilan fungsi memungkinkan Anda membuat aplikasi dan agen berbasis Gemini yang dapat berinteraksi dengan informasi dan layanan real-time seperti database, sistem pengelolaan hubungan pelanggan, dan repositori dokumen. Hal ini meningkatkan kemampuan aplikasi Anda untuk memberikan respons yang relevan dan kontekstual.

Dengan penyesuaian yang diawasi, Anda dapat menggunakan set data penyesuaian Anda sendiri untuk meningkatkan akurasi keseluruhan respons berbasis panggilan fungsi aplikasi Anda.

Model yang didukung

Model Gemini berikut mendukung penyesuaian panggilan fungsi:

  • gemini-2.0-flash-001

Menyesuaikan format set data

fileUri untuk set data penyesuaian dapat berupa URI untuk file di bucket Cloud Storage, atau dapat berupa URL HTTP atau HTTPS yang tersedia secara publik.

Untuk melihat contoh format generik, lihat contoh set data untuk Gemini.

Bagian berikut menampilkan contoh set data panggilan fungsi untuk digunakan dalam membuat tugas penyesuaian untuk panggilan fungsi.

Menyesuaikan panggilan fungsi untuk membuat teks

Berikut adalah contoh set data untuk menyesuaikan pemanggilan fungsi guna menghasilkan satu respons teks.

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

Menyesuaikan panggilan fungsi untuk mendukung sesi chat

Berikut adalah contoh set data untuk menyesuaikan panggilan fungsi untuk mendukung sesi 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"
              }
            }
          }
        }
      ]
    }
  ]
}

Menyesuaikan panggilan fungsi paralel

Berikut adalah contoh set data untuk menyesuaikan panggilan fungsi paralel.

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

Langkah berikutnya