大模型怎么实现连续对话(记忆上下文)
Chat models take a series of messages as input, and return a model-generated message as output.
聊天模型将一系列消息作为输入,并返回模型生成的消息作为输出。
import openai
from openai import OpenAI
API_SECRET_KEY = "你的智增增获取的api_key";
BASE_URL = "https://api.zhizengzeng.com/v1/"; #智增增的base_url
# 连续对话的实例,自己根据业务逻辑填充messages即可
def lianxu():
client = OpenAI(api_key=API_SECRET_KEY, base_url=BASE_URL)
resp = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
]
)
print(resp)
修改于 2024-05-15 01:30:51