Gemini API ile İşlev Çağrısı'na Giriş

Özel işlevler, şu işlev kullanılarak tanımlanıp Gemini modellerine sağlanabilir: Arama özelliği. Modeller bu işlevleri doğrudan çağırmaz, işlev adını belirten ve önerilen işlev adını belirten yapılandırılmış veri çıkışı oluşturmak bağımsız değişkenlerdir. Bu çıkış, yapılandırılmış veri öğelerini alan ve harici API'leri çağırır. Elde edilen API çıkışı daha sonra model istemine eklenerek daha kapsamlı sorgu yapılmasına olanak tanır. tıklayın. İşlev çağrısı, kullanıcıların gerçek zamanlı bilgi ve çeşitli hizmetleri (veritabanları, müşteri ilişkileri gibi) ve belge havuzlarını kullanarak onların çalışma becerilerini geliştirmelerine bağlama uygun yanıtlar vermeliyiz.

İşlev çağrısının işleyiş şekli

İşlev Çağrısı özelliğini, işlev bildirimleri adı verilen programlama arayüzlerini model istemine ekleme. İlgili içeriği oluşturmak için kullanılan işlev bildirimleri API işlevinin adını sağlar, amacını açıklar, URL'nin desteklediği tüm parametreleri ve bu parametrelerin açıklamalarını içerir. Sınavı geçtikten sonra işlev bildirimlerinin bir listesidir. Modele gönderilen sorguda, ifadelerinin ve sorgunun geri kalanının, açıklanan İsteğe yanıt olarak API.

Model, daha sonra OpenAPI uyumlu şema yanıt vermek için bildirilen işlevlerden birinin veya daha fazlasının nasıl çağrılacağını belirterek soru işaretlerine geri dönelim. Ardından, önerilen işlev çağrısını gerçek API'yi çağırın, bir yanıt alın ve bu yanıtı veya başka bir işlem yapmadığı anlamına gelir. Modelin aslında tanımlanmış işlevler. Bunun yerine, döndürülen şema nesnesi parametrelerini kullanarak fonksiyonu çağırın. Gemini API, paralel işlev çağrısını da destekler. model, tek bir isteğe dayalı birden fazla API işlevi çağrısı önerir.

Desteklenen modeller

Aşağıdaki modeller İşlev Çağrısı özelliğini destekler:

  • gemini-1.0-pro
  • gemini-1.0-pro-001
  • gemini-1.5-flash-latest
  • gemini-1.5-pro-latest

İşlev bildirimleri

Bir istemde işlev çağrısı uyguladığınızda bir tools nesnesi oluşturursunuz. ve bir veya daha fazla function declarations içerir. Fonksiyonları JSON kullanarak, özellikle de alt küme seç OpenAPI şeması biçimindedir. Tek bir işlev bildirimi aşağıdaki parametreleri içerebilir:

  • name (dize): API'deki işlevin benzersiz tanımlayıcısı çağrısına bir tıklama URL'si eklemeniz gerekir.
  • description (dize): İşlevin amaç ve kapasitedir.
  • parameters (nesne): İşlev için gereken giriş verilerini tanımlar.
    • type (dize): object gibi genel veri türünü belirtir.
    • properties (nesne): Her biri aşağıdakileri içeren bağımsız parametreleri listeler:
      • type (dize): Parametrenin veri türü. Örneğin: string, integer, boolean.
      • description (dize): Parametrenin ve beklenen biçimdir.
    • required (dizi): Parametre adlarını listeleyen dize dizisi zorunlu değerleridir.

cURL komutlarını kullanan bir işlev bildirimi kod örnekleri için İşlev çağrısı örnekleri. Örnekler için ve diğer platformlar için işlev bildirimleri oluşturma hakkında daha fazla bilgi için İşlev Çağrısı platformları rehberi

İşlev bildirimleri için en iyi uygulamalar

