Add independent thinking-mode controls

This commit is contained in:
2026-09-23 00:36:45 +08:00
parent b645190ea5
commit 0f0594bc41
5 changed files with 18 additions and 2 deletions
+11
View File
@@ -16,6 +16,7 @@ class LLMClientConfig:
base_url: str = "https://api.openai.com/v1"
api_style: str = "responses"
timeout_seconds: int = 240
enable_thinking: bool | None = None
@classmethod
def from_env(cls, role: str) -> "LLMClientConfig":
@@ -25,6 +26,7 @@ class LLMClientConfig:
base_url = os.getenv(f"{prefix}_BASE_URL", "").strip()
api_style = os.getenv(f"{prefix}_API_STYLE", "").strip() or "responses"
timeout_text = os.getenv(f"{prefix}_TIMEOUT_SECONDS", "").strip()
thinking_text = os.getenv(f"{prefix}_ENABLE_THINKING", "").strip().lower()
if not model:
raise ValueError(f"{prefix}_MODEL is required")
if not api_key:
@@ -36,12 +38,16 @@ class LLMClientConfig:
timeout_seconds = int(timeout_text) if timeout_text else 240
if timeout_seconds < 1:
raise ValueError(f"{prefix}_TIMEOUT_SECONDS must be positive")
if thinking_text not in {"", "true", "false"}:
raise ValueError(f"{prefix}_ENABLE_THINKING must be true or false")
enable_thinking = None if not thinking_text else thinking_text == "true"
return cls(
model=model,
api_key=api_key,
base_url=base_url.rstrip("/"),
api_style=api_style,
timeout_seconds=timeout_seconds,
enable_thinking=enable_thinking,
)
@@ -92,6 +98,9 @@ class LLMClient:
"max_tokens": 2500,
}
if self.config.enable_thinking is not None:
body["enable_thinking"] = self.config.enable_thinking
text = self._post(path, body)
try:
result = json.loads(text)
@@ -122,6 +131,8 @@ class LLMClient:
],
"max_tokens": 512,
}
if self.config.enable_thinking is not None:
body["enable_thinking"] = self.config.enable_thinking
return self._post(path, body)
def _post(self, path: str, body: dict[str, Any]) -> str: