25 lines
578 B
Python
25 lines
578 B
Python
import requests
|
|
import json
|
|
|
|
config = {}
|
|
config["gen_host"] = os.environ.get("GEN_HOST","")
|
|
|
|
if not config["gen_host"]:
|
|
raise ValueError("Generative backend invalid")
|
|
|
|
class OllamaService:
|
|
def __init__(self):
|
|
self.url = f"http://{config["gen_host"]}:11434/api/generate"
|
|
|
|
def generate(self, prompt: str):
|
|
payload = {
|
|
"model": "llama3.1:8b",
|
|
"prompt": prompt,
|
|
"stream": False
|
|
}
|
|
|
|
response = requests.post(self.url, json=payload)
|
|
data = response.json()
|
|
|
|
return data.get("response", "")
|