Spaces:
Paused
Paused
| from fastapi import APIRouter, HTTPException | |
| from pydantic import BaseModel | |
| import requests | |
| router = APIRouter() | |
| class QueryRequest(BaseModel): | |
| query: str | |
| async def phi_response(data: QueryRequest): | |
| try: | |
| # Call the Ollama local API to generate a response using the phi model | |
| response = requests.post( | |
| "http://localhost:11434/api/generate", | |
| json={"model": "phi:latest", "prompt": data.query, "stream": False} | |
| ) | |
| response.raise_for_status() | |
| result = response.json() | |
| return {"response": result.get("response", "")} | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=f"Phi error: {str(e)}") | |