Documentation Index
Fetch the complete documentation index at: https://translations.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
/chat/completions 엔드포인트를 사용하여 chat completion을 생성합니다. 이 엔드포인트는 메시지를 전송하고 응답을 받을 때 OpenAI와 호환되는 형식을 따릅니다.
chat completion을 생성하려면 다음을 제공해야 합니다:
- Inference 서비스 기본 URL:
https://api.inference.wandb.ai/v1
- W&B API key:
<your-api-key>
- 선택 사항: 사용할 W&B 팀과 프로젝트:
<your-team>/<your-project>
- 사용 가능한 모델 중 하나의 모델 ID
import openai
client = openai.OpenAI(
# 지정한 base URL은 W&B Inference를 가리킵니다
base_url='https://api.inference.wandb.ai/v1',
# https://wandb.ai/settings에서 API key를 생성하세요
# 보안을 위해 대신 OPENAI_API_KEY 환경 변수에 설정하는 것을 권장합니다
api_key="<your-api-key>",
# 선택 사항: 사용량 추적을 위한 팀과 프로젝트를 지정합니다
project="<your-team>/<your-project>",
)
# 사용 가능한 모델 목록에서 원하는 model ID로 <model-id>를 바꾸세요
response = client.chat.completions.create(
model="<model-id>",
messages=[
{"role": "system", "content": "<your-system-prompt>"},
{"role": "user", "content": "<your-prompt>"}
],
)
print(response.choices[0].message.content)
curl https://api.inference.wandb.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-api-key>" \
-H "OpenAI-Project: <your-team>/<your-project>" \
-d '{
"model": "<model-id>",
"messages": [
{ "role": "system", "content": "당신은 도움이 되는 어시스턴트입니다." },
{ "role": "user", "content": "농담 하나 해줘." }
]
}'
이 API는 OpenAI와 호환되는 형식으로 응답을 반환합니다.
{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1234567890,
"model": "meta-llama/Llama-3.1-8B-Instruct",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Here's a joke for you..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 50,
"total_tokens": 75
}
}