我们先来看官方文档的说明:
https://platform.openai.com/docs/guides/chat/introduction
> Chat models take a series of messages as input, and return a model-generated message as output.
>
> 聊天模型将一系列消息作为输入,并返回模型生成的消息作为输出。
下面是一个实现连续聊天的代码示例,主要看这个 messges 数组:
(首先根据这个github的项目拿到密钥:https://github.com/xing61/xiaoyi-robot)
# Note: you need to be using OpenAI Python v0.27.0 for the code below to work
import openaiAPI_SECRET_KEY = "你的智增增获取的api_key";
BASE_URL = "http://flag.smarttrot.com/index.php/api/v1"; #智增增的base_urlopenai.api_key = API_SECRET_KEY #
openai.api_base = BASE_URL #openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assis