diff --git a/api/Dockerfile b/api/Dockerfile index 24930cb..020bad5 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -14,4 +14,4 @@ RUN mkdir -p /app/data EXPOSE 8100 -CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8100", "--reload"] +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8100", "--reload"] diff --git a/api/README.md b/api/README.md index 2bbe605..0862cb6 100644 --- a/api/README.md +++ b/api/README.md @@ -25,7 +25,7 @@ python init_db.py ```bash # 开发模式 (热重载) -python -m uvicorn main:app --reload --host 0.0.0.0 --port 8100 +python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8100 ``` 服务运行在: http://localhost:8100 @@ -65,18 +65,18 @@ curl http://localhost:8100/api/history | | | PUT | 更新声音 | | | | DELETE | 删除声音 | | | `/api/voices/{id}/preview` | POST | 预览声音 | -| **LLM Models** | `/api/models/llm` | GET | LLM 模型列表 | +| **LLM Models** | `/api/llm` | GET | LLM 模型列表 | | | | POST | 添加模型 | -| | `/api/models/llm/{id}` | GET | 模型详情 | +| | `/api/llm/{id}` | GET | 模型详情 | | | | PUT | 更新模型 | | | | DELETE | 删除模型 | -| | `/api/models/llm/{id}/test` | POST | 测试模型连接 | -| **ASR Models** | `/api/models/asr` | GET | ASR 模型列表 | +| | `/api/llm/{id}/test` | POST | 测试模型连接 | +| **ASR Models** | `/api/asr` | GET | ASR 模型列表 | | | | POST | 添加模型 | -| | `/api/models/asr/{id}` | GET | 模型详情 | +| | `/api/asr/{id}` | GET | 模型详情 | | | | PUT | 更新模型 | | | | DELETE | 删除模型 | -| | `/api/models/asr/{id}/test` | POST | 测试识别 | +| | `/api/asr/{id}/test` | POST | 测试识别 | | **History** | `/api/history` | GET | 通话历史列表 | | | `/api/history/{id}` | GET | 通话详情 | | | | PUT | 更新通话记录 | @@ -213,7 +213,6 @@ api/ ├── requirements.txt ├── .env ├── init_db.py -├── main.py └── docker-compose.yml ``` diff --git a/api/main.py b/api/main.py deleted file mode 100644 index cf659b0..0000000 --- a/api/main.py +++ /dev/null @@ -1,113 +0,0 @@ -from fastapi import FastAPI -from fastapi.middleware.cors import CORSMiddleware -from contextlib import asynccontextmanager -import os - -from app.db import Base, engine -from app.routers import assistants, history, knowledge - -# 配置 -PORT = int(os.getenv("PORT", 8100)) - - -@asynccontextmanager -async def lifespan(app: FastAPI): - # 启动时创建表 - Base.metadata.create_all(bind=engine) - yield - - -app = FastAPI( - title="AI VideoAssistant API", - description="Backend API for AI VideoAssistant", - version="1.0.0", - lifespan=lifespan -) - -# CORS -app.add_middleware( - CORSMiddleware, - allow_origins=["*"], - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], -) - -# 路由 -app.include_router(assistants.router, prefix="/api") -app.include_router(history.router, prefix="/api") -app.include_router(knowledge.router, prefix="/api") - - -@app.get("/") -def root(): - return {"message": "AI VideoAssistant API", "version": "1.0.0"} - - -@app.get("/health") -def health(): - return {"status": "ok"} - - -# 初始化默认数据 -@app.on_event("startup") -def init_default_data(): - from sqlalchemy.orm import Session - from app.db import SessionLocal - from app.models import Voice - - db = SessionLocal() - try: - # 检查是否已有数据 - if db.query(Voice).count() == 0: - # SiliconFlow CosyVoice 2.0 预设声音 (8个) - # 参考: https://docs.siliconflow.cn/cn/api-reference/audio/create-speech - voices = [ - # 男声 (Male Voices) - Voice(id="alex", name="Alex", vendor="SiliconFlow", gender="Male", language="en", - description="Steady male voice.", is_system=True), - Voice(id="benjamin", name="Benjamin", vendor="SiliconFlow", gender="Male", language="en", - description="Deep male voice.", is_system=True), - Voice(id="charles", name="Charles", vendor="SiliconFlow", gender="Male", language="en", - description="Magnetic male voice.", is_system=True), - Voice(id="david", name="David", vendor="SiliconFlow", gender="Male", language="en", - description="Cheerful male voice.", is_system=True), - # 女声 (Female Voices) - Voice(id="anna", name="Anna", vendor="SiliconFlow", gender="Female", language="en", - description="Steady female voice.", is_system=True), - Voice(id="bella", name="Bella", vendor="SiliconFlow", gender="Female", language="en", - description="Passionate female voice.", is_system=True), - Voice(id="claire", name="Claire", vendor="SiliconFlow", gender="Female", language="en", - description="Gentle female voice.", is_system=True), - Voice(id="diana", name="Diana", vendor="SiliconFlow", gender="Female", language="en", - description="Cheerful female voice.", is_system=True), - # 中文方言 (Chinese Dialects) - 可选扩展 - Voice(id="amador", name="Amador", vendor="SiliconFlow", gender="Male", language="zh", - description="Male voice with Spanish accent."), - Voice(id="aelora", name="Aelora", vendor="SiliconFlow", gender="Female", language="en", - description="Elegant female voice."), - Voice(id="aelwin", name="Aelwin", vendor="SiliconFlow", gender="Male", language="en", - description="Deep male voice."), - Voice(id="blooming", name="Blooming", vendor="SiliconFlow", gender="Female", language="en", - description="Fresh and clear female voice."), - Voice(id="elysia", name="Elysia", vendor="SiliconFlow", gender="Female", language="en", - description="Smooth and silky female voice."), - Voice(id="leo", name="Leo", vendor="SiliconFlow", gender="Male", language="en", - description="Young male voice."), - Voice(id="lin", name="Lin", vendor="SiliconFlow", gender="Female", language="zh", - description="Standard Chinese female voice."), - Voice(id="rose", name="Rose", vendor="SiliconFlow", gender="Female", language="en", - description="Soft and gentle female voice."), - Voice(id="shao", name="Shao", vendor="SiliconFlow", gender="Male", language="zh", - description="Deep Chinese male voice."), - Voice(id="sky", name="Sky", vendor="SiliconFlow", gender="Male", language="en", - description="Clear and bright male voice."), - Voice(id="ael西山", name="Ael西山", vendor="SiliconFlow", gender="Female", language="zh", - description="Female voice with Chinese dialect."), - ] - for v in voices: - db.add(v) - db.commit() - print("✅ 默认声音数据已初始化 (SiliconFlow CosyVoice 2.0)") - finally: - db.close()