Gemini API를 사용한 함수 호출 소개

커스텀 함수를 정의하고 함수를 사용해 Gemini 모델에 제공할 수 있음 통화 기능 모델은 이러한 함수를 직접 호출하지 않고 대신 함수 이름과 추천 문장을 지정하는 구조화된 데이터 출력을 생성합니다. 인수입니다. 이 출력을 사용하면 구조화된 외부 API를 출력하고 호출할 수 있으며, 결과 API 출력은 모델을 추가 모델 프롬프트에 통합하여 보다 포괄적인 쿼리를 확인할 수 있습니다 함수 호출을 통해 사용자의 실시간 상호작용 지원 정보 및 다양한 서비스(예: 데이터베이스, 고객 관계) 문서 리포지토리에 대한 액세스를 제공하여 상황에 맞는 답변을 제공합니다

함수 호출 작동 방식

함수를 설명하는 구조화된 쿼리 데이터를 추가하여 함수 선언이라고 하는 프로그래밍 인터페이스를 모델 프롬프트에 추가합니다. 이 함수 선언은 API 함수의 이름을 제공하고, 함수의 목적을 설명합니다. 지원하는 매개변수와 해당 매개변수에 대한 설명 통과 후 모델에 대한 쿼리에서 함수 선언 목록을 생성하여 함수를 분석합니다. 선언과 쿼리의 나머지 부분을 함께 사용하여 선언된 API에서 실행됩니다.

그런 다음 모델은 OpenAPI 호환 스키마 응답하기 위해 하나 이상의 선언된 함수를 호출하는 방법 지정 사용자 질문에 답해야 합니다. 그런 다음 추천 함수 호출을 사용하여 실제 API를 호출하고 응답을 가져오고 해당 응답을 추가 조치를 취할 수 있습니다 모델은 실제로 선언한 함수와 일치해야 합니다. 대신 반환된 스키마 객체 매개변수를 사용하여 함수를 호출합니다. Gemini API는 병렬 함수 호출도 지원합니다. 모델이 단일 요청을 기반으로 여러 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 (문자열): API 내 함수의 고유 식별자입니다. 있습니다.
  • description (문자열): 함수의 함수에 대한 포괄적인 설명 목적과 역량을 갖추는 것입니다.
  • parameters (객체): 함수에 필요한 입력 데이터를 정의합니다.
    • type(문자열): 전반적인 데이터 유형을 지정합니다(예: object).
    • properties (객체): 각 매개변수를 나열하며, 각 매개변수는 다음과 같습니다.
      • 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가 설정되면 모델은 제공된 함수 이름 집합입니다. 다음 코드 스니펫은 요청 예modeANY로 설정하고 허용되는 함수 목록을 지정합니다.

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

함수 호출 예

이 섹션에서는 cURL 명령어를 사용한 함수 호출 프롬프트의 예를 제공합니다. 예에는 싱글턴 및 멀티턴 시나리오와 함수 호출 모드를 지원합니다.

이 기능과 함께 cURL 명령어를 사용하면 tools 요소에 포함됩니다. 위의 각 함수 선언은 tools 요소에 함수 이름이 포함되어 있으며, 사용자는 다음을 사용하여 매개변수를 지정합니다. OpenAPI 호환 스키마 그리고 함수 설명이 있습니다

싱글턴의 예

싱글턴은 언어 모델을 한 번 호출하는 경우입니다. 함수 호출의 경우 싱글턴 사용 사례는 모델에 자연어 쿼리와 함수 목록을 제공하는 것일 수 있습니다. 이 경우 모델은 선언을 포함하는데 이는 함수 이름, 매개변수, 설명이 포함된 호출할 함수와 이를 호출할 인수를 예측합니다.

다음 curl 샘플은 함수를 호출합니다. 요청에는 find_moviesfind_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"
            ]
          }
        }
      ]
    }
  ]
}'
    

이 curl 예시에 대한 응답은 다음과 유사할 수 있습니다.

싱글턴 함수 호출 curl 예시 응답

[{
  "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 모드를 사용하는 싱글턴 예

다음 curl 예는 싱글턴 예시이지만 모드ANY로 변경합니다.

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

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

응답은 다음과 비슷합니다.

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

ANY 모드 및 허용된 함수를 사용하는 싱글턴 예

다음 curl 예는 싱글턴 예시이지만 모드ANY로 변경하며 허용되는 함수:

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

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",
      "allowed_function_names": ["find_theaters", "get_showtimes"]
    },
  }
}'
    

find_movies 함수가 목록에 없으므로 모델에서 예측할 수 없습니다. 따라서 다른 함수를 예측합니다. 응답 다음과 유사할 수 있습니다.

ANY 모드 및 허용된 함수를 사용한 싱글턴 함수 호출 (응답)

{
  "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. 첫 번째 차례에서 함수 호출 응답과 해당 함수 호출에서 가져온 함수 응답을 사용하여 언어 모델을 호출합니다. 이것은 두 번째 회전

두 번째 차례의 응답은 를 포함할 수도 있고, 두 번째 함수 호출을 포함하여 추가 정보를 얻을 수 있습니다.

이 주제에는 다음과 같은 두 가지 멀티턴 curl 예시가 포함됩니다.

이전 회전의 응답 사용

다음 curl 샘플은 이전 싱글턴 예시를 사용하여 응답을 얻습니다. 메서드 및 매개변수 반환된 형식은 이 JSON에 해당합니다.

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

멀티턴 함수 호출 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"
            }]
          }
        }
      }
    }]
  }],
  "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 예에 대한 응답에는 find_theaters 메서드를 사용하여 지도 가장자리에 패딩을 추가할 수 있습니다. 응답은 다음과 비슷합니다.

멀티턴 함수 호출 curl 예시 응답

{
  "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 예시에서는 생성형 AI 모델을 여러 번 호출하여 함수입니다. 모델이 함수를 호출할 때마다 다른 함수를 사용하여 요청 시 다른 사용자 쿼리에 응답할 수 있습니다.

멀티턴 함수 호출 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"]
      }
    }]
  }]
}'
    

멀티턴 함수 호출 curl 예시 응답

[{
  "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 또는 다른 낮은 값을 사용합니다. 이렇게 하면 모델이 보다 신뢰할 수 있는 결과를 생성하도록 할 수 있고 할루시네이션을 줄일 수 있습니다.

API 호출

모델이 주문을 전송하거나, 데이터베이스를 업데이트하거나, 그 밖의 이유로 중대한 결과가 발생할 수 있는 함수의 호출을 제안하는 경우에는 이를 실행하기 전에 사용자와 함께 함수 호출 유효성을 검사합니다.