Gemini API की मदद से, फ़ंक्शन कॉल करने के बारे में जानकारी

फ़ंक्शन का इस्तेमाल करके, Gemini मॉडल को कस्टम फ़ंक्शन तय किए जा सकते हैं और दिए जा सकते हैं कॉल करने की सुविधा. मॉडल सीधे तौर पर इन फ़ंक्शन को शुरू नहीं करते हैं. इसके बजाय, ये सीधे तौर पर इन फ़ंक्शन को शुरू करते हैं ऐसा स्ट्रक्चर्ड डेटा आउटपुट जनरेट करता है जो फ़ंक्शन के नाम और सुझाए गए विकल्पों की जानकारी देता है आर्ग्युमेंट. इस आउटपुट से आप ऐसे ऐप्लिकेशन लिख सकते हैं जो स्ट्रक्चर्ड आउटपुट और कॉल बाहरी API को कॉल करता है, और फिर परिणाम में बनने वाला API आउटपुट इसे एक आगे के मॉडल प्रॉम्प्ट में शामिल किया गया है, जो ज़्यादा व्यापक क्वेरी की अनुमति देता है जवाब. फ़ंक्शन कॉलिंग की मदद से, उपयोगकर्ता रीयल-टाइम में इंटरैक्ट कर सकते हैं जानकारी और विविध सेवाएं, जैसे डेटाबेस, ग्राहक संबंध और दस्तावेज़ का डेटा स्टोर करने की जगहों को मैनेज कर सकता है, ताकि काम के और कॉन्टेक्स्ट के हिसाब से जवाब उपलब्ध कराएं.

फ़ंक्शन कॉलिंग की सुविधा कैसे काम करती है

यह जानकारी देने वाला स्ट्रक्चर्ड क्वेरी डेटा जोड़कर, फ़ंक्शन कॉलिंग की सुविधा का इस्तेमाल किया जाता है प्रोग्रामिंग इंटरफ़ेस, जिन्हें फ़ंक्शन डिक्लेरेशन कहते हैं. इन्हें मॉडल प्रॉम्प्ट में जोड़ा जाता है. कॉन्टेंट बनाने फ़ंक्शन एलान में एपीआई फ़ंक्शन का नाम बताया जाता है और इसके मकसद के बारे में बताया जाता है. और उन पैरामीटर के बारे में जानकारी. पास हो जाने के बाद मॉडल के लिए क्वेरी में फ़ंक्शन एलान की सूची, यह फ़ंक्शन का विश्लेषण करती है एलानों और बाकी क्वेरी का इस्तेमाल करके, अनुरोध के जवाब में एपीआई.

इसके बाद मॉडल, OpenAPI के साथ काम करने वाला स्कीमा बताया गया है कि जवाब देने के लिए, एक या उससे ज़्यादा एलान किए गए फ़ंक्शन को कैसे कॉल करें उपयोगकर्ता के सवालों के जवाब देना. इसके बाद, सुझाए गए फ़ंक्शन कॉल पैरामीटर, वास्तविक API को कॉल करें, प्रतिक्रिया पाएं, और वह प्रतिक्रिया या आगे की कार्रवाई करें. ध्यान दें कि मॉडल वास्तव में बताए गए फ़ंक्शन. इसके बजाय, लौटाए गए स्कीमा ऑब्जेक्ट पैरामीटर का इस्तेमाल इन कामों के लिए किया जाता है फ़ंक्शन को कॉल करें. Gemini API, पैरलल फ़ंक्शन कॉलिंग की सुविधा भी देता है. यह मॉडल एक ही अनुरोध के आधार पर कई एपीआई फ़ंक्शन कॉल का सुझाव देता है.

इस्तेमाल किए जा सकने वाले मॉडल

ये मॉडल, फ़ंक्शन कॉलिंग की सुविधा के साथ काम करते हैं:

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

फ़ंक्शन का एलान

