refactor: replace Ollama client with HTTPX for API requests in AIPlanner
This commit is contained in:
@@ -19,7 +19,7 @@ import sys
|
||||
import time
|
||||
import threading
|
||||
import traceback
|
||||
import ollama
|
||||
import httpx
|
||||
|
||||
|
||||
OLLAMA_MODEL = os.environ.get("OLLAMA_MODEL", "qwen3.5:9b")
|
||||
@@ -192,14 +192,13 @@ class AIPlanner:
|
||||
spinner.start()
|
||||
|
||||
try:
|
||||
client = ollama.Client(host=OLLAMA_HOST)
|
||||
response = client.chat(
|
||||
model=OLLAMA_MODEL,
|
||||
messages=[
|
||||
payload = {
|
||||
"model": OLLAMA_MODEL,
|
||||
"messages": [
|
||||
{"role": "system", "content": SYSTEM_PROMPT},
|
||||
{"role": "user", "content": "/no_think\n" + user_message},
|
||||
{"role": "user", "content": user_message},
|
||||
],
|
||||
format={
|
||||
"format": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"thinking": {"type": "string"},
|
||||
@@ -220,14 +219,23 @@ class AIPlanner:
|
||||
},
|
||||
"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:
|
||||
stop_event.set()
|
||||
spinner.join()
|
||||
|
||||
dt = time.perf_counter() - t0
|
||||
content = response.message.content
|
||||
content = data["message"]["content"]
|
||||
print(f"[AI] 응답 수신 ({dt:.2f}s, {len(content)}자)")
|
||||
if _debug_enabled():
|
||||
print(f"[AI][디버그] raw={content[:300]}")
|
||||
|
||||
Reference in New Issue
Block a user