feat(llm): make tier-C/tier-B model + OpenRouter URL configurable from .env
LLM_MODEL_TIER_C, LLM_MODEL_TIER_B e OPENROUTER_BASE_URL ora override-abili via env. Default invariati (back-compat). LLMClient accetta i tre valori come kwargs opzionali; run_phase1 li propaga da Settings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -75,6 +75,52 @@ def test_completion_retries_on_connection_error(mocker):
|
||||
assert fake_openai.chat.completions.create.call_count == 3
|
||||
|
||||
|
||||
def test_completion_uses_custom_model_tier_c(mocker):
|
||||
fake_openai = mocker.MagicMock()
|
||||
fake_response = mocker.MagicMock()
|
||||
fake_response.choices = [
|
||||
mocker.MagicMock(message=mocker.MagicMock(content="(strategy ...)"))
|
||||
]
|
||||
fake_response.usage = mocker.MagicMock(prompt_tokens=10, completion_tokens=20)
|
||||
fake_openai.chat.completions.create.return_value = fake_response
|
||||
mocker.patch("multi_swarm.llm.client.OpenAI", return_value=fake_openai)
|
||||
|
||||
client = LLMClient(
|
||||
openrouter_api_key="or-x",
|
||||
anthropic_api_key=None,
|
||||
model_tier_c="deepseek/deepseek-chat",
|
||||
)
|
||||
g = make_genome(ModelTier.C)
|
||||
out = client.complete(g, system="sys", user="usr")
|
||||
|
||||
fake_openai.chat.completions.create.assert_called_once()
|
||||
call_kwargs = fake_openai.chat.completions.create.call_args.kwargs
|
||||
assert call_kwargs["model"] == "deepseek/deepseek-chat"
|
||||
assert out.model == "deepseek/deepseek-chat"
|
||||
|
||||
|
||||
def test_completion_uses_custom_model_tier_b(mocker):
|
||||
fake_anthropic = mocker.MagicMock()
|
||||
fake_msg = mocker.MagicMock()
|
||||
fake_msg.content = [mocker.MagicMock(text="(strategy ...)")]
|
||||
fake_msg.usage = mocker.MagicMock(input_tokens=10, output_tokens=20)
|
||||
fake_anthropic.messages.create.return_value = fake_msg
|
||||
mocker.patch("multi_swarm.llm.client.Anthropic", return_value=fake_anthropic)
|
||||
|
||||
client = LLMClient(
|
||||
openrouter_api_key="or-x",
|
||||
anthropic_api_key="an-x",
|
||||
model_tier_b="claude-opus-4-7",
|
||||
)
|
||||
g = make_genome(ModelTier.B)
|
||||
out = client.complete(g, system="sys", user="usr")
|
||||
|
||||
fake_anthropic.messages.create.assert_called_once()
|
||||
call_kwargs = fake_anthropic.messages.create.call_args.kwargs
|
||||
assert call_kwargs["model"] == "claude-opus-4-7"
|
||||
assert out.model == "claude-opus-4-7"
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_completion_succeeds_after_one_retry(mocker):
|
||||
"""Dopo 1 fallimento transient, il retry riesce al 2 tentativo."""
|
||||
|
||||
Reference in New Issue
Block a user