-
Notifications
You must be signed in to change notification settings - Fork 858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在使用chatgpt api时,支持发送上下文 #42
Conversation
will take a look tomorrow. |
感谢 PR 哈,有些小问题你可以先改一下。
|
l=len(self.history)这行代码确实没用。if(len(self.history)>=5)是为了最多只发送5条历史对话,否则可能超过4096token,也会浪费钱。写入文件是没有必要的,只是我为了方便查看。 |
ms.append({"role": "user", "content": h[0]}) | ||
ms.append({"role": "assistant", "content": h[1]}) | ||
ms.append({"role": "user", "content": f"{query}"}) | ||
completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=ms) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's recommend to define the model as constant, it will move to the config.json later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And how about this style
ms = []
if len(self.history) >= 5:
for i in range(-5, 0):
ms.append({"role": "user", "content": self.history[i][0]})
ms.append({"role": "assistant", "content": self.history[i][1]})
else:
for h in self.history:
ms.append({"role": "user", "content": h[0]})
ms.append({"role": "assistant", "content": h[1]})
ms.append({"role": "user", "content": f"{query}"})
completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=ms)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if self.history
is a list, you can use self.history[-5:]
ms = []
for h in self.history[-5:]:
ms.append({"role": "user", "content": h[0]})
ms.append({"role": "assistant", "content": h[1]})
ms.append({"role": "user", "content": f"{query}"})
completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=ms)
No description provided.