Skip to content

Commit 797c0bb

Browse files
committed
fix: No history while use openai chat
--bug=1061932 --user=张展玮 【系统API】调用 openai 接口对话,无法获取历史聊天记录信息 https://www.tapd.cn/62980211/s/1781929
1 parent f834569 commit 797c0bb

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

apps/chat/serializers/chat.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,21 @@ def get_message(instance):
222222
def generate_chat(chat_id, application_id, message, chat_user_id, chat_user_type):
223223
if chat_id is None:
224224
chat_id = str(uuid.uuid1())
225-
chat_info = ChatInfo(chat_id, chat_user_id, chat_user_type, [], [],
226-
application_id)
227-
chat_info.set_cache()
225+
chat_info = ChatInfo(chat_id, chat_user_id, chat_user_type, [], [],
226+
application_id)
227+
chat_info.set_cache()
228+
else:
229+
chat_info = ChatInfo.get_cache(chat_id)
230+
if chat_info is None:
231+
ser = ChatSerializers(data={
232+
'chat_id': chat_id,
233+
'chat_user_id': chat_user_id,
234+
'chat_user_type': chat_user_type,
235+
'application_id': application_id
236+
})
237+
ser.is_valid(raise_exception=True)
238+
chat_info = ser.re_open_chat(chat_id)
239+
chat_info.set_cache()
228240
return chat_id
229241

230242
def chat(self, instance: Dict, with_valid=True):

0 commit comments

Comments
 (0)