优化请求内容上下文及顺序

This commit is contained in:
Chill
2023-04-14 17:03:35 +08:00
parent 54df2d515b
commit 02c2c984d0
2 changed files with 15 additions and 15 deletions

View File

@@ -1057,7 +1057,6 @@ MY
風騷欲女
毛郭伯雄
一九八九年六月四日
game master
龟头操进处女阴道
浪少妇和医生疯狂做爱
狭义道
@@ -1838,7 +1837,6 @@ tiang tang
喇嘛
體奸
u r靠
game MASTER
海盗时代
我和姨在车上干
赌马
@@ -5158,7 +5156,6 @@ renminbao
RMB
少妇房中自淫和两勇男玩17P操得直叫爽 操日本淫女穴
淫奸护士姐姐穴
game
情色电影网站
錘子
民主墙

View File

@@ -35,18 +35,20 @@ class Channel(models.Model):
domain += [('date', '>=', afterTime)]
ai_msg_list = message_model.with_context(tz='UTC').search(domain, order="id desc", limit=chat_count)
for ai_msg in ai_msg_list:
# todo: 判断这个 ai_msg 是不是ai发有才 insert。 判断 user_msg 是不是 user发的有才 insert
# 判断这个 ai_msg 是不是ai发有才 insert。 判断 user_msg 是不是 user发的有才 insert
user_msg = ai_msg.parent_id
user_content = user_msg.description.replace("<p>", "").replace("</p>", "").replace('@%s' % answer_id.name, '').lstrip()
ai_content = str(ai_msg.body).replace("<p>", "").replace("</p>", "").replace("<p>", "")
context_history.insert(0, {
'role': 'assistant',
'content': ai_content,
})
context_history.insert(0, {
'role': 'user',
'content': user_content,
})
if ai_msg.author_id.gpt_id:
ai_content = str(ai_msg.body).replace("<p>", "").replace("</p>", "").replace("<p>", "")
context_history.insert(0, {
'role': 'assistant',
'content': ai_content,
})
if not user_msg.author_id.gpt_id:
user_content = user_msg.description.replace("<p>", "").replace("</p>", "").replace('@%s' % answer_id.name, '').lstrip()
context_history.insert(0, {
'role': 'user',
'content': user_content,
})
return context_history
def get_ai_response(self, ai, messages, channel, user_id, message):
@@ -130,10 +132,11 @@ class Channel(models.Model):
channel = self
try:
messages = [{"role": "user", "content": msg}]
messages = []
c_history = self.get_openai_context(channel.id, author_id, answer_id, openapi_context_timeout, chat_count)
if c_history:
messages += c_history
messages.append({"role": "user", "content": msg})
if sync_config == 'sync':
self.get_ai_response(ai, messages, channel, user_id, message)
else: