Adicionar app/services/ollama_service.py
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
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", "")
|
||||||
Reference in New Issue
Block a user