Skip to content

Commit 393e8df

Browse files
committed
feat: workflow details
1 parent 762357e commit 393e8df

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎apps/application/workflow/workflow_manage.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def get_details(self, position: Dict = None, old_details=None):
211211
details = node.get_details(
212212
index + position_index, position=position, old_details=old_details[position_index]
213213
)
214-
details_result.insert(position_index, details)
214+
details_result[position_index] = details
215215
else:
216216
details = node.get_details(index + position_index)
217217
details_result.append(details)

‎apps/chat/serializers/chat.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def _usage_from_context(workflow_context):
233233
return {"prompt_tokens": prompt_tokens, "completion_tokens": completion_tokens}
234234

235235
@staticmethod
236-
def update_chat_record(chat_user_id, chat_record_id, workflow_context, messages):
236+
def update_chat_record(chat_user_id, chat_record_id, workflow_context, messages, details):
237237
usage = ChatSerializers._usage_from_context(workflow_context)
238238
message_tokens = usage["prompt_tokens"]
239239
answer_tokens = usage["completion_tokens"]
@@ -243,6 +243,7 @@ def update_chat_record(chat_user_id, chat_record_id, workflow_context, messages)
243243
messages=messages,
244244
message_tokens=message_tokens,
245245
answer_tokens=answer_tokens,
246+
details=details,
246247
)
247248

248249
# ---------- 执行 ----------
@@ -327,7 +328,13 @@ def on_complete(wf_manage, error):
327328
FailureContent(str(uuid_utils.uuid7()), str(error), Status.SUCCESS, None, None).to_dict(),
328329
)
329330
messages = aggregation.get_contents()
330-
self.update_chat_record(chat_user_id, chat_record_id_str, wf_manage.context, messages)
331+
old_details = None
332+
if chat_record_id is not None:
333+
chat_record = QuerySet(ChatRecord).filter(id=chat_record_id).first()
334+
if chat_record:
335+
old_details = chat_record.details
336+
details = wf_manage.get_details(position=position, old_details=old_details)
337+
self.update_chat_record(chat_user_id, chat_record_id_str, wf_manage.context, messages, details)
331338
ChatCountSerializer(data={"chat_id": chat_id}).update_chat()
332339
ChatHistory(chat_id).append(
333340
ChatRecord(

0 commit comments

Comments
 (0)