From 8011e5d2cb26980484157318ff70e4d2a7ee916f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Thu, 9 Oct 2025 11:00:41 +0800 Subject: [PATCH] add qwen-agent --- Dockerfile | 3 +- agent_prompt.txt | 2 +- docker-compose.yml | 2 +- test_projects/55bf61e5dfd4c9a8/document.txt | 1 + .../55bf61e5dfd4c9a8/subdir/document.txt | 1 + test_projects/_cache/55bf61e5dfd4c9a8.zip | Bin 0 -> 286 bytes zip_project_handler.py | 56 ++++++++++++++---- 7 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 test_projects/55bf61e5dfd4c9a8/document.txt create mode 100644 test_projects/55bf61e5dfd4c9a8/subdir/document.txt create mode 100644 test_projects/_cache/55bf61e5dfd4c9a8.zip diff --git a/Dockerfile b/Dockerfile index cf8b138..7625154 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,6 @@ WORKDIR /app # 设置环境变量 ENV PYTHONPATH=/app ENV PYTHONUNBUFFERED=1 -ENV AGENT_POOL_SIZE=1 # 安装系统依赖 RUN sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources && \ @@ -39,7 +38,7 @@ EXPOSE 8001 # 健康检查 HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ - CMD curl -f http://localhost:8001/ || exit 1 + CMD curl -f http://localhost:8001/api/health"|| exit 1 # 启动命令 CMD ["python", "fastapi_app.py"] diff --git a/agent_prompt.txt b/agent_prompt.txt index 9572aaa..301cebe 100644 --- a/agent_prompt.txt +++ b/agent_prompt.txt @@ -58,7 +58,7 @@ ### 阶段0:数据集探索 **目标**:识别可用数据集,确定查询目标 **执行步骤**: -1. **目录扫描**:查看data目录下的所有数据集文件夹 +1. **目录扫描**:查看[当前数据目录]下的所有数据集文件夹 2. **数据集选择**:根据用户需求选择合适的数据集文件夹 ### 阶段1:智能索引分析 diff --git a/docker-compose.yml b/docker-compose.yml index 80160e1..eb76f8b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,7 +18,7 @@ services: restart: unless-stopped healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8001/"] + test: ["CMD", "curl", "-f", "http://localhost:8001/api/health"] interval: 30s timeout: 10s retries: 3 diff --git a/test_projects/55bf61e5dfd4c9a8/document.txt b/test_projects/55bf61e5dfd4c9a8/document.txt new file mode 100644 index 0000000..8161444 --- /dev/null +++ b/test_projects/55bf61e5dfd4c9a8/document.txt @@ -0,0 +1 @@ +Test document content \ No newline at end of file diff --git a/test_projects/55bf61e5dfd4c9a8/subdir/document.txt b/test_projects/55bf61e5dfd4c9a8/subdir/document.txt new file mode 100644 index 0000000..65868b8 --- /dev/null +++ b/test_projects/55bf61e5dfd4c9a8/subdir/document.txt @@ -0,0 +1 @@ +Subdirectory document content \ No newline at end of file diff --git a/test_projects/_cache/55bf61e5dfd4c9a8.zip b/test_projects/_cache/55bf61e5dfd4c9a8.zip new file mode 100644 index 0000000000000000000000000000000000000000..75fb7cd26420cb89c29e40a464571341b6a807fc GIT binary patch literal 286 zcmWIWW@Zs#00H*39?=rp-pGgo*&xgV#3}j7rManjC3+SBh2;Fa5}-r? ziuOH*vXZhuZ6GWR#KomaDVat3Fijv+g26(m$tC$kl~_z;WD;Sw_qL7UZ k@J7{%?h=ST28ISkdms~wy8^sf*+7bzfUp`!_kuVK0JUR3Jpcdz literal 0 HcmV?d00001 diff --git a/zip_project_handler.py b/zip_project_handler.py index e97e2a4..d026f78 100644 --- a/zip_project_handler.py +++ b/zip_project_handler.py @@ -27,11 +27,19 @@ class ZipProjectHandler: """获取URL的哈希值用于缓存""" return hashlib.md5(url.encode('utf-8')).hexdigest()[:16] - def _is_valid_url(self, url: str) -> bool: - """验证URL是否有效""" + def _is_valid_url_or_path(self, path: str) -> bool: + """验证URL或本地路径是否有效""" + # 首先尝试作为URL验证 try: - result = urlparse(url) - return all([result.scheme, result.netloc]) + result = urlparse(path) + if all([result.scheme, result.netloc]): + return True + except Exception: + pass + + # 然后尝试作为本地路径验证 + try: + return Path(path).exists() except Exception: return False @@ -51,6 +59,16 @@ class ZipProjectHandler: print(f"下载文件失败: {e}") return False + def _copy_local_file(self, local_path: str, target_path: str) -> bool: + """复制本地文件到目标路径""" + try: + import shutil + shutil.copy2(local_path, target_path) + return True + except Exception as e: + print(f"复制本地文件失败: {e}") + return False + def _extract_zip(self, zip_path: str, extract_to: str) -> bool: """解压ZIP文件到指定目录""" try: @@ -63,16 +81,16 @@ class ZipProjectHandler: def get_project_from_zip(self, zip_url: str) -> Optional[str]: """ - 从ZIP URL获取项目数据 + 从ZIP URL或本地路径获取项目数据 Args: - zip_url: ZIP文件的URL + zip_url: ZIP文件的URL或本地相对路径 Returns: Optional[str]: 成功时返回项目目录路径,失败时返回None """ - if not self._is_valid_url(zip_url): - print(f"无效的URL: {zip_url}") + if not self._is_valid_url_or_path(zip_url): + print(f"无效的URL或路径: {zip_url}") return None # 检查缓存 @@ -83,14 +101,28 @@ class ZipProjectHandler: print(f"使用缓存的项目目录: {cached_project_dir}") return str(cached_project_dir) - # 下载ZIP文件 + # 下载或复制ZIP文件 zip_filename = f"{url_hash}.zip" zip_path = self.cache_dir / zip_filename if not zip_path.exists(): - print(f"下载ZIP文件: {zip_url}") - if not self._download_file(zip_url, str(zip_path)): - return None + # 判断是URL还是本地路径 + try: + result = urlparse(zip_url) + is_url = all([result.scheme, result.netloc]) + except Exception: + is_url = False + + if is_url: + print(f"下载ZIP文件: {zip_url}") + if not self._download_file(zip_url, str(zip_path)): + return None + else: + print(f"复制本地ZIP文件: {zip_url}") + # 解析相对路径 + local_path = Path(zip_url).resolve() + if not self._copy_local_file(str(local_path), str(zip_path)): + return None else: print(f"使用缓存的ZIP文件: {zip_path}")