diff --git a/README.md b/README.md index 0c52901..62ba55b 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ DeepSearcher combines cutting-edge LLMs (OpenAI o3, Qwen3, DeepSeek, Grok 4, Cla - **Flexible Embedding Options**: Compatible with multiple embedding models for optimal selection. - **Multiple LLM Support**: Supports DeepSeek, OpenAI, and other large models for intelligent Q&A and content generation. - **Document Loader**: Supports local file loading, with web crawling capabilities under development. +- **Web Interface**: Provides a user-friendly web interface for loading documents and performing queries. --- @@ -92,6 +93,33 @@ load_from_website(urls=website_url) # Query result = query("Write a report about xxx.") # Your question here ``` + +### Web Interface + +DeepSearcher now includes a web interface for easier interaction with the system. To use it: + +1. Start the service: +```shell +python main.py +``` + +2. Open your browser and navigate to http://localhost:8000 + +3. Use the web interface to: + - Load local files by specifying their paths + - Load website content by providing URLs + - Perform queries against the loaded data + +You can also enable CORS support for development: +```shell +python main.py --enable-cors +``` + +To customize the host and port: +```shell +python main.py --host 127.0.0.1 --port 8080 +``` + ### Configuration Details: #### LLM Configuration diff --git a/deepsearcher/backend/templates/index.html b/deepsearcher/backend/templates/index.html new file mode 100644 index 0000000..a0ef791 --- /dev/null +++ b/deepsearcher/backend/templates/index.html @@ -0,0 +1,469 @@ + + + + + + DeepSearcher - 智能搜索系统 + + + +
+
+

DeepSearcher 智能搜索系统

+

基于大型语言模型和向量数据库的企业知识管理系统,支持私有数据搜索和在线内容整合,提供准确答案和综合报告。

+
+ +
+
+

文件加载

+
+ + +
+
+ + +
+
+ + +
+ +
+
+ +
+

网站内容加载

+
+ + +
+
+ + +
+
+ + +
+ +
+
+ +
+

智能查询

+
+ + +
+
+ + +
+ +
+
+

查询结果:

+
+
+
+
+
+ + +
+ + + + \ No newline at end of file diff --git a/main.py b/main.py index 197d416..9a29d40 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,9 @@ from typing import Dict, List, Union import uvicorn from fastapi import Body, FastAPI, HTTPException, Query from fastapi.middleware.cors import CORSMiddleware +from fastapi.responses import HTMLResponse from pydantic import BaseModel +import os from deepsearcher.configuration import Configuration, init_config from deepsearcher.offline_loading import load_from_local_files, load_from_website @@ -32,6 +34,62 @@ class ProviderConfigRequest(BaseModel): config: Dict +@app.get("/", response_class=HTMLResponse) +async def read_root(): + """ + Serve the main HTML page. + """ + # 获取当前文件所在目录 + current_dir = os.path.dirname(os.path.abspath(__file__)) + # 构建模板文件路径 - 修复路径问题 + template_path = os.path.join(current_dir, "deepsearcher", "backend", "templates", "index.html") + + # 读取HTML文件内容 + try: + with open(template_path, "r", encoding="utf-8") as file: + html_content = file.read() + return HTMLResponse(content=html_content, status_code=200) + except FileNotFoundError: + # 如果找不到文件,提供一个简单的默认页面 + default_html = """ + + + + DeepSearcher + + + + +
+

DeepSearcher

+
+

欢迎使用 DeepSearcher 智能搜索系统!

+

系统正在运行,但未找到前端模板文件。

+

请确认文件是否存在: {}

+
+
+

API 接口

+

您仍然可以通过以下 API 接口使用系统:

+ +

有关 API 使用详情,请查看 API 文档

+
+
+ + + """.format(template_path) + return HTMLResponse(content=default_html, status_code=200) + + @app.post("/set-provider-config/") def set_provider_config(request: ProviderConfigRequest): """ @@ -194,8 +252,11 @@ def perform_query( if __name__ == "__main__": parser = argparse.ArgumentParser(description="FastAPI Server") - parser.add_argument("--enable-cors", type=bool, default=False, help="Enable CORS support") + parser.add_argument("--host", type=str, default="0.0.0.0", help="Host to bind the server to") + parser.add_argument("--port", type=int, default=8000, help="Port to bind the server to") + parser.add_argument("--enable-cors", action="store_true", default=False, help="Enable CORS support") args = parser.parse_args() + if args.enable_cors: app.add_middleware( CORSMiddleware, @@ -207,4 +268,6 @@ if __name__ == "__main__": print("CORS is enabled.") else: print("CORS is disabled.") - uvicorn.run(app, host="0.0.0.0", port=8000) + + print(f"Starting server on {args.host}:{args.port}") + uvicorn.run(app, host=args.host, port=args.port) \ No newline at end of file