mirror of
https://github.com/stardrophere/InsightRadar.git
synced 2026-06-06 00:57:51 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 531844f33c | |||
| 76f00db86d | |||
| 761fad17bc | |||
| 0cab5c1cda | |||
| 9574b02d8a | |||
| c48c2b9143 | |||
| cdad76cd3b | |||
| d3e59bc7f3 |
+3
-4
@@ -37,9 +37,6 @@ MANIFEST
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# uv
|
||||
*.lock
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
@@ -192,4 +189,6 @@ cython_debug/
|
||||
|
||||
**/data/*
|
||||
**/docker/*
|
||||
backend/app/static/*
|
||||
backend/app/static/*
|
||||
|
||||
test*.*
|
||||
@@ -24,6 +24,10 @@ def get_multi(db: Session, skip: int = 0, limit: int = 100) -> List[InfoSource]:
|
||||
def create(db: Session, obj_in: InfoSourceCreate) -> InfoSource:
|
||||
"""创建新的信息源"""
|
||||
db_obj = InfoSource(**obj_in.model_dump())
|
||||
exits =db.query(InfoSource).filter(InfoSource.source_name == db_obj.source_name).first()
|
||||
if exits:
|
||||
db.close()
|
||||
return db_obj
|
||||
try:
|
||||
db.add(db_obj)
|
||||
db.commit()
|
||||
|
||||
+17
-5
@@ -1,10 +1,11 @@
|
||||
# app/main.py
|
||||
import logging
|
||||
import os
|
||||
from fastapi.responses import FileResponse
|
||||
from pathlib import Path
|
||||
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
|
||||
import httpx
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI, staticfiles
|
||||
from fastapi import FastAPI, HTTPException, Request, staticfiles
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from dotenv import load_dotenv
|
||||
|
||||
@@ -112,14 +113,25 @@ app.add_middleware(
|
||||
# 版本控制
|
||||
app.include_router(api_router, prefix="/api/v1")
|
||||
|
||||
# 把目录改成static对应我们放dist内容的路径就可以
|
||||
app.mount("/", staticfiles.StaticFiles(directory="app/static", html=True), name="static")
|
||||
|
||||
# 只需要保留API的优先匹配,catch_all可以简化成这样
|
||||
@app.get("/api/{full_path:path}")
|
||||
async def api_not_found(full_path: str):
|
||||
return {"detail": "API Not Found"}
|
||||
|
||||
staticPath = staticfiles.StaticFiles(directory="app/static", html=True)
|
||||
|
||||
# 把目录改成static对应我们放dist内容的路径就可以
|
||||
app.mount("/", staticPath, name="static")
|
||||
|
||||
INDEX_HTML = Path("app/static/index.html").read_text(encoding="utf-8")
|
||||
|
||||
@app.exception_handler(404)
|
||||
async def not_found_handler(request: Request, exc: HTTPException):
|
||||
# 如果是API路径才返回404,前端路径走catch-all不会进这里
|
||||
if request.url.path.startswith("/api/"):
|
||||
return JSONResponse({"detail": "Not Found"}, status_code=404)
|
||||
return HTMLResponse(INDEX_HTML)
|
||||
|
||||
# 健康检查
|
||||
@app.get("/", tags=["健康检查"])
|
||||
async def root():
|
||||
|
||||
@@ -26,9 +26,9 @@ SIMILARITY_THRESHOLD = float(os.getenv("SIMILARITY_THRESHOLD", 0.72))
|
||||
API_BASE_URL = os.getenv("API_BASE_URL", "https://newsnow.busiyi.world/api/s")
|
||||
EMBEDDING_MODEL_PATH = os.getenv("EMBEDDING_MODEL_PATH", "")
|
||||
|
||||
print("正在加载 BAAI/bge-m3 向量模型...")
|
||||
print("正在加载模型...")
|
||||
# 全局单例
|
||||
embedder_model = SentenceTransformer(EMBEDDING_MODEL_PATH, local_files_only=True, device="cuda")
|
||||
embedder_model = SentenceTransformer(EMBEDDING_MODEL_PATH, local_files_only=True)
|
||||
print("模型加载完成。")
|
||||
|
||||
|
||||
|
||||
+12
-3
@@ -49,7 +49,6 @@ dependencies = [
|
||||
"safetensors==0.7.0",
|
||||
"scikit-learn==1.8.0",
|
||||
"scipy==1.17.1",
|
||||
"sentence-transformers==5.2.3",
|
||||
"shellingham==1.5.4",
|
||||
"sniffio==1.3.1",
|
||||
"sqlalchemy==2.0.48",
|
||||
@@ -57,8 +56,6 @@ dependencies = [
|
||||
"sympy==1.14.0",
|
||||
"threadpoolctl==3.6.0",
|
||||
"tokenizers==0.22.2",
|
||||
"torch==2.10.0",
|
||||
"torchvision==0.25.0",
|
||||
"tqdm==4.67.3",
|
||||
"transformers==5.3.0",
|
||||
"typer==0.24.1",
|
||||
@@ -68,4 +65,16 @@ dependencies = [
|
||||
"tzlocal==5.3.1",
|
||||
"urllib3==2.6.3",
|
||||
"uvicorn==0.41.0",
|
||||
"torch==2.11.0+cpu",
|
||||
"torchvision==0.26.0+cpu",
|
||||
"torchaudio==2.11.0+cpu",
|
||||
"sentence-transformers>=5.3.0",
|
||||
]
|
||||
|
||||
[[tool.uv.index]]
|
||||
name = "pytorch-cpu"
|
||||
url = "https://download.pytorch.org/whl/cpu"
|
||||
default = false
|
||||
|
||||
[tool.uv]
|
||||
index-strategy = "unsafe-best-match"
|
||||
|
||||
Generated
+1720
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -20,7 +20,7 @@ WORKDIR /backend
|
||||
COPY backend/pyproject.toml backend/uv.lock ./
|
||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
pip install --no-cache-dir uv && \
|
||||
uv sync --frozen --no-dev
|
||||
uv sync --frozen --no-dev --index https://pypi.tuna.tsinghua.edu.cn/simple/
|
||||
|
||||
# 复制后端代码
|
||||
COPY backend/app ./app
|
||||
|
||||
Reference in New Issue
Block a user