Fonksiyonlarınızı doğru şekilde tanımlamak, fonksiyonlarınızı kabul edersiniz. Her işlev, davranışını yönlendiren belirli parametrelere dayanır modelle etkileşimi de etkiler. Aşağıdaki listede functions_declarations işlevinde tek bir işlevin parametrelerini tanımlama dizisidir.

  • name: Boşluk, nokta içermeyen, net, açıklayıcı adlar kullanın (.) veya kısa çizgi (-) karakterden oluşmalıdır. Bunun yerine alt çizgi (_) karakterleri kullanın büyük/küçük harf kullanımını değiştirebilirsiniz.

  • description: İşlevsel açıdan ayrıntılı, net ve spesifik bilgiler verin ve gerekirse örnekler vermelidir. Örneğin, find theaters, find theaters based on location and optionally movie title that is currently playing in theaters. kullanın Çok geniş kapsamlı veya belirsizlikten kaçının açıklamaları.

  • properties> type: Kesintileri azaltmak için örnek halüsinasyonlar olabilir. Örneğin, parametre değerleri sonlu bir değerden set, değerleri açıklamada listelemek yerine bir enum alanı kullanın (ör. "type": "enum", "values": ["now_playing", "upcoming"]) bilgileri gösterilir. Öğe parametre değeri her zaman tam sayıdır; türü yerine integer olarak ayarlayın number.

  • properties> description: Somut örnekler ve sınırlamalar sağlayın. Örneğin, the location to search yerine The city and state, e.g. San Francisco, CA or a zip code e.g. 95616 değerini kullanın.

İşlev Çağrısı özelliğini kullanmayla ilgili diğer en iyi uygulamalar için En İyi Uygulamalar bölümüne bakın.

İşlev çağrısı modu

Yürütme işlemini değiştirmek için İşlev Çağrısı mode parametresini kullanabilirsiniz ve özelliğin davranışı. Kullanabileceğiniz üç mod vardır:

  • AUTO: Varsayılan model davranışı. Model, bir veya daha fazla işlev çağrısı veya doğal dil yanıtı gibi
  • ANY: Model, her zaman bir işlev çağrısını tahmin edecek şekilde sınırlandırılmıştır. Eğer allowed_function_names sağlanmadı. Model, tüm mevcut seçenekler arasından kullanabilirsiniz. allowed_function_names sağlanmışsa model, izin verilen fonksiyonlar kümesinden seçim yapar.
  • NONE: Model, bir işlev çağrısını tahmin etmez. Bu durumda model herhangi bir işlev bildirimi iletmediğinizde ile aynı olur.

Ayrıca, sağlandığında sınıra sahip bir allowed_function_names grubu da aktarabilirsiniz modelin çağıracağı işlevler. Yalnızca allowed_function_names, mod ANY olduğunda. İşlev adları eşleşmelidir işlev bildirimlerinin adları için de geçerlidir. Mod ANY olarak ayarlandığında ve allowed_function_names ayarlanırsa model, verilen işlev adı kümesidir. Aşağıdaki kod snippet'i örnek istek, mode değerini ANY olarak ayarlar ve izin verilen işlevlerin listesini belirtir:

"tool_config": {
  "function_calling_config": {
    "mode": "ANY",
    "allowed_function_names": ["find_theaters", "get_showtimes"]
  },
}

İşlev çağrısı örnekleri

Bu bölümde, cURL komutlarını kullanarak işlev çağrısı için örnek istemler sunulmaktadır. Örnekler arasında tek dönüş ve çok dönüşlü senaryoları kapsar. farklı işlev çağırma modları vardır.

Bu özellikle cURL komutlarını kullanırken, işlev ve parametre bilgileri tools öğesinde yer alır. Bu tools öğesi, işlev adını içerir ve parametreleri aşağıdakileri kullanarak belirtirsiniz: OpenAPI uyumlu bir şema kullanıyorsanız bir fonksiyon açıklaması girmelisiniz.

Tek dönüş örneği

Tek dönüş, dil modelini bir kez çağırdığınızda gerçekleşir. İşlev çağrısı ile modele doğal bir dil sunduğunuzda ise bir fonksiyon listesidir. Bu durumda model, işlev adını, parametrelerini ve açıklamasını içeren bildirimi ve hangi fonksiyonla çağrılacağını tahmin etmek için kullanılan bağımsız değişkenleri içerir.

