-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
OpenAI不能进行上下文对话。可否修订一下? #193
Comments
连续上下文对话很容易超出max_tokens,所以可能不行。 |
果然被我言中了,我就问了2句(马斯克在忙啥,如何画画),就超过最大token了,我设的是4000 openai.error.InvalidRequestError: This model's maximum context length is 4097 tokens. However, you requested 4258 tokens (258 in the messages, 4000 in the completion). Please reduce the length of the messages or completion. |
上下文对话超出 token 数量是不可避免的,这种情况下只能丢弃,目前不存在其他取巧的办法。 master 分支已经加了丢弃会话的处理并自动重试。 另外,我问了半天都没有出现这个情况,是不是你生成的内容实在是太长了。 如果要限制一下一轮返回的字数,其实可以使用 "prefix" 参数:
|
我把这个prefix清空了,prefix: '' 我刚测试了加了丢弃后自动重试的程序了,重试后OPENai会有回答,但没有播放了出来。 |
看了下,丢弃的代码确实有问题,已经修复。提交到了主干。 |
确认已寻找过答案
chat.openai.com里面的聊天体验很棒,有上下文功能。以下是我找到的一段代码,可以实现这样的体验。单独使用挺好,我尝试加入到AI.py里,我水平有限,没搞成,大神看是否可以加入此功能。
import openai
openai.api_key = "********************"
text = "" #设置一个字符串变量
turns = [] #设置一个列表变量,turn指对话时的话轮
last_result = ""
def get_answer(question):
global text
global turns
global last_result
if name == 'main':
The text was updated successfully, but these errors were encountered: