File size: 715 Bytes
55cfbd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
import requests

router = APIRouter()

class QueryRequest(BaseModel):
    query: str

@router.post("/")
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)}")