Spaces:
Runtime error
Runtime error
File size: 1,527 Bytes
4836039 a5081b6 611cff1 5273e65 4836039 b916cdf 611cff1 b916cdf 5273e65 5e8c185 4836039 45ed5ce a5081b6 4836039 733bea7 eacb76c 0995744 a5081b6 eacb76c a5081b6 0995744 9ebbf3c | 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 49 50 51 52 53 | from fastapi import FastAPI,Request
from fastapi.responses import StreamingResponse
from fastapi.middleware.cors import CORSMiddleware
from service.vector_store import vector_store
from service.api import api
from service.scheduler import Scheduler
from pydantic import BaseModel
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # 允许所有来源
allow_credentials=True,
allow_methods=["*"], # 允许所有方法
allow_headers=["*"], # 允许所有头
)
scheduler = Scheduler()
scheduler.run()
@app.get("/")
def read_root():
return {"Hello": "World!"}
@app.get("/api/search")
def search(request: Request, inputs: str):
client_host = request.client.host
x_forwarded_for = request.headers.get("x-forwarded-for")
if x_forwarded_for:
client_host = x_forwarded_for.split(",")[0] # 取X-Forwarded-For头的第一个值
print(f"client_host: {client_host}")
return vector_store.search(inputs)
## FILECOIN WEB COMPLETE API
@app.get("/api/suggestion")
def get_suggestion(inputs: str):
return api.get_suggestion(inputs)
## FILECOIN WEB ASNWER API
@app.get("/api/answer")
async def get_answer(inputs: str):
return StreamingResponse(api.get_answer(inputs))
class AnswerRequest(BaseModel):
inputs: str
@app.post("/api/answer_v2")
async def post_answer(request: AnswerRequest):
# 假设 api.get_answer() 需要 description 和 link 两个参数
response = api.get_answer_v2(request.inputs)
return StreamingResponse(response) |