python如何调用ai连续对话
import openai
import time
打印openai的版本
print(openai.version)
client = openai.OpenAI(
base_url="https://zzzzapi.com/v1",
api_key="sk-xxx"
)
messages = [
{"role": "system", "content": "You are a helpful assistant."}
]
while True:
user_input = input("You: ")
messages.append({"role": "user", "content": user_input})
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=messages,
temperature=1
)
assistant_response = response.choices[0].message.content
print(f"Assistant: {assistant_response}")
messages.append({"role": "assistant", "content": assistant_response})
time.sleep(1)
#我使用的 中转ai:https://zzzzapi.com
浏览 (48)
点赞
收藏