fix: Qwen3.5 /nothink 모드 + json_mode 파라미터 추가

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-03-26 13:33:23 +09:00
parent a77477140b
commit 948be1624f
2 changed files with 16 additions and 5 deletions

View File

@@ -106,17 +106,28 @@ def run_applescript_inline(script: str) -> str:
def llm_generate(prompt: str, model: str = "mlx-community/Qwen3.5-35B-A3B-4bit",
host: str = "http://localhost:8800") -> str:
host: str = "http://localhost:8800", json_mode: bool = False) -> str:
"""MLX 서버 API 호출 (OpenAI 호환)"""
import requests
messages = []
if json_mode:
messages.append({"role": "system", "content": "You must respond ONLY with valid JSON. No thinking, no explanation, no markdown."})
# Qwen3.5: /nothink 접미사로 thinking 출력 억제
messages.append({"role": "user", "content": prompt + " /nothink"})
resp = requests.post(f"{host}/v1/chat/completions", json={
"model": model,
"messages": [{"role": "user", "content": prompt}],
"messages": messages,
"temperature": 0.3,
"max_tokens": 1024,
}, timeout=120)
resp.raise_for_status()
return resp.json()["choices"][0]["message"]["content"]
content = resp.json()["choices"][0]["message"]["content"]
# JSON 블록 추출 (```json ... ``` 감싸기 대응)
if "```json" in content:
content = content.split("```json")[1].split("```")[0].strip()
elif "```" in content:
content = content.split("```")[1].split("```")[0].strip()
return content
# 하위호환 별칭