İşlev çağrısı

Özel işlevler, işlev çağrısı kullanılarak tanımlanıp üretken yapay zeka modeline sağlanabilir. Model, bu işlevleri doğrudan çağırmaz. Bunun yerine işlev adını ve önerilen bağımsız değişkenleri belirten yapılandırılmış veri çıkışı oluşturur. Bu çıkış, harici API'lerin çağrılmasını sağlar ve sonuçta ortaya çıkan API çıkışı daha sonra modele tekrar dahil edilebilir. Böylece daha kapsamlı sorgu yanıtları elde edilebilir. İşlev çağrısı, LLM'lerin gerçek zamanlı bilgilerle ve veritabanları, müşteri ilişkileri yönetim sistemleri ve belge depoları gibi çeşitli hizmetlerle etkileşim kurmasını sağlayarak alakalı ve bağlamsal yanıtlar sağlama becerilerini geliştirir.

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

İşlevler, işlev bildirimleri kullanılarak açıklanır. Bir sorgudaki işlev bildirimleri listesini bir dil modeline ilettikten sonra model, işlevlerin adlarını ve bağımsız değişkenlerini içeren OpenAPI uyumlu şema biçiminde bir nesne döndürür ve kullanıcı sorgusunu döndürülen işlevlerden biriyle yanıtlamaya çalışır. Dil modeli, işlev bildirimini analiz ederek işlevin amacını anlar. Model aslında işlevi çağırmaz. Bunun yerine geliştirici, modelin döndürdüğü işlevi çağırmak için yanıtta OpenAPI uyumlu şema nesnesini kullanır.

İşlev çağrısını uyguladığınızda, bir veya daha fazla işlev bildirimi oluşturur, ardından işlev bildirimlerini modele iletilen bir tools nesnesine eklersiniz. Her işlev beyanı, bir işlevle ilgili aşağıdakileri içeren bilgiler içerir:

  • İşlev adı
  • OpenAPI uyumlu şema biçimindeki işlev parametreleri. Belirli bir alt küme desteklenir. curl kullanılırken şema, JSON kullanılarak belirtilir.
  • İşlev açıklaması (isteğe bağlı). En iyi sonuçları elde etmek için bir açıklama eklemenizi öneririz.

Bu belgede, GenerativeModel sınıfı ve yöntemleriyle REST çağrıları yapan curl örnekleri bulunmaktadır.

Desteklenen modeller

Aşağıdaki modeller işlev çağrısını destekler:

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

İşlev çağrısı modu

İşlev çağrısının yürütme davranışını tanımlamak için mode özelliğini çağıran işlev kullanabilirsiniz. Kullanabileceğiniz üç mod vardır:

  • AUTO: Varsayılan model davranışı. Model, bir işlev çağrısı veya doğal dil yanıtı tahmininde bulunmaya karar verir.
  • ANY: Model, her zaman bir işlev çağrısını tahmin edecek şekilde kısıtlanır. allowed_function_names sağlanmazsa model, kullanılabilir tüm işlev bildirimleri arasından seçim yapar. allowed_function_names sağlanmışsa model, izin verilen işlevler grubundan seçim yapar.
  • NONE: Model, işlev çağrısı tahmin etmez. Bu durumda model davranışı, herhangi bir işlev bildirimini geçirmemenizle aynı olur.

Ayrıca, sağlandığında modelin çağıracağı işlevleri sınırlayan bir allowed_function_names grubu da iletebilirsiniz. allowed_function_names öğesini yalnızca mod ANY olduğunda eklemeniz gerekir. İşlev adları, işlev bildirim adlarıyla eşleşmelidir. Mod ANY olarak ayarlanıp allowed_function_names ayarlandığında model, sağlanan işlev adı grubundan bir işlev çağrısı tahmin eder.

Modu ANY olarak ayarlayan ve izin verilen işlevlerin listesini belirten örnek bir isteğin bölümünü burada görebilirsiniz:

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

cURL örneklerini çağıran işlev

cURL kullandığınızda işlev ve parametre bilgileri tools öğesine eklenir. tools öğesindeki her işlev bildirimi; işlev adını, OpenAPI uyumlu şema kullanılarak belirtilen parametrelerini ve bir işlev açıklamasını içerir. Aşağıdaki örnekler, curl komutlarının işlev çağrısıyla nasıl kullanılacağını göstermektedir:

Tek dönüşlü kıvırma örneği

Tek dönüş, dil modelini bir kez çağırmanızdır. İşlev çağrısında, modele bir doğal dil sorgusu ve işlev listesi sağladığınızda tek dönüşlü bir kullanım alanı olabilir. Bu durumda model, hangi işlevin çağırılacağını ve işlevin çağırılacağı bağımsız değişkenlerin tahmin edilmesi için işlev adını, parametreleri ve açıklamayı içeren işlev bildirimini kullanır.

Aşağıdaki kıvrım örneği, bir filmin oynatıldığı yerle ilgili bilgileri döndüren bir işlevin açıklamasına geçirilmesine bir örnektir. İsteğe find_movies ve find_theaters gibi çeşitli işlev bildirimleri dahil edilir.

