diff --git a/mempalace/llm_client.py b/mempalace/llm_client.py index f6292fa..9e1a92c 100644 --- a/mempalace/llm_client.py +++ b/mempalace/llm_client.py @@ -140,7 +140,21 @@ class LLMProvider: # require explicit user confirmation. self.api_key_source = api_key_source - def classify(self, system: str, user: str, json_mode: bool = True) -> LLMResponse: + def classify( + self, + system: str, + user: str, + json_mode: bool = True, + think: Optional[bool] = None, + ) -> LLMResponse: + """Classify a (system, user) pair into a structured response. + + ``think`` controls reasoning emission for thinking-capable models + (currently honored by ``OllamaProvider`` for Qwen 3 / DeepSeek-R1 + style toggles). Other providers ignore it. Pass ``False`` to + disable reasoning when the caller wants a fast classification + without ```` overhead. + """ raise NotImplementedError def check_available(self) -> tuple[bool, str]: @@ -221,7 +235,13 @@ class OllamaProvider(LLMProvider): ) return True, "ok" - def classify(self, system: str, user: str, json_mode: bool = True) -> LLMResponse: + def classify( + self, + system: str, + user: str, + json_mode: bool = True, + think: Optional[bool] = None, + ) -> LLMResponse: body: dict = { "model": self.model, "messages": [ @@ -233,6 +253,12 @@ class OllamaProvider(LLMProvider): } if json_mode: body["format"] = "json" + if think is not None: + # Ollama 0.7+ supports `think` for thinking-capable models (Qwen 3 + # family, DeepSeek-R1). Pure-instruct models ignore it. We forward + # only when the caller explicitly opts in/out so the wire format + # stays minimal for the common case. + body["think"] = think data = _http_post_json(f"{self.endpoint}/api/chat", body, headers={}, timeout=self.timeout) text = (data.get("message") or {}).get("content", "") if not text: @@ -300,7 +326,13 @@ class OpenAICompatProvider(LLMProvider): return False, f"Cannot reach {self.endpoint}: {e}" return True, "ok" - def classify(self, system: str, user: str, json_mode: bool = True) -> LLMResponse: + def classify( + self, + system: str, + user: str, + json_mode: bool = True, + think: Optional[bool] = None, # noqa: ARG002 — accepted for interface compat; OpenAI-compat has no thinking toggle + ) -> LLMResponse: body: dict = { "model": self.model, "messages": [ @@ -362,7 +394,13 @@ class AnthropicProvider(LLMProvider): # surface auth errors if the key is invalid. return True, "ok" - def classify(self, system: str, user: str, json_mode: bool = True) -> LLMResponse: + def classify( + self, + system: str, + user: str, + json_mode: bool = True, + think: Optional[bool] = None, # noqa: ARG002 — accepted for interface compat; Anthropic extended thinking is configured separately + ) -> LLMResponse: if not self.api_key: raise LLMError("Anthropic provider requires ANTHROPIC_API_KEY env or --llm-api-key") sys_prompt = system