이 문서는 영어 원문을 자동 번역한 것으로, 내용이 원문과 다를 수 있습니다.영어 원문 보기
예시
요청
# pip install openai
from openai import OpenAI # openai==1.52.2
client = OpenAI(
api_key="UPSTAGE_API_KEY",
base_url="https://api.upstage.ai/v1"
)
stream = client.chat.completions.create(
model="solar-pro4",
messages=[
{
"role": "user",
"content": "Hi, how are you?"
}
],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="")
# Use with stream=False
# print(stream.choices[0].message.content)응답
{
"id": "75c4def7-5cc8-43eb-9558-545009063a3b",
"object": "chat.completion",
"created": 1785952894,
"model": "solar-pro4-260806",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! I'm doing well, thank you for asking. I'm an AI assistant, so I'm always ready to help you with whatever you need. How are you doing today? Is there anything specific I can assist you with?",
"reasoning": "The user is asking a simple greeting question. I should respond warmly and briefly.\n"
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 57,
"completion_tokens": 66,
"total_tokens": 123,
"prompt_tokens_details": {
"cached_tokens": 0,
"audio_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 17,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
}
},
"system_fingerprint": null
}