Use fast non-thinking DeepSeek for stove matching

This commit is contained in:
anor
2026-11-26 22:14:19 +10:00
parent dd93361276
commit 95a8b36ecb
3 changed files with 44 additions and 2 deletions
+37
View File
@@ -2,6 +2,7 @@
import asyncio
import os
import sys
import time
from types import SimpleNamespace
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -13,6 +14,15 @@ import stove_pricing
import stove_contract as c
def test_explicit_non_thinking_mode_reaches_anthropic_provider():
body = {"messages": [{"role": "user", "content": "Верни JSON"}],
"max_tokens": 2000, "thinking": {"type": "disabled"}}
payload = stove_match.gateway._to_provider(body, "deepseek-flash", 4096)
assert payload["thinking"] == {"type": "disabled"}
assert "thinking" not in stove_match.gateway._to_provider(
{"messages": body["messages"]}, "glm-5.3", 4096)
def _prices():
return {"region": "Москва", "zone": None, "valid_at": "III кв. 2026",
"lines": [{"name": "Глина шамотная", "qty": 0.5, "unit": "т", "code": None}]}
@@ -105,3 +115,30 @@ def test_match_reuses_price_search_for_site_material(monkeypatch):
priced, key_id=1, budget=300, deadline=__import__('time').monotonic()+10, request_id="rid"))
assert calls.count("Дверка топочная 250×205") == 1
assert result["lines"][2]["code"] == candidate["code"]
def test_match_prefers_deepseek_without_thinking_and_keeps_glm_fallback(monkeypatch):
glm = SimpleNamespace(name="glm", model="glm-5.3", uses_api_token=True)
deepseek = SimpleNamespace(name="deepseek", model="deepseek-flash", uses_api_token=True)
monkeypatch.setattr(stove_match.agent_provider, "provider_chain", lambda user: [glm, deepseek])
monkeypatch.setattr(stove_match.provider_health, "should_include", lambda name: True)
monkeypatch.setattr(stove_match.zaika_quota, "snapshot", lambda: {"known": False})
assert [p.name for p in stove_match._profile_chain()] == ["deepseek", "glm"]
calls = []
monkeypatch.setattr(stove_match, "_reserve", lambda *args: 42)
monkeypatch.setattr(stove_match.db, "settle_llm_usage_stub", lambda *args, **kw: None)
monkeypatch.setattr(stove_match.stove_history, "add_ai_cost", lambda *args, **kw: None)
async def call(profile, body, timeout):
calls.append((profile.name, body.get("thinking")))
if profile.name == "deepseek":
raise stove_match.gateway.ProviderError(503, "temporary")
return '[{"index":0,"code":null}]', {}
monkeypatch.setattr(stove_match, "_call", call)
batch = [{"index": 0, "line": {"name": "Бетон B20", "unit": "м3"},
"candidates": [{"code": "x", "name": "Балки из бетона B20", "unit": "м3"}]}]
picked = asyncio.run(stove_match._ask(batch, 1, 300, time.monotonic()+10, "rid"))
assert picked == [None]
assert calls == [("deepseek", {"type": "disabled"}), ("glm", None)]