Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/application/workflow/workflow_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def get_details(self, position: Dict = None, old_details=None):
details = node.get_details(
index + position_index, position=position, old_details=old_details[position_index]
)
details_result.insert(position_index, details)
details_result[position_index] = details
else:
details = node.get_details(index + position_index)
details_result.append(details)
Expand Down
11 changes: 9 additions & 2 deletions apps/chat/serializers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _usage_from_context(workflow_context):
return {"prompt_tokens": prompt_tokens, "completion_tokens": completion_tokens}

@staticmethod
def update_chat_record(chat_user_id, chat_record_id, workflow_context, messages):
def update_chat_record(chat_user_id, chat_record_id, workflow_context, messages, details):
usage = ChatSerializers._usage_from_context(workflow_context)
message_tokens = usage["prompt_tokens"]
answer_tokens = usage["completion_tokens"]
Expand All @@ -243,6 +243,7 @@ def update_chat_record(chat_user_id, chat_record_id, workflow_context, messages)
messages=messages,
message_tokens=message_tokens,
answer_tokens=answer_tokens,
details=details,
)

# ---------- 执行 ----------
Expand Down Expand Up @@ -327,7 +328,13 @@ def on_complete(wf_manage, error):
FailureContent(str(uuid_utils.uuid7()), str(error), Status.SUCCESS, None, None).to_dict(),
)
messages = aggregation.get_contents()
self.update_chat_record(chat_user_id, chat_record_id_str, wf_manage.context, messages)
old_details = None
if chat_record_id is not None:
chat_record = QuerySet(ChatRecord).filter(id=chat_record_id).first()
if chat_record:
old_details = chat_record.details
details = wf_manage.get_details(position=position, old_details=old_details)
self.update_chat_record(chat_user_id, chat_record_id_str, wf_manage.context, messages, details)
ChatCountSerializer(data={"chat_id": chat_id}).update_chat()
ChatHistory(chat_id).append(
ChatRecord(
Expand Down
Loading