GhadaSaylami commited on
Commit
6f7940e
·
verified ·
1 Parent(s): 1741611

Update src/llm/langchain_llm.py

Browse files
Files changed (1) hide show
  1. src/llm/langchain_llm.py +18 -11
src/llm/langchain_llm.py CHANGED
@@ -69,18 +69,25 @@ _API_KEY_VARS = {
69
 
70
 
71
  def _reasoning_kwargs(provider: str, model_name: str) -> dict:
72
- """Deliberately returns {} — server-side reasoning suppression disabled.
73
-
74
- Groq's `reasoning_format: "hidden"` switch, forwarded through this
75
- langchain-groq version, produced an empty final message instead of a
76
- hidden-reasoning-plus-answer response (observed in production: the LLM
77
- call succeeded with no exception, but engine.sanitize_reply logged "LLM
78
- returned an empty reply"). Rather than fight that server-side behaviour,
79
- reasoning models are left to emit their full <think>...</think> block,
80
- and engine.strip_reasoning (called from engine.sanitize_reply on every
81
- reply) strips it client-side — the same client-side cleanup CLAUDE.md
82
- already documents as the second of two independent suppression layers.
 
 
83
  """
 
 
 
 
 
84
  return {}
85
 
86
 
 
69
 
70
 
71
  def _reasoning_kwargs(provider: str, model_name: str) -> dict:
72
+ """Ask Groq to hide reasoning-model chain-of-thought from the response.
73
+
74
+ Qwen/MiniMax/DeepSeek are reasoning models that otherwise spend the
75
+ completion's token budget on visible <think>...</think> content before
76
+ ever reaching the answer — observed in production: with a 2048-token
77
+ budget and no hidden-reasoning switch, the model's reasoning alone
78
+ exhausted it, the response was cut off mid-<think> block with no closing
79
+ tag, and engine.strip_reasoning correctly treated that as "the answer
80
+ never arrived", leaving an empty reply. `reasoning_format` is a top-level
81
+ ChatGroq constructor argument in this langchain-groq version, not a
82
+ model_kwargs entry — passing it inside model_kwargs raises a pydantic
83
+ ValidationError, which is why this returns a plain dict of top-level
84
+ kwargs rather than nesting it.
85
  """
86
+ if provider != "groq":
87
+ return {}
88
+ model = (model_name or "").lower()
89
+ if any(fam in model for fam in ("qwen", "minimax", "deepseek")):
90
+ return {"reasoning_format": "hidden"}
91
  return {}
92
 
93