Spaces:
Running
Running
| # 用途:如需额外极简推理接口(非OpenAI格式),可启用;无需则可删除 | |
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from utils import generate_response | |
| from config import EXTRA_INFER_PORT | |
| app = FastAPI(title="Phi-3-mini 极简推理接口") | |
| # 简易请求格式(比OpenAI格式更精简,速度略快) | |
| class SimpleInferRequest(BaseModel): | |
| input_text: str # 直接传用户输入,无需嵌套结构 | |
| # 极简接口:/infer | |
| async def simple_infer(request: SimpleInferRequest): | |
| try: | |
| response_text = generate_response([request.input_text])[0] | |
| return {"input": request.input_text, "response": response_text} | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=f"推理失败:{str(e)[:80]}") | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run( | |
| app, | |
| host="0.0.0.0", | |
| port=EXTRA_INFER_PORT, | |
| workers=1, | |
| log_level="warning" | |
| ) |