함수 호출은 관련성이 있는 상황별 답변을 제공하는 LLM의 기능을 향상시킵니다.
Function Calling API를 사용하여 커스텀 함수를 생성형 AI 모델에 제공할 수 있습니다. 모델은 이러한 함수를 직접 호출하지 않지만 대신 함수 이름과 추천 인수를 지정하는 구조화된 데이터 출력을 생성합니다.
이 출력을 통해 외부 API 또는 정보 시스템(예: 데이터베이스, 고객 관계 관리 시스템, 문서 저장소)을 호출할 수 있습니다. LLM에서 응답 품질을 개선하는 데 결과 API 출력을 사용할 수 있습니다.
함수 호출에 관한 개념적 문서는 함수 호출을 참고하세요.
지원되는 모델
- Gemini 2.5 Flash (프리뷰)
- Gemini 2.5 Flash-Lite (프리뷰)
- Gemini 2.5 Flash-Lite
- Live API 네이티브 오디오를 사용한 Gemini 2.5 Flash (프리뷰)
- Live API를 사용한 Gemini 2.0 Flash (프리뷰)
- Gemini 2.5 Pro
- Gemini 2.5 Flash
- Gemini 2.0 Flash
- Gemini 2.0 Flash-Lite
제한사항:
- 요청에 제공할 수 있는 최대 함수 선언 수는 128개입니다.
예시 구문
함수 호출 API 요청을 보내는 구문입니다.
curl
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/publishers/google/models/${MODEL_ID}:generateContent \ -d '{ "contents": [{ ... }], "tools": [{ "function_declarations": [ { ... } ] }] }'
매개변수 목록
구현 세부정보는 예시를 참고하세요.
FunctionDeclaration
OpenAPI 3.0 사양에 따라 모델에서 JSON 입력을 생성할 수 있는 함수를 정의합니다.
| 파라미터 | |
|---|---|
|
호출하려는 함수의 이름입니다. 문자 또는 밑줄로 시작해야 하며 a~z, A~Z, 0~9이거나 밑줄, 점 또는 대시를 포함할 수 있고 최대 64자 길이입니다. |
|
(선택사항) 함수 설명 및 용도입니다. 모델은 이를 사용하여 함수를 호출할지 여부와 방법을 결정합니다. 최상의 결과를 얻으려면 설명을 포함하는 것이 좋습니다. |
|
(선택사항) 함수 파라미터를 OpenAPI JSON 스키마 객체 형식인 OpenAPI 3.0 사양으로 설명합니다. |
|
선택사항: 함수의 출력을 OpenAPI JSON 스키마 객체 형식인 OpenAPI 3.0 사양으로 설명합니다. |
자세한 내용은 함수 호출을 참조하세요.
Schema
OpenAPI 3.0 스키마 사양에 따라 함수 호출에서 입력 및 출력 데이터의 형식을 정의합니다.
| 파라미터 | |
|---|---|
| 유형 |
Enum. 데이터 유형입니다. 다음 중 하나여야 합니다.
|
description |
(선택사항) 데이터에 대한 설명입니다. |
enum |
(선택사항) enum 형식의 기본 유형 요소의 가능한 값입니다. |
items |
(선택사항)
|
properties |
(선택사항)
|
required |
(선택사항)
|
nullable |
(선택사항) 값이 |
FunctionCallingConfig
FunctionCallingConfig는 모델의 동작을 제어하고 호출할 함수 유형을 결정합니다.
| 파라미터 | |
|---|---|
|
(선택사항)
|
|
(선택사항) 호출할 함수 이름입니다. |
functionCall
functionDeclaration.name을 나타내는 문자열 및 파라미터와 해당 값이 포함된 구조화된 JSON 객체를 포함하는 모델에서 반환된 예측된 functionCall입니다.
| 파라미터 | |
|---|---|
|
호출하려는 함수의 이름입니다. |
|
JSON 객체 형식의 함수 파라미터와 값입니다. 매개변수 세부정보는 함수 호출을 참조하세요. |
functionResponse
FunctionDeclaration.name을 나타내는 문자열이 포함된 FunctionCall의 결과 출력입니다. 함수의 출력이 포함된 정형 JSON 객체도 포함되며 이를 모델의 컨텍스트로 사용합니다. 여기에는 모델 예측을 기반으로 한 FunctionCall의 결과가 포함되어야 합니다.
| 파라미터 | |
|---|---|
|
호출하려는 함수의 이름입니다. |
|
JSON 객체 형식의 함수 응답입니다. |
예시
함수 선언 전송
다음은 쿼리 및 함수 선언을 모델에 전송하는 기본 예시입니다.
REST
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- PROJECT_ID: 프로젝트 ID
- MODEL_ID: 처리 중인 모델의 ID
- ROLE: 메시지를 만드는 항목의 ID
- TEXT: 모델에 전송할 프롬프트
- NAME: 호출하려는 함수의 이름
- DESCRIPTION: 함수 설명 및 용도
- 다른 필드에 대해서는 파라미터 목록 테이블을 참고하세요.
HTTP 메서드 및 URL:
POST https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/publishers/google/models/MODEL_ID:generateContent
JSON 요청 본문:
{
"contents": [{
"role": "ROLE",
"parts": [{
"text": "TEXT"
}]
}],
"tools": [{
"function_declarations": [
{
"name": "NAME",
"description": "DESCRIPTION",
"parameters": {
"type": "TYPE",
"properties": {
"location": {
"type": "TYPE",
"description": "DESCRIPTION"
}
},
"required": [
"location"
]
}
}
]
}]
}
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/publishers/google/models/MODEL_ID:generateContent"
PowerShell
요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/publishers/google/models/MODEL_ID:generateContent" | Select-Object -Expand Content
curl 명령어 예시
PROJECT_ID=myproject
LOCATION=us-central1
MODEL_ID=gemini-2.5-flash
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/publishers/google/models/${MODEL_ID}:generateContent \
-d '{
"contents": [{
"role": "user",
"parts": [{
"text": "What is the weather in Boston?"
}]
}],
"tools": [{
"functionDeclarations": [
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
}
},
"required": [
"location"
]
}
}
]
}]
}'
Python용 Gen AI SDK
Node.js
자바
Go
REST(OpenAI)
OpenAI 라이브러리를 사용하여 Function Calling API를 호출할 수 있습니다. 자세한 내용은 OpenAI 라이브러리를 사용하여 Vertex AI 모델 호출을 참조하세요.
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- PROJECT_ID: .
- MODEL_ID: 처리 중인 모델의 ID
HTTP 메서드 및 URL:
POST https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/endpoints/openapi/chat/completions
JSON 요청 본문:
{
"model": "google/MODEL_ID",
"messages": [
{
"role": "user",
"content": "What is the weather in Boston?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "OBJECT",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
}
},
"required": ["location"]
}
}
}
]
}
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/endpoints/openapi/chat/completions"
PowerShell
요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/endpoints/openapi/chat/completions" | Select-Object -Expand Content
Python(OpenAI)
OpenAI 라이브러리를 사용하여 Function Calling API를 호출할 수 있습니다. 자세한 내용은 OpenAI 라이브러리를 사용하여 Vertex AI 모델 호출을 참조하세요.
FunctionCallingConfig를 사용하여 함수 선언 전송
다음은 FunctionCallingConfig를 모델에 전달하는 방법을 보여주는 예시입니다.
functionCallingConfig는 모델 출력이 항상 특정 함수 호출이 되도록 확인합니다. 구성 방법:
- 호출 함수
mode를ANY로 설정합니다. allowed_function_names에서 사용할 함수 이름을 지정합니다.allowed_function_names가 비어 있으면 제공된 함수 중 하나가 반환될 수 있습니다.
REST
PROJECT_ID=myproject
LOCATION=us-central1
MODEL_ID=gemini-2.5-flash
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://${LOCATION}-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${LOCATION}/publishers/google/models/${MODEL_ID}:generateContent \
-d '{
"contents": [{
"role": "user",
"parts": [{
"text": "Do you have the White 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"}
}
}
},
{
"name": "get_store_location",
"description": "Get the location of the closest store",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "Location"}
},
}
}
]
}],
"toolConfig": {
"functionCallingConfig": {
"mode":"ANY",
"allowedFunctionNames": ["get_product_sku"]
}
},
"generationConfig": {
"temperature": 0.95,
"topP": 1.0,
"maxOutputTokens": 8192
}
}'
Python용 Gen AI SDK
Node.js
Go
REST(OpenAI)
OpenAI 라이브러리를 사용하여 Function Calling API를 호출할 수 있습니다. 자세한 내용은 OpenAI 라이브러리를 사용하여 Vertex AI 모델 호출을 참조하세요.
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- PROJECT_ID: .
- MODEL_ID: 처리 중인 모델의 ID
HTTP 메서드 및 URL:
POST https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/endpoints/openapi/chat/completions
JSON 요청 본문:
{
"model": "google/MODEL_ID",
"messages": [
{
"role": "user",
"content": "What is the weather in Boston?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "OBJECT",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
}
},
"required": ["location"]
}
}
}
],
"tool_choice": "auto"
}
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/endpoints/openapi/chat/completions"
PowerShell
요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/endpoints/openapi/chat/completions" | Select-Object -Expand Content
Python(OpenAI)
OpenAI 라이브러리를 사용하여 Function Calling API를 호출할 수 있습니다. 자세한 내용은 OpenAI 라이브러리를 사용하여 Vertex AI 모델 호출을 참조하세요.
다음 단계
자세한 문서는 다음을 참조하세요.