添加意见反馈

This commit is contained in:
sophie committed 2026-04-23 13:52:28 +08:00
1 parent 2bd27ed70d
commit 6b2ab65436
16 files changed
+853 -37

No files matched your search

+9 -3
View File
@@ -24,7 +24,7 @@ chat.py (/api/chat/completions)
"""
import json
import time
from typing import Any, List
from typing import Any, List, Optional
import requests
from flask import current_app
@@ -153,7 +153,7 @@ class DifyService:
usage = metadata.get('usage', {}) or {}
with current_app.app_context():
DifyService._log_chat(
chat_log_id = DifyService._log_chat(
user_id=user_id,
agent_id=agent.id,
conversation_id=data.get('conversation_id') or conversation_id,
@@ -164,6 +164,8 @@ class DifyService:
retriever_resources=retriever_resources,
attribution_parts=attribution_parts,
)
if chat_log_id:
data['chat_log_id'] = chat_log_id
if current_app:
current_app.logger.info(
"[chat-stream] message_end logged conversation_id=%s answer_len=%s resources=%s attribution=%s latency_ms=%s",
@@ -195,7 +197,7 @@ class DifyService:
latency,
retriever_resources=None,
attribution_parts=None,
):
) -> Optional[int]:
"""
把最终问答和元数据写入 ChatLog
Persist one chat record into ChatLog table.
@@ -223,10 +225,14 @@ class DifyService:
)
db.session.add(chat_log)
db.session.commit()
return chat_log.id
except Exception as e:
if current_app:
current_app.logger.error(f'Failed to log chat: {e}')
db.session.rollback()
return None
return None
@staticmethod
def _normalize_resources(resources):