Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9aaff7ee87 | |||
| b5284ce18e |
@@ -648,6 +648,7 @@ async def get_messages(conversation_id: str, db: Session = Depends(get_db)):
|
|||||||
"role": m.role,
|
"role": m.role,
|
||||||
"content": m.content,
|
"content": m.content,
|
||||||
"thinking_content": m.thinking_content, # v2新增
|
"thinking_content": m.thinking_content, # v2新增
|
||||||
|
"extra_data": m.extra_data, # 包含搜索结果等
|
||||||
"source": m.source,
|
"source": m.source,
|
||||||
"agent_id": m.agent_id, # v2新增
|
"agent_id": m.agent_id, # v2新增
|
||||||
"model_used": m.model_used, # v2新增
|
"model_used": m.model_used, # v2新增
|
||||||
@@ -807,6 +808,7 @@ async def websocket_endpoint(websocket: WebSocket, user_id: str):
|
|||||||
|
|
||||||
# 4. 执行搜索并发送搜索结果
|
# 4. 执行搜索并发送搜索结果
|
||||||
search_context = None
|
search_context = None
|
||||||
|
search_results_for_client = None # 用于发送给前端和保存
|
||||||
logger.info(f"检查搜索条件: agent_tools={agent_tools}, disabled_tools={disabled_tools}")
|
logger.info(f"检查搜索条件: agent_tools={agent_tools}, disabled_tools={disabled_tools}")
|
||||||
|
|
||||||
if 'search' in agent_tools and 'search' not in disabled_tools:
|
if 'search' in agent_tools and 'search' not in disabled_tools:
|
||||||
@@ -888,12 +890,13 @@ async def websocket_endpoint(websocket: WebSocket, user_id: str):
|
|||||||
'duration_ms': duration_ms
|
'duration_ms': duration_ms
|
||||||
})
|
})
|
||||||
|
|
||||||
# 5. 保存用户消息到数据库
|
# 5. 保存用户消息到数据库(包含搜索结果)
|
||||||
user_msg = conv_service.add_message(
|
user_msg = conv_service.add_message(
|
||||||
conversation_id=conversation.id,
|
conversation_id=conversation.id,
|
||||||
role='user',
|
role='user',
|
||||||
content=message,
|
content=message,
|
||||||
source='web'
|
source='web',
|
||||||
|
extra_data={'search_results': search_results_for_client, 'search_query': message} if search_results_for_client else None
|
||||||
)
|
)
|
||||||
|
|
||||||
# 6. 获取对话历史(包含刚保存的用户消息)
|
# 6. 获取对话历史(包含刚保存的用户消息)
|
||||||
|
|||||||
@@ -304,7 +304,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 消息渲染
|
// 消息渲染
|
||||||
function appendMessage(role, content, thinking = null, agentName = null) {
|
function appendMessage(role, content, thinking = null, agentName = null, extraData = null) {
|
||||||
const container = document.getElementById('messagesContainer');
|
const container = document.getElementById('messagesContainer');
|
||||||
container.querySelector('.welcome')?.remove();
|
container.querySelector('.welcome')?.remove();
|
||||||
|
|
||||||
@@ -372,6 +372,15 @@
|
|||||||
html += '</div>';
|
html += '</div>';
|
||||||
div.innerHTML = html;
|
div.innerHTML = html;
|
||||||
container.appendChild(div);
|
container.appendChild(div);
|
||||||
|
|
||||||
|
// 如果是用户消息且有搜索结果,追加显示
|
||||||
|
if (role === 'user' && extraData && extraData.search_results && extraData.search_results.length > 0) {
|
||||||
|
const msgBody = div.querySelector('.message-body');
|
||||||
|
if (msgBody) {
|
||||||
|
msgBody.innerHTML += buildSearchResultsHtml(extraData.search_results, extraData.search_query || content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
container.scrollTop = container.scrollHeight;
|
container.scrollTop = container.scrollHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -622,7 +631,9 @@
|
|||||||
function displayHistory(messages) {
|
function displayHistory(messages) {
|
||||||
const container = document.getElementById('messagesContainer');
|
const container = document.getElementById('messagesContainer');
|
||||||
container.innerHTML = '';
|
container.innerHTML = '';
|
||||||
messages.forEach(m => appendMessage(m.role, m.content, m.thinking_content));
|
messages.forEach(m => {
|
||||||
|
appendMessage(m.role, m.content, m.thinking_content, null, m.extra_data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearMessages() {
|
function clearMessages() {
|
||||||
|
|||||||
Reference in New Issue
Block a user