Spaces:
Running
Running
File size: 1,241 Bytes
7cc8bc0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
from typing import Dict, Any
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from .llm_api import DeepseekInterface
from .search_api import GoogleSearch
def create_app(config: Dict[str, Any] = None) -> FastAPI:
"""
创建并配置 FastAPI 应用
"""
app = FastAPI(
title="Travel RAG API",
description="Travel recommendation system using RAG",
version="1.0.0"
)
# 配置 CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 初始化配置
if config:
app.state.config = config
# 初始化 LLM
app.state.llm = DeepseekInterface(
api_key=config['deepseek_api_key'],
base_url=config['llm_settings']['deepseek']['base_url'],
model=config['llm_settings']['deepseek']['models'][0]
)
# 初始化搜索引擎在 init_app 中完成
from .routes import init_app
init_app(app)
# 导入和注册路由
from .routes import router
app.include_router(router)
return app
__all__ = ['create_app']
|