Spaces:
Runtime error
Runtime error
Download main.py from JR818/JarvisFastAPI: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/JR818/JarvisFastAPI/resolve/524fd18baf44cf2bf5561fa52a53279dc9a54fbd/main.py
- Command line
-
hf download hf://spaces/JR818/JarvisFastAPI@524fd18baf44cf2bf5561fa52a53279dc9a54fbd/main.py
-
curl -L -o main.py https://huggingface.co/spaces/JR818/JarvisFastAPI/resolve/524fd18baf44cf2bf5561fa52a53279dc9a54fbd/main.py
1.19 kB
| 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() | |
| def read_root(): | |
| return {"Hello": "World!"} | |
| 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) | |
| def get_suggestion(inputs: str): | |
| return api.get_suggestion(inputs) | |
| async def get_answer(inputs: str): | |
| return StreamingResponse(api.get_answer(inputs)) |