Aşağıdaki curl örneği, bir öğeyi fonksiyonudur. Birkaç işlev bildirimleri isteğe dahil edilir (ör. find_movies ve find_theaters.

Tek dönüşlü işlev çağrısı örnek isteği

curl https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$API_KEY \
  -H 'Content-Type: application/json' \
  -d '{
    "contents": {
      "role": "user",
      "parts": {
        "text": "Which theaters in Mountain View show Barbie movie?"
    }
  },
  "tools": [
    {
      "function_declarations": [
        {
          "name": "find_movies",
          "description": "find movie titles currently playing in theaters based on any description, genre, title words, etc.",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
              },
              "description": {
                "type": "string",
                "description": "Any kind of description including category or genre, title words, attributes, etc."
              }
            },
            "required": [
              "description"
            ]
          }
        },
        {
          "name": "find_theaters",
          "description": "find theaters based on location and optionally movie title which is currently playing in theaters",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
              },
              "movie": {
                "type": "string",
                "description": "Any movie title"
              }
            },
            "required": [
              "location"
            ]
          }
        },
        {
          "name": "get_showtimes",
          "description": "Find the start times for movies playing in a specific theater",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
              },
              "movie": {
                "type": "string",
                "description": "Any movie title"
              },
              "theater": {
                "type": "string",
                "description": "Name of the theater"
              },
              "date": {
                "type": "string",
                "description": "Date for requested showtime"
              }
            },
            "required": [
              "location",
              "movie",
              "theater",
              "date"
            ]
          }
        }
      ]
    }
  ]
}'
    

Bu curl örneğine verilen yanıt aşağıdakine benzer olabilir.

Tek dönüşlü işlev çağrısı curl örnek yanıtı

[{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "functionCall": {
              "name": "find_theaters",
              "args": {
                "movie": "Barbie",
                "location": "Mountain View, CA"
              }
            }
          }
        ]
      },
      "finishReason": "STOP",
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE"
        }
      ]
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 9,
    "totalTokenCount": 9
  }
}]
    

ANY modunun kullanıldığı tek dönüş örneği

Aşağıdaki curl örneği şuna benzerdir: tek dönüşlü örneği, ancak modu ANY olarak ayarlayın:

"tool_config": {
  "function_calling_config": {
    "mode": "ANY"
  },
}

HERHANGİ BİR modu kullanarak tek dönüşlü işlev çağrısı (istek)

curl https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$API_KEY \
  -H 'Content-Type: application/json' \
  -d '{
    "contents": {
      "role": "user",
      "parts": {
        "text": "What movies are showing in North Seattle tonight?"
    }
  },
  "tools": [
    {
      "function_declarations": [
        {
          "name": "find_movies",
          "description": "find movie titles currently playing in theaters based on any description, genre, title words, etc.",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
              },
              "description": {
                "type": "string",
                "description": "Any kind of description including category or genre, title words, attributes, etc."
              }
            },
            "required": [
              "description"
            ]
          }
        },
        {
          "name": "find_theaters",
          "description": "find theaters based on location and optionally movie title which is currently playing in theaters",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
              },
              "movie": {
                "type": "string",
                "description": "Any movie title"
              }
            },
            "required": [
              "location"
            ]
          }
        },
        {
          "name": "get_showtimes",
          "description": "Find the start times for movies playing in a specific theater",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
              },
              "movie": {
                "type": "string",
                "description": "Any movie title"
              },
              "theater": {
                "type": "string",
                "description": "Name of the theater"
              },
              "date": {
                "type": "string",
                "description": "Date for requested showtime"
              }
            },
            "required": [
              "location",
              "movie",
              "theater",
              "date"
            ]
          }
        }
      ]
    }
  ],
  "tool_config": {
    "function_calling_config": {
      "mode": "ANY"
    },
  }
}'
    

Yanıt, aşağıdakine benzer olabilir:

