Skip to content

Commit 1f56365

Browse files
committed
style: 统一代码格式和 import 顺序
- 调整 Python 文件 import 顺序,遵循标准库→第三方库→项目模块顺序 - 统一字符串引号风格为双引号 - 优化 Vue 组件 console.log 格式 - 压缩 import 语句为单行 - 清理不必要的空行
1 parent 44e41bb commit 1f56365

File tree

6 files changed

+47
-45
lines changed

6 files changed

+47
-45
lines changed

src/agents/chatbot/graph.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from langchain.agents import create_agent
2-
from langchain.agents.middleware import ModelRetryMiddleware
3-
41
from deepagents.backends import StateBackend
52
from deepagents.middleware.filesystem import FilesystemMiddleware
3+
from langchain.agents import create_agent
4+
from langchain.agents.middleware import ModelRetryMiddleware
65

76
from src.agents.common import BaseAgent, load_chat_model
87
from src.agents.common.middlewares import (

src/services/conversation_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def _make_attachment_path(file_name: str) -> str:
3131
"""
3232
# 提取不带扩展名的部分
3333
base_name = file_name
34-
for ext in ['.docx', '.txt', '.html', '.htm', '.pdf', '.md']:
34+
for ext in [".docx", ".txt", ".html", ".htm", ".pdf", ".md"]:
3535
if file_name.lower().endswith(ext):
36-
base_name = file_name[:-len(ext)]
36+
base_name = file_name[: -len(ext)]
3737
break
3838

3939
# 替换路径分隔符

test/api/test_attachment_and_agent_state.py

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@
1313
import contextlib
1414
import os
1515
import sys
16+
import uuid
1617
from pathlib import Path
1718

19+
import httpx
20+
from dotenv import load_dotenv
21+
1822
# 添加项目根目录到 Python 路径
1923
PROJECT_ROOT = Path(__file__).parent.parent.parent
2024
sys.path.insert(0, str(PROJECT_ROOT))
2125

22-
# 加载 .env 文件
23-
from dotenv import load_dotenv
2426
load_dotenv(PROJECT_ROOT / ".env")
2527

26-
import httpx
27-
import uuid
28-
2928

3029
# API 配置
3130
API_BASE_URL = os.getenv("API_BASE_URL", "http://localhost:5050")
@@ -58,9 +57,9 @@ async def _client(self, timeout: float = 30.0):
5857

5958
async def login(self) -> bool:
6059
"""登录获取 token"""
61-
print(f"\n{'='*60}")
60+
print(f"\n{'=' * 60}")
6261
print(f"1. 正在登录: {self.username}")
63-
print(f"{'='*60}")
62+
print(f"{'=' * 60}")
6463

6564
async with self._client() as client:
6665
response = await client.post(
@@ -82,9 +81,9 @@ async def login(self) -> bool:
8281

8382
async def create_thread(self, agent_id: str) -> str:
8483
"""创建对话线程"""
85-
print(f"\n{'='*60}")
84+
print(f"\n{'=' * 60}")
8685
print(f"2. 创建对话线程 (agent_id: {agent_id})")
87-
print(f"{'='*60}")
86+
print(f"{'=' * 60}")
8887

8988
async with self._client() as client:
9089
response = await client.post(
@@ -104,9 +103,9 @@ async def create_thread(self, agent_id: str) -> str:
104103

105104
async def upload_attachment(self, thread_id: str, file_path: str) -> dict | None:
106105
"""上传附件"""
107-
print(f"\n{'='*60}")
106+
print(f"\n{'=' * 60}")
108107
print(f"3. 上传附件: {file_path}")
109-
print(f"{'='*60}")
108+
print(f"{'=' * 60}")
110109

111110
if not os.path.exists(file_path):
112111
print(f" ✗ 文件不存在: {file_path}")
@@ -123,7 +122,7 @@ async def upload_attachment(self, thread_id: str, file_path: str) -> dict | None
123122

124123
if response.status_code == 200:
125124
attachment = response.json()
126-
print(f" ✓ 上传成功!")
125+
print(" ✓ 上传成功!")
127126
print(f" file_id: {attachment.get('file_id')}")
128127
print(f" file_name: {attachment.get('file_name')}")
129128
print(f" status: {attachment.get('status')}")
@@ -134,9 +133,9 @@ async def upload_attachment(self, thread_id: str, file_path: str) -> dict | None
134133

135134
async def list_attachments(self, thread_id: str) -> list[dict]:
136135
"""列出附件"""
137-
print(f"\n{'='*60}")
136+
print(f"\n{'=' * 60}")
138137
print(f"4. 列出附件 (thread_id: {thread_id})")
139-
print(f"{'='*60}")
138+
print(f"{'=' * 60}")
140139

141140
async with self._client() as client:
142141
response = await client.get(
@@ -157,9 +156,9 @@ async def list_attachments(self, thread_id: str) -> list[dict]:
157156

158157
async def get_agent_state(self, agent_id: str, thread_id: str) -> dict | None:
159158
"""获取 agent state"""
160-
print(f"\n{'='*60}")
159+
print(f"\n{'=' * 60}")
161160
print(f"5. 获取 Agent State (agent_id: {agent_id}, thread_id: {thread_id})")
162-
print(f"{'='*60}")
161+
print(f"{'=' * 60}")
163162

164163
async with self._client() as client:
165164
response = await client.get(
@@ -171,11 +170,11 @@ async def get_agent_state(self, agent_id: str, thread_id: str) -> dict | None:
171170
if response.status_code == 200:
172171
state = response.json()
173172
agent_state = state.get("agent_state", {})
174-
print(f" ✓ 获取成功!")
173+
print(" ✓ 获取成功!")
175174
print(f" files: {len(agent_state.get('files', {}))} 个")
176175
print(f" todos: {len(agent_state.get('todos', []))} 个")
177176
if agent_state.get("files"):
178-
print(f" 文件列表:")
177+
print(" 文件列表:")
179178
for path in agent_state["files"]:
180179
file_info = agent_state["files"][path]
181180
print(f" - {path}: {len(file_info.get('content', []))} 行")
@@ -186,9 +185,9 @@ async def get_agent_state(self, agent_id: str, thread_id: str) -> dict | None:
186185

187186
async def send_chat_message(self, agent_id: str, thread_id: str, query: str) -> bool:
188187
"""发送聊天消息(流式)"""
189-
print(f"\n{'='*60}")
190-
print(f"6. 发送聊天消息")
191-
print(f"{'='*60}")
188+
print(f"\n{'=' * 60}")
189+
print("6. 发送聊天消息")
190+
print(f"{'=' * 60}")
192191
print(f" Query: {query}")
193192
print(f" Thread ID: {thread_id}")
194193

@@ -200,7 +199,7 @@ async def send_chat_message(self, agent_id: str, thread_id: str, query: str) ->
200199
headers=self.headers,
201200
) as response:
202201
print(f"\n 响应状态: {response.status_code}")
203-
print(f" 响应内容:")
202+
print(" 响应内容:")
204203
async for chunk in response.aiter_lines():
205204
if chunk:
206205
print(f" {chunk[:150]}...")
@@ -264,11 +263,7 @@ def hello():
264263
await tester.get_agent_state(agent_id, thread_id)
265264

266265
# 7. 发送聊天消息测试
267-
await tester.send_chat_message(
268-
agent_id,
269-
thread_id,
270-
"你好,请简单介绍一下你自己。"
271-
)
266+
await tester.send_chat_message(agent_id, thread_id, "你好,请简单介绍一下你自己。")
272267

273268
# 8. 再次获取 agent state (验证 todos 等状态)
274269
await asyncio.sleep(1)
@@ -279,9 +274,9 @@ def hello():
279274
os.remove(test_file_path)
280275
print(f"\n 测试文件已清理: {test_file_path}")
281276

282-
print(f"\n{'='*60}")
277+
print(f"\n{'=' * 60}")
283278
print(" 测试完成!")
284-
print(f"{'='*60}\n")
279+
print(f"{'=' * 60}\n")
285280

286281

287282
if __name__ == "__main__":

web/src/components/AgentChatComponent.vue

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,16 @@ const fetchAgentState = async (agentId, threadId) => {
671671
// 确保更新 currentChatId 对应的 state,因为 currentAgentState 依赖它
672672
// 如果 currentChatId 为 null,使用传入的 threadId
673673
const targetChatId = currentChatId.value || threadId
674-
console.log('[fetchAgentState] agentId:', agentId, 'threadId:', threadId, 'targetChatId:', targetChatId, 'agent_state:', JSON.stringify(res.agent_state || {})?.slice(0, 200))
674+
console.log(
675+
'[fetchAgentState] agentId:',
676+
agentId,
677+
'threadId:',
678+
threadId,
679+
'targetChatId:',
680+
targetChatId,
681+
'agent_state:',
682+
JSON.stringify(res.agent_state || {})?.slice(0, 200)
683+
)
675684
const ts = getThreadState(targetChatId)
676685
if (ts) {
677686
ts.agentState = res.agent_state || null
@@ -1088,7 +1097,14 @@ const handleAgentStateRefresh = async (threadId = null) => {
10881097
if (!currentAgentId.value) return
10891098
// 优先使用传入的 threadId,否则使用当前的 currentChatId
10901099
let chatId = threadId || currentChatId.value
1091-
console.log('[handleAgentStateRefresh] input threadId:', threadId, 'currentChatId:', currentChatId.value, 'final chatId:', chatId)
1100+
console.log(
1101+
'[handleAgentStateRefresh] input threadId:',
1102+
threadId,
1103+
'currentChatId:',
1104+
currentChatId.value,
1105+
'final chatId:',
1106+
chatId
1107+
)
10921108
if (!chatId) return
10931109
await fetchAgentState(currentAgentId.value, chatId)
10941110
}

web/src/components/AgentPanel.vue

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,7 @@
151151

152152
<script setup>
153153
import { computed, ref, onMounted, onUpdated, nextTick } from 'vue'
154-
import {
155-
Download,
156-
X,
157-
FolderCode,
158-
RefreshCw,
159-
Folder,
160-
FolderOpen
161-
} from 'lucide-vue-next'
154+
import { Download, X, FolderCode, RefreshCw, Folder, FolderOpen } from 'lucide-vue-next'
162155
import {
163156
CheckCircleOutlined,
164157
SyncOutlined,

web/src/components/dashboard/CallStatsComponent.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ const loadCallStats = async () => {
121121
await nextTick()
122122
renderCallStatsChart()
123123
} catch (error) {
124-
125124
console.error('加载调用统计数据失败:', error)
126125
} finally {
127126
callStatsLoading.value = false

0 commit comments

Comments
 (0)