style: 统一代码格式和 import 顺序
- 调整 Python 文件 import 顺序,遵循标准库→第三方库→项目模块顺序 - 统一字符串引号风格为双引号 - 优化 Vue 组件 console.log 格式 - 压缩 import 语句为单行 - 清理不必要的空行
This commit is contained in:
parent
44e41bbb5a
commit
1f5636520e
@ -1,8 +1,7 @@
|
|||||||
from langchain.agents import create_agent
|
|
||||||
from langchain.agents.middleware import ModelRetryMiddleware
|
|
||||||
|
|
||||||
from deepagents.backends import StateBackend
|
from deepagents.backends import StateBackend
|
||||||
from deepagents.middleware.filesystem import FilesystemMiddleware
|
from deepagents.middleware.filesystem import FilesystemMiddleware
|
||||||
|
from langchain.agents import create_agent
|
||||||
|
from langchain.agents.middleware import ModelRetryMiddleware
|
||||||
|
|
||||||
from src.agents.common import BaseAgent, load_chat_model
|
from src.agents.common import BaseAgent, load_chat_model
|
||||||
from src.agents.common.middlewares import (
|
from src.agents.common.middlewares import (
|
||||||
|
|||||||
@ -31,9 +31,9 @@ def _make_attachment_path(file_name: str) -> str:
|
|||||||
"""
|
"""
|
||||||
# 提取不带扩展名的部分
|
# 提取不带扩展名的部分
|
||||||
base_name = file_name
|
base_name = file_name
|
||||||
for ext in ['.docx', '.txt', '.html', '.htm', '.pdf', '.md']:
|
for ext in [".docx", ".txt", ".html", ".htm", ".pdf", ".md"]:
|
||||||
if file_name.lower().endswith(ext):
|
if file_name.lower().endswith(ext):
|
||||||
base_name = file_name[:-len(ext)]
|
base_name = file_name[: -len(ext)]
|
||||||
break
|
break
|
||||||
|
|
||||||
# 替换路径分隔符
|
# 替换路径分隔符
|
||||||
|
|||||||
@ -13,19 +13,18 @@ import asyncio
|
|||||||
import contextlib
|
import contextlib
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import uuid
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
# 添加项目根目录到 Python 路径
|
# 添加项目根目录到 Python 路径
|
||||||
PROJECT_ROOT = Path(__file__).parent.parent.parent
|
PROJECT_ROOT = Path(__file__).parent.parent.parent
|
||||||
sys.path.insert(0, str(PROJECT_ROOT))
|
sys.path.insert(0, str(PROJECT_ROOT))
|
||||||
|
|
||||||
# 加载 .env 文件
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
load_dotenv(PROJECT_ROOT / ".env")
|
load_dotenv(PROJECT_ROOT / ".env")
|
||||||
|
|
||||||
import httpx
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
|
|
||||||
# API 配置
|
# API 配置
|
||||||
API_BASE_URL = os.getenv("API_BASE_URL", "http://localhost:5050")
|
API_BASE_URL = os.getenv("API_BASE_URL", "http://localhost:5050")
|
||||||
@ -58,9 +57,9 @@ class APITester:
|
|||||||
|
|
||||||
async def login(self) -> bool:
|
async def login(self) -> bool:
|
||||||
"""登录获取 token"""
|
"""登录获取 token"""
|
||||||
print(f"\n{'='*60}")
|
print(f"\n{'=' * 60}")
|
||||||
print(f"1. 正在登录: {self.username}")
|
print(f"1. 正在登录: {self.username}")
|
||||||
print(f"{'='*60}")
|
print(f"{'=' * 60}")
|
||||||
|
|
||||||
async with self._client() as client:
|
async with self._client() as client:
|
||||||
response = await client.post(
|
response = await client.post(
|
||||||
@ -82,9 +81,9 @@ class APITester:
|
|||||||
|
|
||||||
async def create_thread(self, agent_id: str) -> str:
|
async def create_thread(self, agent_id: str) -> str:
|
||||||
"""创建对话线程"""
|
"""创建对话线程"""
|
||||||
print(f"\n{'='*60}")
|
print(f"\n{'=' * 60}")
|
||||||
print(f"2. 创建对话线程 (agent_id: {agent_id})")
|
print(f"2. 创建对话线程 (agent_id: {agent_id})")
|
||||||
print(f"{'='*60}")
|
print(f"{'=' * 60}")
|
||||||
|
|
||||||
async with self._client() as client:
|
async with self._client() as client:
|
||||||
response = await client.post(
|
response = await client.post(
|
||||||
@ -104,9 +103,9 @@ class APITester:
|
|||||||
|
|
||||||
async def upload_attachment(self, thread_id: str, file_path: str) -> dict | None:
|
async def upload_attachment(self, thread_id: str, file_path: str) -> dict | None:
|
||||||
"""上传附件"""
|
"""上传附件"""
|
||||||
print(f"\n{'='*60}")
|
print(f"\n{'=' * 60}")
|
||||||
print(f"3. 上传附件: {file_path}")
|
print(f"3. 上传附件: {file_path}")
|
||||||
print(f"{'='*60}")
|
print(f"{'=' * 60}")
|
||||||
|
|
||||||
if not os.path.exists(file_path):
|
if not os.path.exists(file_path):
|
||||||
print(f" ✗ 文件不存在: {file_path}")
|
print(f" ✗ 文件不存在: {file_path}")
|
||||||
@ -123,7 +122,7 @@ class APITester:
|
|||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
attachment = response.json()
|
attachment = response.json()
|
||||||
print(f" ✓ 上传成功!")
|
print(" ✓ 上传成功!")
|
||||||
print(f" file_id: {attachment.get('file_id')}")
|
print(f" file_id: {attachment.get('file_id')}")
|
||||||
print(f" file_name: {attachment.get('file_name')}")
|
print(f" file_name: {attachment.get('file_name')}")
|
||||||
print(f" status: {attachment.get('status')}")
|
print(f" status: {attachment.get('status')}")
|
||||||
@ -134,9 +133,9 @@ class APITester:
|
|||||||
|
|
||||||
async def list_attachments(self, thread_id: str) -> list[dict]:
|
async def list_attachments(self, thread_id: str) -> list[dict]:
|
||||||
"""列出附件"""
|
"""列出附件"""
|
||||||
print(f"\n{'='*60}")
|
print(f"\n{'=' * 60}")
|
||||||
print(f"4. 列出附件 (thread_id: {thread_id})")
|
print(f"4. 列出附件 (thread_id: {thread_id})")
|
||||||
print(f"{'='*60}")
|
print(f"{'=' * 60}")
|
||||||
|
|
||||||
async with self._client() as client:
|
async with self._client() as client:
|
||||||
response = await client.get(
|
response = await client.get(
|
||||||
@ -157,9 +156,9 @@ class APITester:
|
|||||||
|
|
||||||
async def get_agent_state(self, agent_id: str, thread_id: str) -> dict | None:
|
async def get_agent_state(self, agent_id: str, thread_id: str) -> dict | None:
|
||||||
"""获取 agent state"""
|
"""获取 agent state"""
|
||||||
print(f"\n{'='*60}")
|
print(f"\n{'=' * 60}")
|
||||||
print(f"5. 获取 Agent State (agent_id: {agent_id}, thread_id: {thread_id})")
|
print(f"5. 获取 Agent State (agent_id: {agent_id}, thread_id: {thread_id})")
|
||||||
print(f"{'='*60}")
|
print(f"{'=' * 60}")
|
||||||
|
|
||||||
async with self._client() as client:
|
async with self._client() as client:
|
||||||
response = await client.get(
|
response = await client.get(
|
||||||
@ -171,11 +170,11 @@ class APITester:
|
|||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
state = response.json()
|
state = response.json()
|
||||||
agent_state = state.get("agent_state", {})
|
agent_state = state.get("agent_state", {})
|
||||||
print(f" ✓ 获取成功!")
|
print(" ✓ 获取成功!")
|
||||||
print(f" files: {len(agent_state.get('files', {}))} 个")
|
print(f" files: {len(agent_state.get('files', {}))} 个")
|
||||||
print(f" todos: {len(agent_state.get('todos', []))} 个")
|
print(f" todos: {len(agent_state.get('todos', []))} 个")
|
||||||
if agent_state.get("files"):
|
if agent_state.get("files"):
|
||||||
print(f" 文件列表:")
|
print(" 文件列表:")
|
||||||
for path in agent_state["files"]:
|
for path in agent_state["files"]:
|
||||||
file_info = agent_state["files"][path]
|
file_info = agent_state["files"][path]
|
||||||
print(f" - {path}: {len(file_info.get('content', []))} 行")
|
print(f" - {path}: {len(file_info.get('content', []))} 行")
|
||||||
@ -186,9 +185,9 @@ class APITester:
|
|||||||
|
|
||||||
async def send_chat_message(self, agent_id: str, thread_id: str, query: str) -> bool:
|
async def send_chat_message(self, agent_id: str, thread_id: str, query: str) -> bool:
|
||||||
"""发送聊天消息(流式)"""
|
"""发送聊天消息(流式)"""
|
||||||
print(f"\n{'='*60}")
|
print(f"\n{'=' * 60}")
|
||||||
print(f"6. 发送聊天消息")
|
print("6. 发送聊天消息")
|
||||||
print(f"{'='*60}")
|
print(f"{'=' * 60}")
|
||||||
print(f" Query: {query}")
|
print(f" Query: {query}")
|
||||||
print(f" Thread ID: {thread_id}")
|
print(f" Thread ID: {thread_id}")
|
||||||
|
|
||||||
@ -200,7 +199,7 @@ class APITester:
|
|||||||
headers=self.headers,
|
headers=self.headers,
|
||||||
) as response:
|
) as response:
|
||||||
print(f"\n 响应状态: {response.status_code}")
|
print(f"\n 响应状态: {response.status_code}")
|
||||||
print(f" 响应内容:")
|
print(" 响应内容:")
|
||||||
async for chunk in response.aiter_lines():
|
async for chunk in response.aiter_lines():
|
||||||
if chunk:
|
if chunk:
|
||||||
print(f" {chunk[:150]}...")
|
print(f" {chunk[:150]}...")
|
||||||
@ -264,11 +263,7 @@ def hello():
|
|||||||
await tester.get_agent_state(agent_id, thread_id)
|
await tester.get_agent_state(agent_id, thread_id)
|
||||||
|
|
||||||
# 7. 发送聊天消息测试
|
# 7. 发送聊天消息测试
|
||||||
await tester.send_chat_message(
|
await tester.send_chat_message(agent_id, thread_id, "你好,请简单介绍一下你自己。")
|
||||||
agent_id,
|
|
||||||
thread_id,
|
|
||||||
"你好,请简单介绍一下你自己。"
|
|
||||||
)
|
|
||||||
|
|
||||||
# 8. 再次获取 agent state (验证 todos 等状态)
|
# 8. 再次获取 agent state (验证 todos 等状态)
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
@ -279,9 +274,9 @@ def hello():
|
|||||||
os.remove(test_file_path)
|
os.remove(test_file_path)
|
||||||
print(f"\n 测试文件已清理: {test_file_path}")
|
print(f"\n 测试文件已清理: {test_file_path}")
|
||||||
|
|
||||||
print(f"\n{'='*60}")
|
print(f"\n{'=' * 60}")
|
||||||
print(" 测试完成!")
|
print(" 测试完成!")
|
||||||
print(f"{'='*60}\n")
|
print(f"{'=' * 60}\n")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@ -671,7 +671,16 @@ const fetchAgentState = async (agentId, threadId) => {
|
|||||||
// 确保更新 currentChatId 对应的 state,因为 currentAgentState 依赖它
|
// 确保更新 currentChatId 对应的 state,因为 currentAgentState 依赖它
|
||||||
// 如果 currentChatId 为 null,使用传入的 threadId
|
// 如果 currentChatId 为 null,使用传入的 threadId
|
||||||
const targetChatId = currentChatId.value || threadId
|
const targetChatId = currentChatId.value || threadId
|
||||||
console.log('[fetchAgentState] agentId:', agentId, 'threadId:', threadId, 'targetChatId:', targetChatId, 'agent_state:', JSON.stringify(res.agent_state || {})?.slice(0, 200))
|
console.log(
|
||||||
|
'[fetchAgentState] agentId:',
|
||||||
|
agentId,
|
||||||
|
'threadId:',
|
||||||
|
threadId,
|
||||||
|
'targetChatId:',
|
||||||
|
targetChatId,
|
||||||
|
'agent_state:',
|
||||||
|
JSON.stringify(res.agent_state || {})?.slice(0, 200)
|
||||||
|
)
|
||||||
const ts = getThreadState(targetChatId)
|
const ts = getThreadState(targetChatId)
|
||||||
if (ts) {
|
if (ts) {
|
||||||
ts.agentState = res.agent_state || null
|
ts.agentState = res.agent_state || null
|
||||||
@ -1088,7 +1097,14 @@ const handleAgentStateRefresh = async (threadId = null) => {
|
|||||||
if (!currentAgentId.value) return
|
if (!currentAgentId.value) return
|
||||||
// 优先使用传入的 threadId,否则使用当前的 currentChatId
|
// 优先使用传入的 threadId,否则使用当前的 currentChatId
|
||||||
let chatId = threadId || currentChatId.value
|
let chatId = threadId || currentChatId.value
|
||||||
console.log('[handleAgentStateRefresh] input threadId:', threadId, 'currentChatId:', currentChatId.value, 'final chatId:', chatId)
|
console.log(
|
||||||
|
'[handleAgentStateRefresh] input threadId:',
|
||||||
|
threadId,
|
||||||
|
'currentChatId:',
|
||||||
|
currentChatId.value,
|
||||||
|
'final chatId:',
|
||||||
|
chatId
|
||||||
|
)
|
||||||
if (!chatId) return
|
if (!chatId) return
|
||||||
await fetchAgentState(currentAgentId.value, chatId)
|
await fetchAgentState(currentAgentId.value, chatId)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -151,14 +151,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, ref, onMounted, onUpdated, nextTick } from 'vue'
|
import { computed, ref, onMounted, onUpdated, nextTick } from 'vue'
|
||||||
import {
|
import { Download, X, FolderCode, RefreshCw, Folder, FolderOpen } from 'lucide-vue-next'
|
||||||
Download,
|
|
||||||
X,
|
|
||||||
FolderCode,
|
|
||||||
RefreshCw,
|
|
||||||
Folder,
|
|
||||||
FolderOpen
|
|
||||||
} from 'lucide-vue-next'
|
|
||||||
import {
|
import {
|
||||||
CheckCircleOutlined,
|
CheckCircleOutlined,
|
||||||
SyncOutlined,
|
SyncOutlined,
|
||||||
|
|||||||
@ -121,7 +121,6 @@ const loadCallStats = async () => {
|
|||||||
await nextTick()
|
await nextTick()
|
||||||
renderCallStatsChart()
|
renderCallStatsChart()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
console.error('加载调用统计数据失败:', error)
|
console.error('加载调用统计数据失败:', error)
|
||||||
} finally {
|
} finally {
|
||||||
callStatsLoading.value = false
|
callStatsLoading.value = false
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user