fix: Phase 2 버그 픽스 — JP 번역, API 서버, AppleScript 경로

- pkm_utils.py: strip_thinking() 추가 + llm_generate() no_think 옵션
  - <think> 태그 제거 + thinking 패턴("Wait,", "Let me" 등) 필터링
  - enable_thinking: false 파라미터 지원
- law_monitor.py: JP 번역 호출에 no_think=True 적용
- pkm_api_server.py: /devonthink/stats 최적화 (children 순회 → count 사용)
  + /devonthink/search 한글 쿼리 이스케이프 수정
- auto_classify.scpt: baseDir property로 경로 변수화
- omnifocus_sync.scpt: 로그 경로 변수화

인프라: MailPlus IMAP HOST → LAN IP(192.168.1.227)로 변경
참고: 한국 법령 API IP(122.153.226.74) open.law.go.kr 등록 필요

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hyungi
2026-03-30 14:00:46 +09:00
parent f21f950c04
commit dc3f03b421
5 changed files with 59 additions and 38 deletions

View File

@@ -105,19 +105,40 @@ def run_applescript_inline(script: str) -> str:
raise RuntimeError("AppleScript 타임아웃 (인라인)")
def strip_thinking(text: str) -> str:
"""LLM thinking 출력 제거 — <think>...</think> 태그 및 thinking 패턴 필터링"""
import re
# <think>...</think> 태그 제거
text = re.sub(r'<think>[\s\S]*?</think>\s*', '', text)
# "Wait,", "Let me", "I'll check" 등으로 시작하는 thinking 줄 제거
lines = text.strip().split('\n')
filtered = [l for l in lines if not re.match(
r'^\s*(Wait|Let me|I\'ll|Hmm|OK,|Okay|Let\'s|Actually|So,|First)', l, re.IGNORECASE
)]
return '\n'.join(filtered).strip() if filtered else text.strip()
def llm_generate(prompt: str, model: str = "mlx-community/Qwen3.5-35B-A3B-4bit",
host: str = "http://localhost:8800", json_mode: bool = False) -> str:
"""MLX 서버 API 호출 (OpenAI 호환)"""
host: str = "http://localhost:8800", json_mode: bool = False,
no_think: bool = False) -> str:
"""MLX 서버 API 호출 (OpenAI 호환)
no_think=True: thinking 비활성화 + 응답 필터링 (번역 등 단순 작업용)
"""
import requests
messages = [{"role": "user", "content": prompt}]
resp = requests.post(f"{host}/v1/chat/completions", json={
payload = {
"model": model,
"messages": messages,
"temperature": 0.3,
"max_tokens": 4096,
}, timeout=300)
}
if no_think:
payload["enable_thinking"] = False
resp = requests.post(f"{host}/v1/chat/completions", json=payload, timeout=300)
resp.raise_for_status()
content = resp.json()["choices"][0]["message"]["content"]
if no_think:
content = strip_thinking(content)
if not json_mode:
return content
# JSON 모드: thinking 허용 → 마지막 유효 JSON 객체 추출