from openai import OpenAI
import random
if __name__ == '__main__':
client = OpenAI(api_key="the_key", base_url="the_url")
messages = []
while True:
question = input('请输入问题:')
messages.append({"role": "user", "content": question})
# print(messages)
response = client.chat.completions.create(
messages=messages,
model='the_model', frequency_penalty=1, presence_penalty=1)
result = response.choices[0].message.content # .lstrip('<think>').strip().lstrip('</think>').strip()
messages.append({"role": "assistant", "content": result})
print("大模型回复:" + result)
OpenAI接口,多轮对话调用
最新推荐文章于 2025-07-29 16:29:35 发布