@devries-cameron20 / OCIU-npo Mirror · read-only
Fork 0

Mirrored from https://github.com/Camo67/OCIU-npo.git

Synced Nov 21, 07:15 UTC

1 import os
2 import httpx
3 from typing import Dict, Any
4
5 class OllamaClient:
6 def __init__(self):
7 self.base_url = os.getenv("OLLAMA_BASE_URL", "http://localhost:11434")
8
9 async def generate(self, model: str, prompt: str) -> str:
10 async with httpx.AsyncClient(timeout=60.0) as client:
11 try:
12 response = await client.post(
13 f"{self.base_url}/api/generate",
14 json={"model": model, "prompt": prompt, "stream": False}
15 )
16 response.raise_for_status()
17 return response.json().get("response", "")
18 except Exception as e:
19 return f"Error calling Ollama: {str(e)}"
20
21 ollama_client = OllamaClient()