HERHANGİ BİR modu kullanarak tek dönüşlü işlev çağrısı (yanıt)

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "functionCall": {
              "name": "find_movies",
              "args": {
                "description": "",
                "location": "North Seattle, WA"
              }
            }
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0,
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE"
        }
      ]
    }
  ],
  "promptFeedback": {
    "safetyRatings": [
      {
        "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
        "probability": "NEGLIGIBLE"
      },
      {
        "category": "HARM_CATEGORY_HATE_SPEECH",
        "probability": "NEGLIGIBLE"
      },
      {
        "category": "HARM_CATEGORY_HARASSMENT",
        "probability": "NEGLIGIBLE"
      },
      {
        "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
        "probability": "NEGLIGIBLE"
      }
    ]
  }
}
    

ANY modunu ve izin verilen işlevleri kullanan tek dönüş örneği

Aşağıdaki curl örneği şuna benzerdir: tek dönüşlü örneği, ancak mod'u ANY olarak ayarlar ve izin verilenlerin listesini içerir. işlevler:

"tool_config": {
  "function_calling_config": {
    "mode": "ANY",
    "allowed_function_names": ["find_theaters", "get_showtimes"]
  },
}

HERHANGİ BİR modu ve izin verilen işlevleri kullanarak tek dönüşlü işlev çağrısı (istek)

curl https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$API_KEY \
  -H 'Content-Type: application/json' \
  -d '{
    "contents": {
      "role": "user",
      "parts": {
        "text": "What movies are showing in North Seattle tonight?"
    }
  },
  "tools": [
    {
      "function_declarations": [
        {
          "name": "find_movies",
          "description": "find movie titles currently playing in theaters based on any description, genre, title words, etc.",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
              },
              "description": {
                "type": "string",
                "description": "Any kind of description including category or genre, title words, attributes, etc."
              }
            },
            "required": [
              "description"
            ]
          }
        },
        {
          "name": "find_theaters",
          "description": "find theaters based on location and optionally movie title which is currently playing in theaters",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
              },
              "movie": {
                "type": "string",
                "description": "Any movie title"
              }
            },
            "required": [
              "location"
            ]
          }
        },
        {
          "name": "get_showtimes",
          "description": "Find the start times for movies playing in a specific theater",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
              },
              "movie": {
                "type": "string",
                "description": "Any movie title"
              },
              "theater": {
                "type": "string",
                "description": "Name of the theater"
              },
              "date": {
                "type": "string",
                "description": "Date for requested showtime"
              }
            },
            "required": [
              "location",
              "movie",
              "theater",
              "date"
            ]
          }
        }
      ]
    }
  ],
  "tool_config": {
    "function_calling_config": {
      "mode": "ANY",
      "allowed_function_names": ["find_theaters", "get_showtimes"]
    },
  }
}'
    

Model, listede olmadığı için find_movies işlevini tahmin edemiyor için farklı bir işlev tahmin eder. Yanıt aşağıdakine benzer olabilir:

HERHANGİ BİR modu ve izin verilen işlevleri kullanarak tek dönüşlü işlev çağrısı (yanıt)

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "functionCall": {
              "name": "find_theaters",
              "args": {
                "location": "North Seattle, WA",
                "movie": null
              }
            }
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0,
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE"
        }
      ]
    }
  ],
  "promptFeedback": {
    "safetyRatings": [
      {
        "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
        "probability": "NEGLIGIBLE"
      },
      {
        "category": "HARM_CATEGORY_HATE_SPEECH",
        "probability": "NEGLIGIBLE"
      },
      {
        "category": "HARM_CATEGORY_HARASSMENT",
        "probability": "NEGLIGIBLE"
      },
      {
        "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
        "probability": "NEGLIGIBLE"
      }
    ]
  }
}
    

Çok dönüşlü geçiş örnekleri

Aşağıdakileri yaparak çok dönüşlü işlev çağırma senaryosu uygulayabilirsiniz:

  1. Dil modelini çağırarak bir işlev çağrısı yanıtı alın. Bu ilk CANNOT TRANSLATE
  2. İlk dönüşteki işlev çağrısı yanıtını kullanarak dil modelini çağırın ve bu işlevi çağırarak aldığınız fonksiyon yanıtını ekleyin. Bu, ikinci dönüş.