Tek 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?"
    }
  },
  "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ğinin yanıtı, aşağıdakine benzer olabilir.

Curl örnek yanıtı çağıran tek dönüş işlevi

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

HERHANGİ BİR modu kullanan tek dönüşlü örnek

Aşağıdaki kıvrım örneği, tek dönüş örneğine benzer ancak modu ANY olarak ayarlar:

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

HERHANGİ BİR modu ve izin verilen işlevleri kullanan tek dönüşlü örnek

Aşağıdaki kıvrım örneği, tek dönüş örneğine benzer ancak modu ANY olarak ayarlar ve izin verilen işlevlerin listesini içerir:

"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, izin verilen işlevler listesinde olmadığından find_movies işlevini tahmin edemez. Dolayısıyla bunun yerine 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ü kıvrım örnekleri

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

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

İkinci dönüşün yanıtı, ilk aşamada sorgunuzu cevaplayacak sonuçları özetler veya sorgunuzla ilgili daha fazla bilgi almak için kullanabileceğiniz ikinci bir işlev çağrısı içerir.

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

Önceki dönüşün yanıtının kullanıldığı Curl örneği

Aşağıdaki curl örneği, yanıt almak için önceki tek dönüşlü örneğin döndürdüğü işlevi ve bağımsız değişkenleri çağırır. Tek dönüşlü örneğin döndürdüğü yöntem ve parametreler 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ğinin yanıtı, find_theaters yönteminin çağrılmasının sonucunu içerir. Yanıt, aşağıdakine benzer olabilir:

Curl örneği yanıtı için çok dönüşlü işlev çağrısı

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

Bir dil modelini birden çok kez çağıran Curl örneği

Aşağıdaki curl örneği, bir işlevi çağırmak için dil modelini birden çok kez çağırır. Model, işlevi her çağırdığında istekteki farklı bir kullanıcı sorgusunu yanıtlamak için farklı bir işlev kullanabilir.

Ç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"]
      }
    }]
  }]
}'
    

Curl örneği yanıtı için çok dönüşlü işlev çağrısı

[{
  "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

İşlev çağrılarınızın doğruluğunu ve güvenilirliğini artırmak için bu en iyi uygulamalardan yararlanın.

İşlev anahtarı alanları

İşlevlerinizi isteklerinize entegre ederken doğru şekilde tanımlamak çok önemlidir. Her işlev, davranışını ve modelle etkileşimini yönlendiren belirli parametrelere dayanır. functions_declarations dizisinde kullanılan anahtar parametrelerinin dökümünü burada bulabilirsiniz.

function_declarations (dizi):

  • Her biri farklı bir işlevi temsil eden bir veya daha fazla nesne içerir.

Her function_declarations nesnesinde:

  • name (dize): API çağrısındaki işlevin benzersiz tanımlayıcısı.
    • En iyi uygulama: Boşluk, nokta (.) veya tire (-) karakteri içermeyen net, açıklayıcı adlar kullanın. Bunun yerine, alt çizgi (_) karakterleri veya büyük/küçük harf kullanın.
  • description (dize): İşlevin amacı ve özellikleri hakkında kapsamlı bir açıklama.
    • En iyi uygulama: İşlev açıklamalarında ayrıntılı, net ve spesifik olun, gerekirse örnekler verin. Örneğin, find theaters yerine find theaters based on location and optionally movie title that is currently playing in theaters. kullanın. Aşırı geniş veya belirsiz açıklamalardan kaçının.
  • parameters (nesne): İşlev için gereken giriş verilerini tanımlar.
    • type (dize): Genel veri türünü belirtir (ör. object).
    • properties (nesne):
      • Her biri şu özelliklere sahip bağımsız parametreleri listeler:
        • type (dize): Parametrenin veri türü (ör. string, integer, boolean).
          • En iyi uygulama: Model halüsinasyonlarını azaltmak için kesin bir şekilde yazılmış parametreleri kullanın. Örneğin, parametre değerleri sonlu bir kümedense değerleri açıklamada listelemek yerine (ör.enum "type": "enum", "values": ["now_playing", "upcoming"]). Parametre değeri her zaman tam sayıysa türü number yerine integer olarak ayarlayın.
        • description (dize): Parametrenin amacı ve beklenen biçimiyle ilgili net bir açıklama.
          • En iyi uygulama: Somut örnekler ve kısıtlamalar 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 kullanın.
    • required (dizi):
      • İşlevin çalışması için zorunlu olan parametre adlarını listeleyen dize dizisi.

Kullanıcı istemi

En iyi sonuçlar için aşağıdaki ayrıntıları içeren kullanıcı sorgusunun başına 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ı belirsizse aydınlatıcı sorular sormaya yönelik talimatlar. Örneğin, 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, modele daha güvenli sonuçlar üretmesini ve halüsinasyonları azaltmasını sağlar.

API çağrısı

Model; sipariş gönderecek, veritabanını güncelleyecek veya başka şekilde önemli sonuçları olacak bir işlevin çağrılmasını öneriyorsa işlev çağrısını, yürütmeden önce kullanıcıyla doğrulayın.