किसी प्रॉम्प्ट में फ़ंक्शन कॉल करने की सुविधा लागू करने पर, tools ऑब्जेक्ट बनाया जाता है, जिसमें एक या एक से ज़्यादा function declarations शामिल हैं. फ़ंक्शन तय करने के लिए JSON का इस्तेमाल करके, खास तौर पर सबसेट चुनें का तरीका OpenAPI स्कीमा फ़ॉर्मैट. एक फ़ंक्शन के एलान में ये पैरामीटर शामिल हो सकते हैं:

  • name (स्ट्रिंग): एपीआई में मौजूद फ़ंक्शन के लिए यूनीक आइडेंटिफ़ायर कॉल.
  • description (स्ट्रिंग): फ़ंक्शन के बारे में पूरी जानकारी मकसद और क्षमताओं को पूरा करता हो.
  • parameters (ऑब्जेक्ट): फ़ंक्शन के लिए ज़रूरी इनपुट डेटा के बारे में बताता है.
    • type (स्ट्रिंग): इससे, कुल डेटा टाइप की जानकारी मिलती है, जैसे कि object.
    • properties (object): इसमें अलग-अलग पैरामीटर की सूची होती है. हर पैरामीटर में:
      • type (स्ट्रिंग): पैरामीटर का डेटा टाइप, जैसे कि string, integer, और boolean.
      • description (स्ट्रिंग): पैरामीटर की साफ़ तौर पर जानकारी का इस्तेमाल करें.
    • required (अरे): स्ट्रिंग का कलेक्शन, जिसमें पैरामीटर के नाम होते हैं जो इस फ़ंक्शन के काम करने के लिए ज़रूरी हैं.

cURL कमांड का इस्तेमाल करके फ़ंक्शन की जानकारी देने वाले कोड के उदाहरणों के लिए, फ़ंक्शन कॉलिंग के उदाहरण. उदाहरण के लिए और दूसरे प्लैटफ़ॉर्म के लिए फ़ंक्शन एलान बनाने की जानकारी देखें, तो फ़ंक्शन कॉलिंग प्लैटफ़ॉर्म की गाइड.

फ़ंक्शन का एलान करने के लिए सबसे सही तरीके

अपने अनुरोध. हर फ़ंक्शन खास पैरामीटर पर निर्भर करता है, जो इसके व्यवहार को गाइड करते हैं मॉडल के साथ इंटरैक्शन करते हैं. नीचे दी गई लिस्टिंग में, इन विषयों के बारे में दिशा-निर्देश दिए गए हैं functions_declarations में किसी फ़ंक्शन के पैरामीटर तय करें अरे.

  • name: बिना खाली जगह और सटीक जानकारी देने वाले नाम इस्तेमाल करें (.) या डैश (-) वर्ण इस्तेमाल करें. इसके बजाय, अंडरस्कोर (_) वर्णों का इस्तेमाल करें या ऊंट जैसा.

  • description: फ़ंक्शन में पूरी, सही, और सटीक जानकारी दें और ज़रूरी होने पर उदाहरण दें. उदाहरण के लिए, find theaters, find theaters based on location and optionally movie title that is currently playing in theaters. का इस्तेमाल करें. इसमें ज़्यादा जानकारी शामिल न करें ब्यौरे.

  • properties > type: वैल्यू को कम करने के लिए, बहुत ज़्यादा टाइप किए गए पैरामीटर का इस्तेमाल करें गलत जानकारी. उदाहरण के लिए, अगर पैरामीटर वैल्यू सेट करें, ब्यौरे में वैल्यू डालने के बजाय enum फ़ील्ड का इस्तेमाल करें (उदाहरण के लिए, "type": "enum", "values": ["now_playing", "upcoming"]). अगर पैरामीटर का मान हमेशा एक पूर्णांक होता है. इसके बजाय, टाइप को integer पर सेट करें number.

  • properties > description: सटीक उदाहरण और शर्तें बताएं. उदाहरण के लिए, the location to search के बजाय The city and state, e.g. San Francisco, CA or a zip code e.g. 95616 का इस्तेमाल करें.

फ़ंक्शन कॉलिंग का इस्तेमाल करते समय ज़्यादा सबसे सही तरीकों के बारे में जानने के लिए, सबसे सही तरीके सेक्शन.

फ़ंक्शन कॉलिंग मोड

कोड को एक्ज़ीक्यूट करने के तरीके में बदलाव करने के लिए, फ़ंक्शन कॉलिंग mode पैरामीटर का इस्तेमाल किया जा सकता है सुविधा का व्यवहार. तीन मोड उपलब्ध हैं:

  • AUTO: यह मॉडल का डिफ़ॉल्ट व्यवहार होता है. मॉडल यह अनुमान लगाता है कि फ़ंक्शन कॉल या आम बोलचाल वाली भाषा में जवाब देना.
  • ANY: इस मॉडल को हमेशा फ़ंक्शन कॉल का अनुमान लगाने की अनुमति है. अगर आपने allowed_function_names की जानकारी नहीं दी गई है, यह मॉडल सभी उपलब्ध फ़ंक्शन एलान. अगर allowed_function_names दिया गया है तो, मॉडल, अनुमति वाले फ़ंक्शन के सेट में से कोई विकल्प चुनता है.
  • NONE: यह मॉडल, फ़ंक्शन कॉल का अनुमान नहीं लगाएगा. इस मामले में, मॉडल यह वैसा ही होगा जैसे किसी फ़ंक्शन से जुड़ी जानकारी को पास नहीं किया जाता.

