Disable DeepSeek thinking when a tool is forced.

Auto-resolve of passives was 400ing because thinking mode cannot be combined with named tool_choice. Also strip BOM descriptions after an em dash before DigiKey search.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-28 01:58:22 +02:00
co-authored by Cursor
parent 776d714754
commit 27a3ce8bd0
5 changed files with 76 additions and 6 deletions
+4
View File
@@ -105,6 +105,10 @@ def mpn_query_variants(mpn: str) -> list[str]:
add(raw)
add(raw.replace("_", "/"))
add(raw.replace("/", "_"))
for sep in ("", " ", " - "):
if sep in raw:
add(raw.split(sep, 1)[0])
break
if "," in raw:
add(raw.split(",", 1)[0])
if len(_alnum(raw)) > 8 and raw[-1] in "Rr" and raw[-2].isalnum():
+19 -2
View File
@@ -113,11 +113,19 @@ def _find_product(mpn: str, products: list[dict]) -> dict | None:
Prefers punctuation-insensitive equality, then packing suffixes, then a
longer orderable code that starts with the BOM MPN. Does not fall back
to ``products[0]``.
to ``products[0]``. Tries BOM spelling variants (underscore, reel, extra
description after an em dash).
"""
if not products:
return None
for query in mpn_query_variants(mpn):
hit = _find_product_one(query, products)
if hit:
return hit
return None
def _find_product_one(mpn: str, products: list[dict]) -> dict | None:
exact = None
loose = None
family = None
@@ -325,7 +333,16 @@ async def fetch_params(mpn: str) -> ParamsFetchResult:
return ParamsFetchResult(mpn, error="DigiKey API not configured")
try:
products = await _keyword_search(mpn)
products: list[dict] = []
tried: set[str] = set()
for keyword in mpn_query_variants(mpn):
key = keyword.upper()
if key in tried:
continue
tried.add(key)
products = await _keyword_search(keyword)
if _find_product(mpn, products):
break
except httpx.HTTPStatusError as e:
logger.warning("DigiKey search failed for %s: %s", mpn, e)
return ParamsFetchResult(mpn, error=f"DigiKey search failed ({e.response.status_code})")
+8 -2
View File
@@ -253,10 +253,16 @@ class DeepSeekSession(LLMSession):
]
oai_messages.extend(messages_to_openai(messages, vision=self._vision))
# DeepSeek rejects forced tool_choice while thinking is on
# ("Thinking mode does not support this tool_choice"). Auto-resolve
# and extraction always force a save_* tool, so drop thinking there.
forced_tool = isinstance(tool_choice, dict) and "name" in tool_choice
thinking = self._thinking and not forced_tool
extra_body: dict[str, Any] = {
"thinking": {"type": "enabled" if self._thinking else "disabled"},
"thinking": {"type": "enabled" if thinking else "disabled"},
}
if self._thinking:
if thinking:
extra_body["reasoning_effort"] = self._reasoning_effort
kwargs: dict[str, Any] = {
"model": self.model,