İkinci dönüşün yanıtı, o ana kadar bir fonksiyon çağrısı içeriyorsa veya ikinci bir fonksiyon çağrısını daha fazla bilgi edinin.

Bu konu, iki çok dönüşlü kıvrım örneği içerir:

Önceki bir dönüşten bir yanıtı kullanma

Aşağıdaki curl örneği, tek dönüşlü önceki örneğe bakın. Yöntem ve parametreler tek dönüşlü örneği tarafından döndürülen tüm anahtar/değer çiftleri bu JSON'dadır.

"functionCall": {
  "name": "find_theaters",
  "args": {
    "movie": "Barbie",
    "location": "Mountain View, CA"
  }
}

Çok dönüşlü işlev çağrısı curl örnek isteği

curl https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$API_KEY \
  -H 'Content-Type: application/json' \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [{
        "text": "Which theaters in Mountain View show Barbie movie?"
    }]
  }, {
    "role": "model",
    "parts": [{
      "functionCall": {
        "name": "find_theaters",
        "args": {
          "location": "Mountain View, CA",
          "movie": "Barbie"
        }
      }
    }]
  }, {
    "role": "function",
    "parts": [{
      "functionResponse": {
        "name": "find_theaters",
        "response": {
          "name": "find_theaters",
          "content": {
            "movie": "Barbie",
            "theaters": [{
              "name": "AMC Mountain View 16",
              "address": "2000 W El Camino Real, Mountain View, CA 94040"
            }, {
              "name": "Regal Edwards 14",
              "address": "245 Castro St, Mountain View, CA 94040"
            }]
          }
        }
      }
    }]
  }],
  "tools": [{
    "functionDeclarations": [{
      "name": "find_movies",
      "description": "find movie titles currently playing in theaters based on any description, genre, title words, etc.",
      "parameters": {
        "type": "OBJECT",
        "properties": {
          "location": {
            "type": "STRING",
            "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
          },
          "description": {
            "type": "STRING",
            "description": "Any kind of description including category or genre, title words, attributes, etc."
          }
        },
        "required": ["description"]
      }
    }, {
      "name": "find_theaters",
      "description": "find theaters based on location and optionally movie title which is currently playing in theaters",
      "parameters": {
        "type": "OBJECT",
        "properties": {
          "location": {
            "type": "STRING",
            "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
          },
          "movie": {
            "type": "STRING",
            "description": "Any movie title"
          }
        },
        "required": ["location"]
      }
    }, {
      "name": "get_showtimes",
      "description": "Find the start times for movies playing in a specific theater",
      "parameters": {
        "type": "OBJECT",
        "properties": {
          "location": {
            "type": "STRING",
            "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
          },
          "movie": {
            "type": "STRING",
            "description": "Any movie title"
          },
          "theater": {
            "type": "STRING",
            "description": "Name of the theater"
          },
          "date": {
            "type": "STRING",
            "description": "Date for requested showtime"
          }
        },
        "required": ["location", "movie", "theater", "date"]
      }
    }]
  }]
}'
    

Bu curl örneğine verilen yanıt, find_theaters yöntemini çağırın. Yanıt, aşağıdakine benzer olabilir:

Çok dönüşlü işlev çağrısı curl örnek yanıtı

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": " OK. Barbie is showing in two theaters in Mountain View, CA: AMC Mountain View 16 and Regal Edwards 14."
          }
        ]
      }
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 9,
    "candidatesTokenCount": 27,
    "totalTokenCount": 36
  }
}
    

Modeli birden çok kez çağırma

Aşağıdaki cURL örneği, üretken yapay zeka modelini birden çok kez çağırarak bir işlev olarak tanımlanır. Model, fonksiyonu her çağırdığında farklı bir işlevini kullanın.

Çok dönüşlü işlev çağrısı curl örnek isteği