आप allowed_function_names का एक सेट भी पास कर सकते हैं, जिसे दिए जाने पर, सीमा फ़ंक्शन जिन्हें मॉडल कॉल करेगा. आपको सिर्फ़ इसे शामिल करना चाहिए मोड ANY होने पर, allowed_function_names. फ़ंक्शन के नाम मेल खाने चाहिए फ़ंक्शन की जानकारी के लिए नाम. जब मोड को ANY पर सेट किया गया हो और allowed_function_names सेट किया गया है, तो यह मॉडल फ़ंक्शन के नाम का सेट दिया गया है. एक अनुरोध के उदाहरण में बताया गया है कि mode को ANY पर सेट करता है और अनुमति वाले फ़ंक्शन की सूची के बारे में बताता है:

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

फ़ंक्शन कॉलिंग के उदाहरण

इस सेक्शन में, CURL कमांड का इस्तेमाल करके फ़ंक्शन कॉल करने के लिए प्रॉम्प्ट के उदाहरण दिए गए हैं. इसके उदाहरणों में एक मोड़ और एक से ज़्यादा मोड़ वाली स्थितियां शामिल हैं. साथ ही, कॉल करने के लिए अलग-अलग मोड हैं.

इस सुविधा के साथ cURL निर्देशों का इस्तेमाल करने पर, फ़ंक्शन और पैरामीटर tools एलिमेंट में जानकारी शामिल होती है. हर फ़ंक्शन की जानकारी tools एलिमेंट में फ़ंक्शन का नाम होता है और आपने इसका इस्तेमाल करके पैरामीटर तय किए हैं OpenAPI के साथ काम करने वाला स्कीमा, और फ़ंक्शन का ब्यौरा.

एक मोड़ वाला उदाहरण

एक टर्न तब होता है, जब भाषा के मॉडल को एक बार कॉल किया जाता है. फ़ंक्शन कॉलिंग के साथ, उस स्थिति में एक बार में इस्तेमाल का उदाहरण दिया जा सकता है, जब मॉडल क्वेरी और फ़ंक्शन की सूची देखें. इस मामले में, मॉडल एलान में, फ़ंक्शन का नाम, पैरामीटर, और ब्यौरा शामिल होता है. अनुमान लगाएं कि किस फ़ंक्शन को कॉल करना है और आर्ग्युमेंट के साथ कॉल करना है.

नीचे दिया गया कर्ल सैंपल, फ़ंक्शन, जो इस बारे में जानकारी देता है कि फ़िल्म कहां चल रही है. कई अनुरोध में फ़ंक्शन से जुड़ी जानकारी शामिल होती है, जैसे कि find_movies और find_theaters.

एक टर्न वाले फ़ंक्शन के लिए, अनुरोध का उदाहरण

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

इस कर्ल के उदाहरण के लिए रिस्पॉन्स कुछ ऐसा हो सकता है.

एक टर्न वाला फ़ंक्शन, जिसमें कर्ल के उदाहरण का जवाब दिया गया है

[{
  "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 तक:

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

किसी भी मोड का इस्तेमाल करके सिंगल-टर्न फ़ंक्शन कॉलिंग (अनुरोध)

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"
    },
  }
}'
    

रिस्पॉन्स, इससे मिलता-जुलता हो सकता है:

कोई भी मोड (रिस्पॉन्स) का इस्तेमाल करके सिंगल-टर्न फ़ंक्शन कॉलिंग

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

किसी भी मोड और अनुमति वाले फ़ंक्शन का इस्तेमाल करके एक मोड़ों वाला उदाहरण

नीचे दिए गए कर्ल का उदाहरण एक मोड़ वाला उदाहरण, लेकिन यह सेट हो जाता है mode से ANY और इसमें अनुमति वाली सूची की सूची शामिल है फ़ंक्शन:

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

किसी भी मोड और अनुमति वाले फ़ंक्शन (अनुरोध) का इस्तेमाल करके सिंगल-टर्न फ़ंक्शन कॉलिंग

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

यह मॉडल, find_movies फ़ंक्शन का अनुमान नहीं लगा सकता, क्योंकि यह सूची में शामिल नहीं है इसलिए, यह किसी दूसरे फ़ंक्शन का अनुमान लगाता है. जवाब नीचे दिए गए विकल्पों से मिलता-जुलता हो सकता है:

