여러 라운드의 대화
/chat/completions
API를 사용하는 방법을 설명합니다./chat/completions
API는 "Stateless"API입니다. 즉, 서버는 사용자 요청의 컨텍스트를 기록하지 않습니다. 사용자가 요청할 때마다 이전 대화 기록을 모두 스플릿하고 대화 API에 전달해야합니다 .from openai import OpenAI
client = OpenAI(api_key="<DeepSeek API Key>", base_url="https://api.deepseek.com")
# Round 1
messages = [{"role": "user", "content": "What's the highest mountain in the world?"}]
response = client.chat.completions.create(
model="deepseek-chat",
messages=messages
)
messages.append(response.choices[0].message)
print(f"Messages Round 1: {messages}")
# Round 2
messages.append({"role": "user", "content": "What is the second?"})
response = client.chat.completions.create(
model="deepseek-chat",
messages=messages
)
messages.append(response.choices[0].message)
print(f"Messages Round 2: {messages}")
messages
다음과 같습니다.[
{"role": "user", "content": "What's the highest mountain in the world?"}
]
1.
messages
끝까지 추가하려면2.
messages
끝에 새로운 질문을 추가하십시오messages
마침내 API로 전달됩니다.[
{"role": "user", "content": "What's the highest mountain in the world?"},
{"role": "assistant", "content": "The highest mountain in the world is Mount Everest."},
{"role": "user", "content": "What is the second?"}
]
Modified at 3 months ago