curl https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$API_KEY \
  -H 'Content-Type: application/json' \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [{
        "text": "Which theaters in Mountain View show Barbie movie?"
    }]
  }, {
    "role": "model",
    "parts": [{
      "functionCall": {
        "name": "find_theaters",
        "args": {
          "location": "Mountain View, CA",
          "movie": "Barbie"
        }
      }
    }]
  }, {
    "role": "function",
    "parts": [{
      "functionResponse": {
        "name": "find_theaters",
        "response": {
          "name": "find_theaters",
          "content": {
            "movie": "Barbie",
            "theaters": [{
              "name": "AMC Mountain View 16",
              "address": "2000 W El Camino Real, Mountain View, CA 94040"
            }, {
              "name": "Regal Edwards 14",
              "address": "245 Castro St, Mountain View, CA 94040"
            }]
          }
        }
      }
    }]
  },
  {
    "role": "model",
    "parts": [{
      "text": " OK. Barbie is showing in two theaters in Mountain View, CA: AMC Mountain View 16 and Regal Edwards 14."
    }]
  },{
    "role": "user",
    "parts": [{
      "text": "Can we recommend some comedy movies on show in Mountain View?"
    }]
  }],
  "tools": [{
    "functionDeclarations": [{
      "name": "find_movies",
      "description": "find movie titles currently playing in theaters based on any description, genre, title words, etc.",
      "parameters": {
        "type": "OBJECT",
        "properties": {
          "location": {
            "type": "STRING",
            "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
          },
          "description": {
            "type": "STRING",
            "description": "Any kind of description including category or genre, title words, attributes, etc."
          }
        },
        "required": ["description"]
      }
    }, {
      "name": "find_theaters",
      "description": "find theaters based on location and optionally movie title which is currently playing in theaters",
      "parameters": {
        "type": "OBJECT",
        "properties": {
          "location": {
            "type": "STRING",
            "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
          },
          "movie": {
            "type": "STRING",
            "description": "Any movie title"
          }
        },
        "required": ["location"]
      }
    }, {
      "name": "get_showtimes",
      "description": "Find the start times for movies playing in a specific theater",
      "parameters": {
        "type": "OBJECT",
        "properties": {
          "location": {
            "type": "STRING",
            "description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
          },
          "movie": {
            "type": "STRING",
            "description": "Any movie title"
          },
          "theater": {
            "type": "STRING",
            "description": "Name of the theater"
          },
          "date": {
            "type": "STRING",
            "description": "Date for requested showtime"
          }
        },
        "required": ["location", "movie", "theater", "date"]
      }
    }]
  }]
}'
    

Çok dönüşlü işlev çağrısı curl örnek yanıtı

[{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "functionCall": {
              "name": "find_movies",
              "args": {
                "description": "comedy",
                "location": "Mountain View, CA"
              }
            }
          }
        ]
      },
      "finishReason": "STOP",
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE"
        }
      ]
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 48,
    "totalTokenCount": 48
  }
}
]
    

En iyi uygulamalar

Doğruluk ve dönüşümleri artırmak için bu en iyi uygulamaları güvenilirliğini artırır.

Kullanıcı istemi

En iyi sonuçlar için kullanıcı sorgusunun başına aşağıdaki ayrıntıları ekleyin:

  • Model için ek bağlam. Örneğin, You are a movie API assistant to help users find movies and showtimes based on their preferences.
  • İşlevlerin nasıl ve ne zaman kullanılacağına ilişkin ayrıntılar veya talimatlar. Örneğin, Don't make assumptions on showtimes. Always use a future date for showtimes.
  • Kullanıcı sorguları belirsiz olduğunda açıklayıcı sorular sorma talimatları. Örneğin, örnek, Ask clarifying questions if not enough information is available to complete the request.

Örnekleme parametreleri

Sıcaklık parametresi için 0 veya başka bir düşük değer kullanın. Bu komut ve halüsinasyonları azaltan bir model kullanır.

API çağrısı

Model, sipariş gönderen bir işlevin çağrılmasını önerirse veya başka şekilde önemli sonuçları olacaksa işlev çağrısında bulunmayı unutmayın.