This commit is contained in:
Ivan Office
2023-08-18 06:51:35 +08:00
parent db2fb13343
commit f7a0f2eac6

View File

@@ -92,7 +92,7 @@ class Channel(models.Model):
result.append((c.id, "%s%s" % (pre, c.name or '')))
return result
def get_openai_context(self, channel_id, author_id, answer_id, minutes=30, chat_count=1):
def get_openai_context(self, channel_id, author_id, answer_id, minutes=30, chat_count=0):
# 上下文处理,要处理群的方式,以及独聊的方式
# azure新api 处理
context_history = []
@@ -115,6 +115,9 @@ class Channel(models.Model):
domain = expression.AND([domain, [('date', '>=', afterTime)]])
else:
domain = expression.AND([domain, [('author_id', '=', answer_id.id)]])
if chat_count == 0:
ai_msg_list = []
else:
ai_msg_list = message_model.with_context(tz='UTC').search(domain, order="id desc", limit=chat_count)
for ai_msg in ai_msg_list:
# 判断这个 ai_msg 是不是ai发有才 insert。 判断 user_msg 是不是 user发的有才 insert
@@ -262,7 +265,7 @@ class Channel(models.Model):
openai.api_key = api_key
# 非4版本取0次。其它取3 次历史
chat_count = 3
if '4' in ai.ai_model:
if '4' in ai.ai_model or '4' in ai.name:
chat_count = 1
if hasattr(self, 'chat_count'):
if self.chat_count > 0: