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

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靠 u r靠
game MASTER
海盗时代 海盗时代
我和姨在车上干 我和姨在车上干
赌马 赌马
@@ -5158,7 +5156,6 @@ renminbao
RMB RMB
少妇房中自淫和两勇男玩17P操得直叫爽 操日本淫女穴 少妇房中自淫和两勇男玩17P操得直叫爽 操日本淫女穴
淫奸护士姐姐穴 淫奸护士姐姐穴
game
情色电影网站 情色电影网站
錘子 錘子
民主墙 民主墙

View File

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