我使用以下代码基于OpenAI创建了一个基本的聊天机器人:
import openai
openai.api_key = "sk-xxx"
while True:
prompt = input("User:")
response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
max_tokens=50,
temperature=0,
)
print(response.choices[0].text)
这是输入和输出:
并以文本形式:
User:What is python
Python is a high-level, interpreted, general-purpose programming language. It is a powerful and versatile language that is used for a wide range of applications, from web development and software development to data science and machine learning.`
User:What is the Latest Version of it?
The latest version of Microsoft Office is Microsoft Office 2019.
正如您所看到的,我正在提出与Python相关的问题,并且询问其版本时,答案却与Microsoft Office有关。然而,当我向ChatGpt提出同样的问题时,它会记住先前的对话并根据其行事。
是否有任何解决方案来记住对话?