|
16 | 16 | _MAX_STANDARD_HISTORY_LENGTH, |
17 | 17 | _compute_validation_count, |
18 | 18 | _find_model_config, |
| 19 | + _strip_provider_prefix, |
19 | 20 | _trim_history, |
20 | 21 | ) |
21 | 22 | from ldai_optimizer.util import judge_passed |
@@ -129,6 +130,40 @@ def _make_client(ldai: MagicMock | None = None) -> OptimizationClient: |
129 | 130 | # --------------------------------------------------------------------------- |
130 | 131 |
|
131 | 132 |
|
| 133 | +# --------------------------------------------------------------------------- |
| 134 | +# _strip_provider_prefix |
| 135 | +# --------------------------------------------------------------------------- |
| 136 | + |
| 137 | + |
| 138 | +class TestStripProviderPrefix: |
| 139 | + def test_strips_known_anthropic_prefix(self): |
| 140 | + assert _strip_provider_prefix("Anthropic.claude-opus-4-5") == "claude-opus-4-5" |
| 141 | + |
| 142 | + def test_strips_known_openai_prefix(self): |
| 143 | + assert _strip_provider_prefix("OpenAI.gpt-4o") == "gpt-4o" |
| 144 | + |
| 145 | + def test_strips_known_bedrock_prefix(self): |
| 146 | + # "Bedrock.us.amazon.nova-pro-v1:0" → region prefix is preserved |
| 147 | + assert _strip_provider_prefix("Bedrock.us.amazon.nova-pro-v1:0") == "us.amazon.nova-pro-v1:0" |
| 148 | + |
| 149 | + def test_does_not_strip_bedrock_region_prefix(self): |
| 150 | + # Raw Bedrock cross-region ID has no provider prefix — must be unchanged |
| 151 | + assert _strip_provider_prefix("us.amazon.nova-pro-v1:0") == "us.amazon.nova-pro-v1:0" |
| 152 | + |
| 153 | + def test_does_not_strip_eu_region_prefix(self): |
| 154 | + assert _strip_provider_prefix("eu.anthropic.claude-3-5-sonnet-20241022-v2:0") == "eu.anthropic.claude-3-5-sonnet-20241022-v2:0" |
| 155 | + |
| 156 | + def test_no_period_returns_unchanged(self): |
| 157 | + assert _strip_provider_prefix("gpt-4o") == "gpt-4o" |
| 158 | + |
| 159 | + def test_empty_string_returns_unchanged(self): |
| 160 | + assert _strip_provider_prefix("") == "" |
| 161 | + |
| 162 | + def test_preserves_dots_in_model_name_after_stripping(self): |
| 163 | + # Multiple dots after the provider prefix are preserved |
| 164 | + assert _strip_provider_prefix("Anthropic.claude-3.5-sonnet") == "claude-3.5-sonnet" |
| 165 | + |
| 166 | + |
132 | 167 | # --------------------------------------------------------------------------- |
133 | 168 | # _find_model_config |
134 | 169 | # --------------------------------------------------------------------------- |
|
0 commit comments