किसी भी मोड और अनुमति वाले फ़ंक्शन (रिस्पॉन्स) का इस्तेमाल करके सिंगल-टर्न फ़ंक्शन कॉलिंग

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

मल्टी-टर्न के उदाहरण

एक से ज़्यादा टर्न वाले फ़ंक्शन को कॉल करने के लिए, ये काम किए जा सकते हैं:

  1. लैंग्वेज मॉडल को कॉल करके, फ़ंक्शन कॉल का जवाब पाएं. यह पहला टर्न.
  2. पहले मोड़ से मिले फ़ंक्शन कॉल के जवाब का इस्तेमाल करके, लैंग्वेज मॉडल को कॉल करें और उस फ़ंक्शन को कॉल करने पर आपको मिलने वाला फंक्शन रिस्पॉन्स. यह है दूसरी बारी.

दूसरी बारी में मिले जवाब में आपको कम शब्दों में क्वेरी को पहली बार में क्वेरी आती है या उसमें कोई दूसरा फ़ंक्शन कॉल शामिल है, जिसका उपयोग आप आपकी क्वेरी के लिए ज़्यादा जानकारी.

इस विषय में मल्टी-टर्न कर्ल के दो उदाहरण शामिल हैं:

पिछली क्वेरी के जवाब का इस्तेमाल करें

नीचे दिया गया कर्ल सैंपल, फ़ंक्शन और आर्ग्युमेंट को पिछले एक टर्न वाला उदाहरण देखें. तरीका और पैरामीटर एक टर्न वाले उदाहरण से मिले नतीजे, इस JSON में दिए गए हैं.

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

मल्टी-टर्न फ़ंक्शन कॉल करने की सुविधा देने वाले यूआरएल का उदाहरण

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

इस कर्ल उदाहरण के लिए प्रतिक्रिया के रूप में find_theaters तरीका. रिस्पॉन्स, इससे मिलता-जुलता हो सकता है:

मल्टी-टर्न फ़ंक्शन कॉल करने की सुविधा देने वाले यूआरएल का उदाहरण

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

मॉडल को कई बार कॉल करें

इस cURL के उदाहरण में, कॉल करने के लिए जनरेटिव एआई मॉडल को कई बार इस्तेमाल किया गया है एक फ़ंक्शन का इस्तेमाल करें. जब भी मॉडल, फ़ंक्शन को कॉल करता है, तो यह फ़ंक्शन का इस्तेमाल करें.

मल्टी-टर्न फ़ंक्शन कॉल करने की सुविधा देने वाले यूआरएल का उदाहरण

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

मल्टी-टर्न फ़ंक्शन कॉल करने की सुविधा देने वाले यूआरएल का उदाहरण

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

सबसे सही तरीके

ज़्यादा सटीक जानकारी पाने के लिए, आपके फ़ंक्शन कॉल की विश्वसनीयता.

उपयोगकर्ता का अनुरोध

सबसे अच्छे नतीजों के लिए, उपयोगकर्ता क्वेरी के शुरू में नीचे दी गई जानकारी जोड़ें:

  • मॉडल के लिए अतिरिक्त जानकारी. उदाहरण के लिए, You are a movie API assistant to help users find movies and showtimes based on their preferences.
  • फ़ंक्शन का इस्तेमाल कैसे और कब करना है, इस बारे में जानकारी या निर्देश. उदाहरण के लिए, Don't make assumptions on showtimes. Always use a future date for showtimes.
  • अगर उपयोगकर्ता की क्वेरी साफ़ तौर पर नहीं दी गई है, तो साफ़ तौर पर सवाल पूछने के लिए निर्देश. इसके लिए उदाहरण, Ask clarifying questions if not enough information is available to complete the request.

सैंपलिंग के पैरामीटर

तापमान पैरामीटर के लिए, 0 या कोई दूसरी कम वैल्यू इस्तेमाल करें. यह निर्देश देता है ताकि गलत जानकारी को कम किया जा सके और ज़्यादा भरोसेमंद नतीजे जनरेट किए जा सकें.

एपीआई शुरू करना

अगर मॉडल किसी ऐसे फ़ंक्शन को शुरू करने का सुझाव देता है जो ऑर्डर भेजता है, तो या किसी डेटाबेस को अपडेट करने के गंभीर नतीजे हो सकते हैं, तो फ़ंक्शन को एक्ज़ीक्यूट करने से पहले उपयोगकर्ता को इसकी जानकारी दें.