שיפור בקשות להפעלת פונקציות

הפעלת פונקציות מאפשרת ליצור אפליקציות וסוכנים מבוססי Gemini שיכולים ליצור אינטראקציה עם מידע ושירותים בזמן אמת, כמו מסדי נתונים, מערכות לניהול קשרי לקוחות ומאגרי מסמכים. כך משפרים את היכולת של האפליקציה לספק תשובות רלוונטיות ותלויות-הקשר.

באמצעות כוונון עדין מפוקח, אתם יכולים להשתמש במערך נתונים משלכם לכוונון כדי לשפר את הדיוק הכולל של התשובות שמבוססות על קריאות לפונקציות באפליקציה שלכם.

פורמט מערך הנתונים של ההתאמה

הערך fileUri של מערך הנתונים לכוונון עדין יכול להיות ה-URI של קובץ בקטגוריה של Cloud Storage, או כתובת URL של HTTP או HTTPS שזמינה לציבור.

כדי לראות דוגמה לפורמט כללי, אפשר לעיין בדוגמה של מערך נתונים ל-Gemini.

בקטעים הבאים מוצגות דוגמאות למערכי נתונים של קריאות לפונקציות, שאפשר להשתמש בהם ליצירת משימת התאמה עדינה לקריאות לפונקציות.

התאמת השימוש בפונקציות ליצירת טקסט

הדוגמה הבאה היא של מערך נתונים לכוונון הפעלת פונקציות כדי ליצור תשובה אחת בטקסט.

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

התאמת השימוש בפונקציות לתמיכה בשיחת צ'אט

הדוגמה הבאה היא של מערך נתונים לכוונון הפעלת פונקציות כדי לתמוך בשיחת צ'אט.

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

כוונון של בקשות מקבילות להפעלת פונקציות

הדוגמה הבאה היא של מערך נתונים לכוונון של קריאות פונקציות מקבילות.

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

המאמרים הבאים