feat: 调整相关路由入口
This commit is contained in:
parent
43a4a1f458
commit
60f9e4d077
24
README.md
24
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
|
Content-Type: multipart/form-data
|
||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
@ -116,7 +116,7 @@ Content-Type: multipart/form-data
|
||||||
|
|
||||||
### 查询问答
|
### 查询问答
|
||||||
```
|
```
|
||||||
POST /chat
|
POST /api/chat
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -128,7 +128,7 @@ Content-Type: application/json
|
||||||
|
|
||||||
### 流式聊天问答 🆕
|
### 流式聊天问答 🆕
|
||||||
```
|
```
|
||||||
POST /chat/stream
|
POST /api/chat/stream
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -146,7 +146,7 @@ Content-Type: application/json
|
||||||
|
|
||||||
### 获取文档列表
|
### 获取文档列表
|
||||||
```
|
```
|
||||||
GET /documents
|
GET /api/documents
|
||||||
|
|
||||||
返回文档列表,包含文档ID、文件名、上传时间等信息
|
返回文档列表,包含文档ID、文件名、上传时间等信息
|
||||||
```
|
```
|
||||||
|
@ -206,13 +206,13 @@ easy-rag/
|
||||||
./start.sh
|
./start.sh
|
||||||
|
|
||||||
# 2. 上传文档
|
# 2. 上传文档
|
||||||
curl -X POST "http://localhost:8000/upload" \
|
curl -X POST "http://localhost:8000/api/upload" \
|
||||||
-H "accept: application/json" \
|
-H "accept: application/json" \
|
||||||
-H "Content-Type: multipart/form-data" \
|
-H "Content-Type: multipart/form-data" \
|
||||||
-F "file=@your_document.pdf"
|
-F "file=@your_document.pdf"
|
||||||
|
|
||||||
# 3. 查询问答
|
# 3. 查询问答
|
||||||
curl -X POST "http://localhost:8000/chat" \
|
curl -X POST "http://localhost:8000/api/chat" \
|
||||||
-H "accept: application/json" \
|
-H "accept: application/json" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
|
@ -221,7 +221,7 @@ curl -X POST "http://localhost:8000/chat" \
|
||||||
}'
|
}'
|
||||||
|
|
||||||
# 4. 流式聊天问答
|
# 4. 流式聊天问答
|
||||||
curl -X POST "http://localhost:8000/chat/stream" \
|
curl -X POST "http://localhost:8000/api/chat/stream" \
|
||||||
-H "accept: text/plain" \
|
-H "accept: text/plain" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
|
@ -239,13 +239,13 @@ import json
|
||||||
# 上传文档
|
# 上传文档
|
||||||
with open('document.pdf', 'rb') as f:
|
with open('document.pdf', 'rb') as f:
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
'http://localhost:8000/upload',
|
'http://localhost:8000/api/upload',
|
||||||
files={'file': f}
|
files={'file': f}
|
||||||
)
|
)
|
||||||
|
|
||||||
# 查询问答
|
# 查询问答
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
'http://localhost:8000/chat',
|
'http://localhost:8000/api/chat',
|
||||||
json={
|
json={
|
||||||
'question': '这个文档讲了什么?',
|
'question': '这个文档讲了什么?',
|
||||||
'top_k': 3
|
'top_k': 3
|
||||||
|
@ -256,7 +256,7 @@ print(response.json())
|
||||||
# 流式聊天问答
|
# 流式聊天问答
|
||||||
def stream_chat(question):
|
def stream_chat(question):
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
'http://localhost:8000/chat/stream',
|
'http://localhost:8000/api/chat/stream',
|
||||||
json={'question': question, 'top_k': 3},
|
json={'question': question, 'top_k': 3},
|
||||||
stream=True
|
stream=True
|
||||||
)
|
)
|
||||||
|
@ -286,7 +286,7 @@ stream_chat("详细解释文档的主要观点")
|
||||||
```javascript
|
```javascript
|
||||||
// 流式聊天问答 - 前端实现
|
// 流式聊天问答 - 前端实现
|
||||||
async function streamChat(question) {
|
async function streamChat(question) {
|
||||||
const response = await fetch('/chat/stream', {
|
const response = await fetch('/api/chat/stream', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
|
|
||||||
# 服务器配置
|
# 服务器配置
|
||||||
BASE_URL = "http://localhost:8000"
|
BASE_URL = "http://localhost:8000"
|
||||||
HEALTH_CHECK_ENDPOINT = "/health"
|
HEALTH_CHECK_ENDPOINT = "/api/health"
|
||||||
UPLOAD_ENDPOINT = "/upload"
|
UPLOAD_ENDPOINT = "/api/upload"
|
||||||
CHAT_ENDPOINT = "/chat"
|
CHAT_ENDPOINT = "/api/chat"
|
||||||
DOCUMENTS_ENDPOINT = "/documents"
|
DOCUMENTS_ENDPOINT = "/api/documents"
|
||||||
|
|
||||||
# 并发测试配置
|
# 并发测试配置
|
||||||
CONCURRENT_CONFIG = {
|
CONCURRENT_CONFIG = {
|
||||||
|
|
|
@ -179,7 +179,7 @@ async def upload_document(session: aiohttp.ClientSession, content: str, filename
|
||||||
data = aiohttp.FormData()
|
data = aiohttp.FormData()
|
||||||
data.add_field('file', f, filename=filename, content_type='text/plain')
|
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 {
|
return {
|
||||||
"success": response.status == 200,
|
"success": response.status == 200,
|
||||||
"type": "upload",
|
"type": "upload",
|
||||||
|
@ -198,7 +198,7 @@ async def chat_query(session: aiohttp.ClientSession, question: str):
|
||||||
payload = {"question": question, "top_k": 3, "temperature": 0.7}
|
payload = {"question": question, "top_k": 3, "temperature": 0.7}
|
||||||
|
|
||||||
async with session.post(
|
async with session.post(
|
||||||
"http://localhost:8000/chat",
|
"http://localhost:8000/api/chat",
|
||||||
json=payload,
|
json=payload,
|
||||||
headers={"Content-Type": "application/json"}
|
headers={"Content-Type": "application/json"}
|
||||||
) as response:
|
) as response:
|
||||||
|
|
|
@ -8,7 +8,7 @@ def test_upload_and_chat():
|
||||||
|
|
||||||
# 测试健康检查
|
# 测试健康检查
|
||||||
print("1. 测试健康检查...")
|
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.status_code}")
|
||||||
print(f"响应: {response.json()}")
|
print(f"响应: {response.json()}")
|
||||||
print()
|
print()
|
||||||
|
@ -23,7 +23,7 @@ def test_upload_and_chat():
|
||||||
|
|
||||||
with open("test_doc.txt", "rb") as f:
|
with open("test_doc.txt", "rb") as f:
|
||||||
files = {"file": ("test_doc.txt", f, "text/plain")}
|
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}")
|
print(f"状态码: {response.status_code}")
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
|
@ -37,7 +37,7 @@ def test_upload_and_chat():
|
||||||
|
|
||||||
# 测试文档列表
|
# 测试文档列表
|
||||||
print("3. 测试文档列表...")
|
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.status_code}")
|
||||||
print(f"文档列表: {response.json()}")
|
print(f"文档列表: {response.json()}")
|
||||||
print()
|
print()
|
||||||
|
@ -47,7 +47,7 @@ def test_upload_and_chat():
|
||||||
chat_data = {"question": "什么是人工智能?", "top_k": 3, "temperature": 0.7}
|
chat_data = {"question": "什么是人工智能?", "top_k": 3, "temperature": 0.7}
|
||||||
start_time = datetime.now()
|
start_time = datetime.now()
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
f"{base_url}/chat/stream",
|
f"{base_url}/api/chat/stream",
|
||||||
json=chat_data,
|
json=chat_data,
|
||||||
headers={"Content-Type": "application/json"},
|
headers={"Content-Type": "application/json"},
|
||||||
stream=True,
|
stream=True,
|
||||||
|
|
Loading…
Reference in New Issue