GigaChat
GigaChat
GigaChat은 러시아 최고 LLM 제공자 Sber AI의 대형 언어 모델이에요. 모든 GigaChat 모델을 지원해요. litellm 요청 시 model=gigachat/<any-model-on-gigachat> 접두사로 설정하기만 하면 돼요.
⚠️ GigaChat API는 자체 서명 SSL 인증서를 사용해요. 요청에
ssl_verify=False를 반드시 전달해야 해요.
출처: 문서
본문
지원 기능 (Supported Features)
| 기능 | 지원 |
|---|---|
| Chat 완성 | 예 |
| 스트리밍 | 예 |
| 비동기 | 예 |
| Function Calling / Tools | 예 |
| 구조화 출력 (JSON Schema) | 예 (function call 에뮬레이션으로) |
| 이미지 입력 | 예 (base64 및 URL) - GigaChat-2-Max, GigaChat-2-Pro만 |
| Embeddings | 예 |
API 키
GigaChat은 OAuth 인증을 사용해요. 자격 증명을 환경 변수로 설정하세요:
import os
# Required: Set credentials (base64-encoded client_id:client_secret)
os.environ['GIGACHAT_CREDENTIALS'] = "your-credentials-here"
# Optional: Set scope (default is GIGACHAT_API_PERS for personal use)
os.environ['GIGACHAT_SCOPE'] = "GIGACHAT_API_PERS" # or GIGACHAT_API_B2B for business
자격 증명은 https://developers.sber.ru/studio/ 에서 얻을 수 있어요.
샘플 사용법 (Sample Usage)
from litellm import completion
import os
os.environ['GIGACHAT_CREDENTIALS'] = "your-credentials-here"
response = completion(
model="gigachat/GigaChat-2-Max",
messages=[
{"role": "user", "content": "Hello from LiteLLM!"}
],
ssl_verify=False, # Required for GigaChat
)
print(response)
샘플 사용법 - 스트리밍 (Streaming)
from litellm import completion
import os
os.environ['GIGACHAT_CREDENTIALS'] = "your-credentials-here"
response = completion(
model="gigachat/GigaChat-2-Max",
messages=[
{"role": "user", "content": "Hello from LiteLLM!"}
],
stream=True,
ssl_verify=False, # Required for GigaChat
)
for chunk in response:
print(chunk)
샘플 사용법 - Function Calling
from litellm import completion
import os
os.environ['GIGACHAT_CREDENTIALS'] = "your-credentials-here"
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"}
},
"required": ["city"]
}
}
}]
response = completion(
model="gigachat/GigaChat-2-Max",
messages=[{"role": "user", "content": "What's the weather in Moscow?"}],
tools=tools,
ssl_verify=False, # Required for GigaChat
)
print(response)
샘플 사용법 - 구조화 출력
GigaChat은 JSON schema를 통한 구조화 출력을 지원해요 (function calling으로 에뮬레이션).
from litellm import completion
import os
os.environ['GIGACHAT_CREDENTIALS'] = "your-credentials-here"
response = completion(
model="gigachat/GigaChat-2-Max",
messages=[{"role": "user", "content": "Extract info: John is 30 years old"}],
response_format={
"type": "json_schema",
"json_schema": {
"name": "person",
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"}
}
}
}
},
ssl_verify=False, # Required for GigaChat
)
print(response) # Returns JSON: {"name": "John", "age": 30}
샘플 사용법 - 이미지 입력
GigaChat은 base64 또는 URL로 이미지 입력을 지원해요 (GigaChat-2-Max, GigaChat-2-Pro만).
from litellm import completion
import os
os.environ['GIGACHAT_CREDENTIALS'] = "your-credentials-here"
response = completion(
model="gigachat/GigaChat-2-Max", # Vision requires GigaChat-2-Max or GigaChat-2-Pro
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}],
ssl_verify=False, # Required for GigaChat
)
print(response)
샘플 사용법 - Embeddings
from litellm import embedding
import os
os.environ['GIGACHAT_CREDENTIALS'] = "your-credentials-here"
response = embedding(
model="gigachat/Embeddings",
input=["Hello world", "How are you?"],
ssl_verify=False, # Required for GigaChat
)
print(response)
LiteLLM Proxy 사용법
1. config.yaml에 GigaChat 모델 설정
model_list:
- model_name: gigachat
litellm_params:
model: gigachat/GigaChat-2-Max
api_key: "os.environ/GIGACHAT_CREDENTIALS"
ssl_verify: false
- model_name: gigachat-lite
litellm_params:
model: gigachat/GigaChat-2-Lite
api_key: "os.environ/GIGACHAT_CREDENTIALS"
ssl_verify: false
- model_name: gigachat-embeddings
litellm_params:
model: gigachat/Embeddings
api_key: "os.environ/GIGACHAT_CREDENTIALS"
ssl_verify: false
2. Proxy 시작
litellm --config config.yaml
3. 테스트
curl:
curl --location 'http://0.0.0.0:4000/chat/completions' \
--header 'Content-Type: application/json' \
--data '{
"model": "gigachat",
"messages": [
{
"role": "user",
"content": "Hello!"
}
]
}'
OpenAI v1.0.0+:
import openai
client = openai.OpenAI(
api_key="anything",
base_url="http://0.0.0.0:4000"
)
response = client.chat.completions.create(
model="gigachat",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response)
지원 모델 (Supported Models)
Chat 모델
| 모델 이름 | 컨텍스트 창 | 비전 | 설명 |
|---|---|---|---|
| gigachat/GigaChat-2-Lite | 128K | 아니오 | 빠르고 가벼운 모델 |
| gigachat/GigaChat-2-Pro | 128K | 예 | 비전이 있는 프로페셔널 모델 |
| gigachat/GigaChat-2-Max | 128K | 예 | 최대 성능 모델 |
Embedding 모델
| 모델 이름 | 최대 입력 | 차원 | 설명 |
|---|---|---|---|
| gigachat/Embeddings | 512 | 1024 | 표준 임베딩 |
| gigachat/Embeddings-2 | 512 | 1024 | 업데이트된 임베딩 |
| gigachat/EmbeddingsGigaR | 4096 | 2560 | 고차원 임베딩 |
사용 가능한 모델은 API 접근 수준(개인 또는 비즈니스)에 따라 다를 수 있어요.