-
Notifications
You must be signed in to change notification settings - Fork 0
/
clients.py
32 lines (28 loc) · 1.01 KB
/
clients.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import requests
class GPTClient:
def __init__(self, url, model):
self.url = url
self.model = model
def query(self, prompt):
"""
Send the final prompt to the local GPT (Ollama) and return response text.
"""
try:
payload = {
"prompt": prompt,
"model": self.model,
"stream": False
}
resp = requests.post(self.url, json=payload, timeout=120)
resp.raise_for_status()
data = resp.json()
# If it's a list, might be streaming tokens
if isinstance(data, list):
return "".join(part.get("response", "") for part in data).strip()
elif isinstance(data, dict):
return data.get("response", "").strip()
else:
return "No valid response from local GPT."
except Exception as e:
print("[ERROR] GPT query failed:", e)
return "Error: Could not reach local GPT."