refactor: replace Ollama client with HTTPX for API requests in AIPlanner

This commit is contained in:
kswdev0
2026-03-27 10:59:43 +09:00
parent 3fccbb20eb
commit dabce8b6fb

View File

@@ -19,7 +19,7 @@ import sys
import time import time
import threading import threading
import traceback import traceback
import ollama import httpx
OLLAMA_MODEL = os.environ.get("OLLAMA_MODEL", "qwen3.5:9b") OLLAMA_MODEL = os.environ.get("OLLAMA_MODEL", "qwen3.5:9b")
@@ -192,14 +192,13 @@ class AIPlanner:
spinner.start() spinner.start()
try: try:
client = ollama.Client(host=OLLAMA_HOST) payload = {
response = client.chat( "model": OLLAMA_MODEL,
model=OLLAMA_MODEL, "messages": [
messages=[
{"role": "system", "content": SYSTEM_PROMPT}, {"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": "/no_think\n" + user_message}, {"role": "user", "content": user_message},
], ],
format={ "format": {
"type": "object", "type": "object",
"properties": { "properties": {
"thinking": {"type": "string"}, "thinking": {"type": "string"},
@@ -220,14 +219,23 @@ class AIPlanner:
}, },
"required": ["actions"], "required": ["actions"],
}, },
options={"temperature": 0.3, "num_ctx": 8192}, "think": False,
"stream": False,
"options": {"temperature": 0.3, "num_ctx": 8192},
}
resp = httpx.post(
f"{OLLAMA_HOST}/api/chat",
json=payload,
timeout=300.0,
) )
resp.raise_for_status()
data = resp.json()
finally: finally:
stop_event.set() stop_event.set()
spinner.join() spinner.join()
dt = time.perf_counter() - t0 dt = time.perf_counter() - t0
content = response.message.content content = data["message"]["content"]
print(f"[AI] 응답 수신 ({dt:.2f}s, {len(content)}자)") print(f"[AI] 응답 수신 ({dt:.2f}s, {len(content)}자)")
if _debug_enabled(): if _debug_enabled():
print(f"[AI][디버그] raw={content[:300]}") print(f"[AI][디버그] raw={content[:300]}")