diff --git a/README.md b/README.md index d86366d..7278d6a 100644 --- a/README.md +++ b/README.md @@ -102,12 +102,12 @@ python run_tests.py all ### 健康检查 ``` -GET /health +GET /api/health ``` ### 上传文档 ``` -POST /upload +POST /api/upload Content-Type: multipart/form-data 参数: @@ -116,7 +116,7 @@ Content-Type: multipart/form-data ### 查询问答 ``` -POST /chat +POST /api/chat Content-Type: application/json { @@ -128,7 +128,7 @@ Content-Type: application/json ### 流式聊天问答 🆕 ``` -POST /chat/stream +POST /api/chat/stream Content-Type: application/json { @@ -146,7 +146,7 @@ Content-Type: application/json ### 获取文档列表 ``` -GET /documents +GET /api/documents 返回文档列表,包含文档ID、文件名、上传时间等信息 ``` @@ -206,13 +206,13 @@ easy-rag/ ./start.sh # 2. 上传文档 -curl -X POST "http://localhost:8000/upload" \ +curl -X POST "http://localhost:8000/api/upload" \ -H "accept: application/json" \ -H "Content-Type: multipart/form-data" \ -F "file=@your_document.pdf" # 3. 查询问答 -curl -X POST "http://localhost:8000/chat" \ +curl -X POST "http://localhost:8000/api/chat" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ -d '{ @@ -221,7 +221,7 @@ curl -X POST "http://localhost:8000/chat" \ }' # 4. 流式聊天问答 -curl -X POST "http://localhost:8000/chat/stream" \ +curl -X POST "http://localhost:8000/api/chat/stream" \ -H "accept: text/plain" \ -H "Content-Type: application/json" \ -d '{ @@ -239,13 +239,13 @@ import json # 上传文档 with open('document.pdf', 'rb') as f: response = requests.post( - 'http://localhost:8000/upload', + 'http://localhost:8000/api/upload', files={'file': f} ) # 查询问答 response = requests.post( - 'http://localhost:8000/chat', + 'http://localhost:8000/api/chat', json={ 'question': '这个文档讲了什么?', 'top_k': 3 @@ -256,7 +256,7 @@ print(response.json()) # 流式聊天问答 def stream_chat(question): response = requests.post( - 'http://localhost:8000/chat/stream', + 'http://localhost:8000/api/chat/stream', json={'question': question, 'top_k': 3}, stream=True ) @@ -286,7 +286,7 @@ stream_chat("详细解释文档的主要观点") ```javascript // 流式聊天问答 - 前端实现 async function streamChat(question) { - const response = await fetch('/chat/stream', { + const response = await fetch('/api/chat/stream', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/tests/config.py b/tests/config.py index f78bd95..735b075 100644 --- a/tests/config.py +++ b/tests/config.py @@ -5,10 +5,10 @@ # 服务器配置 BASE_URL = "http://localhost:8000" -HEALTH_CHECK_ENDPOINT = "/health" -UPLOAD_ENDPOINT = "/upload" -CHAT_ENDPOINT = "/chat" -DOCUMENTS_ENDPOINT = "/documents" +HEALTH_CHECK_ENDPOINT = "/api/health" +UPLOAD_ENDPOINT = "/api/upload" +CHAT_ENDPOINT = "/api/chat" +DOCUMENTS_ENDPOINT = "/api/documents" # 并发测试配置 CONCURRENT_CONFIG = { diff --git a/tests/performance_monitor.py b/tests/performance_monitor.py index 4d1ab4b..76c77fc 100644 --- a/tests/performance_monitor.py +++ b/tests/performance_monitor.py @@ -179,7 +179,7 @@ async def upload_document(session: aiohttp.ClientSession, content: str, filename data = aiohttp.FormData() data.add_field('file', f, filename=filename, content_type='text/plain') - async with session.post("http://localhost:8000/upload", data=data) as response: + async with session.post("http://localhost:8000/api/upload", data=data) as response: return { "success": response.status == 200, "type": "upload", @@ -198,7 +198,7 @@ async def chat_query(session: aiohttp.ClientSession, question: str): payload = {"question": question, "top_k": 3, "temperature": 0.7} async with session.post( - "http://localhost:8000/chat", + "http://localhost:8000/api/chat", json=payload, headers={"Content-Type": "application/json"} ) as response: diff --git a/tests/test_api.py b/tests/test_api.py index 230e7b4..882224d 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -8,7 +8,7 @@ def test_upload_and_chat(): # 测试健康检查 print("1. 测试健康检查...") - response = requests.get(f"{base_url}/health") + response = requests.get(f"{base_url}/api/health") print(f"状态码: {response.status_code}") print(f"响应: {response.json()}") print() @@ -23,7 +23,7 @@ def test_upload_and_chat(): with open("test_doc.txt", "rb") as f: files = {"file": ("test_doc.txt", f, "text/plain")} - response = requests.post(f"{base_url}/upload", files=files) + response = requests.post(f"{base_url}/api/upload", files=files) print(f"状态码: {response.status_code}") if response.status_code == 200: @@ -37,7 +37,7 @@ def test_upload_and_chat(): # 测试文档列表 print("3. 测试文档列表...") - response = requests.get(f"{base_url}/documents") + response = requests.get(f"{base_url}/api/documents") print(f"状态码: {response.status_code}") print(f"文档列表: {response.json()}") print() @@ -47,7 +47,7 @@ def test_upload_and_chat(): chat_data = {"question": "什么是人工智能?", "top_k": 3, "temperature": 0.7} start_time = datetime.now() response = requests.post( - f"{base_url}/chat/stream", + f"{base_url}/api/chat/stream", json=chat_data, headers={"Content-Type": "application/json"}, stream=True,