mito-ai 0.1.58__py3-none-any.whl → 0.1.59__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mito_ai/__init__.py +5 -2
- mito_ai/_version.py +1 -1
- mito_ai/completions/prompt_builders/prompt_constants.py +2 -0
- mito_ai/constants.py +25 -3
- mito_ai/enterprise/litellm_client.py +12 -5
- mito_ai/enterprise/utils.py +16 -2
- mito_ai/openai_client.py +26 -6
- mito_ai/provider_manager.py +34 -2
- mito_ai/tests/message_history/test_generate_short_chat_name.py +35 -4
- mito_ai/tests/open_ai_utils_test.py +34 -36
- mito_ai/tests/providers/test_azure.py +2 -2
- mito_ai/tests/test_constants.py +90 -0
- mito_ai/tests/test_enterprise_mode.py +55 -0
- mito_ai/tests/test_model_utils.py +116 -25
- mito_ai/utils/model_utils.py +130 -51
- mito_ai/utils/open_ai_utils.py +29 -33
- mito_ai/utils/provider_utils.py +13 -7
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/build_log.json +1 -1
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/package.json +2 -2
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/schemas/mito_ai/package.json.orig +1 -1
- mito_ai-0.1.58.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.03302cc521d72eb56b00.js → mito_ai-0.1.59.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.44c109c7be36fb884d25.js +389 -70
- mito_ai-0.1.59.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.44c109c7be36fb884d25.js.map +1 -0
- mito_ai-0.1.58.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.570df809a692f53a7ab7.js → mito_ai-0.1.59.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.f7decebaf69618541e0f.js +3 -3
- mito_ai-0.1.58.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.570df809a692f53a7ab7.js.map → mito_ai-0.1.59.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.f7decebaf69618541e0f.js.map +1 -1
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/themes/mito_ai/index.css +78 -78
- {mito_ai-0.1.58.dist-info → mito_ai-0.1.59.dist-info}/METADATA +1 -1
- {mito_ai-0.1.58.dist-info → mito_ai-0.1.59.dist-info}/RECORD +52 -52
- mito_ai-0.1.58.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.03302cc521d72eb56b00.js.map +0 -1
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/etc/jupyter/jupyter_server_config.d/mito_ai.json +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/schemas/mito_ai/toolbar-buttons.json +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/node_modules_process_browser_js.4b128e94d31a81ebd209.js +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/node_modules_process_browser_js.4b128e94d31a81ebd209.js.map +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/style.js +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/style_index_js.f5d476ac514294615881.js +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/style_index_js.f5d476ac514294615881.js.map +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_auth_dist_esm_providers_cognito_apis_signOut_mjs-node_module-75790d.688c25857e7b81b1740f.js +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_auth_dist_esm_providers_cognito_apis_signOut_mjs-node_module-75790d.688c25857e7b81b1740f.js.map +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_auth_dist_esm_providers_cognito_tokenProvider_tokenProvider_-72f1c8.a917210f057fcfe224ad.js +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_auth_dist_esm_providers_cognito_tokenProvider_tokenProvider_-72f1c8.a917210f057fcfe224ad.js.map +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_dist_esm_index_mjs.6bac1a8c4cc93f15f6b7.js +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_dist_esm_index_mjs.6bac1a8c4cc93f15f6b7.js.map +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_ui-react_dist_esm_index_mjs.4fcecd65bef9e9847609.js +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_ui-react_dist_esm_index_mjs.4fcecd65bef9e9847609.js.map +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_react-dom_client_js-node_modules_aws-amplify_ui-react_dist_styles_css.b43d4249e4d3dac9ad7b.js +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_react-dom_client_js-node_modules_aws-amplify_ui-react_dist_styles_css.b43d4249e4d3dac9ad7b.js.map +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_semver_index_js.3f6754ac5116d47de76b.js +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_semver_index_js.3f6754ac5116d47de76b.js.map +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_vscode-diff_dist_index_js.ea55f1f9346638aafbcf.js +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_vscode-diff_dist_index_js.ea55f1f9346638aafbcf.js.map +0 -0
- {mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/themes/mito_ai/index.js +0 -0
- {mito_ai-0.1.58.dist-info → mito_ai-0.1.59.dist-info}/WHEEL +0 -0
- {mito_ai-0.1.58.dist-info → mito_ai-0.1.59.dist-info}/entry_points.txt +0 -0
- {mito_ai-0.1.58.dist-info → mito_ai-0.1.59.dist-info}/licenses/LICENSE +0 -0
|
@@ -137,6 +137,61 @@ class TestModelValidation:
|
|
|
137
137
|
|
|
138
138
|
from mito_ai.utils.model_utils import STANDARD_MODELS
|
|
139
139
|
assert result == STANDARD_MODELS
|
|
140
|
+
|
|
141
|
+
@patch('mito_ai.utils.model_utils.is_enterprise')
|
|
142
|
+
@patch('mito_ai.utils.model_utils.constants')
|
|
143
|
+
@patch('mito_ai.utils.model_utils.is_abacus_configured')
|
|
144
|
+
def test_provider_manager_validates_abacus_model(self, mock_is_abacus_configured, mock_constants, mock_is_enterprise, provider_config: Config):
|
|
145
|
+
"""Test that ProviderManager validates Abacus models against available models."""
|
|
146
|
+
mock_is_abacus_configured.return_value = True
|
|
147
|
+
mock_is_enterprise.return_value = True
|
|
148
|
+
mock_constants.ABACUS_BASE_URL = "https://routellm.abacus.ai/v1"
|
|
149
|
+
mock_constants.ABACUS_MODELS = ["Abacus/gpt-4.1", "Abacus/gpt-5.2"]
|
|
150
|
+
|
|
151
|
+
provider_manager = ProviderManager(config=provider_config)
|
|
152
|
+
provider_manager.set_selected_model("Abacus/gpt-4.1")
|
|
153
|
+
|
|
154
|
+
# Should not raise an error for valid model
|
|
155
|
+
available_models = get_available_models()
|
|
156
|
+
assert "Abacus/gpt-4.1" in available_models
|
|
157
|
+
|
|
158
|
+
@patch('mito_ai.utils.model_utils.is_enterprise')
|
|
159
|
+
@patch('mito_ai.utils.model_utils.constants')
|
|
160
|
+
@patch('mito_ai.utils.model_utils.is_abacus_configured')
|
|
161
|
+
@pytest.mark.asyncio
|
|
162
|
+
async def test_provider_manager_rejects_invalid_abacus_model(self, mock_is_abacus_configured, mock_constants, mock_is_enterprise, provider_config: Config):
|
|
163
|
+
"""Test that ProviderManager rejects invalid Abacus models."""
|
|
164
|
+
mock_is_abacus_configured.return_value = True
|
|
165
|
+
mock_is_enterprise.return_value = True
|
|
166
|
+
mock_constants.ABACUS_BASE_URL = "https://routellm.abacus.ai/v1"
|
|
167
|
+
mock_constants.ABACUS_MODELS = ["Abacus/gpt-4.1"]
|
|
168
|
+
mock_constants.ABACUS_API_KEY = "test-key"
|
|
169
|
+
|
|
170
|
+
provider_manager = ProviderManager(config=provider_config)
|
|
171
|
+
provider_manager.set_selected_model("invalid-model")
|
|
172
|
+
|
|
173
|
+
messages: list[ChatCompletionMessageParam] = [{"role": "user", "content": "test"}]
|
|
174
|
+
|
|
175
|
+
# Should raise ValueError for invalid model
|
|
176
|
+
with pytest.raises(ValueError, match="is not in the allowed model list"):
|
|
177
|
+
await provider_manager.request_completions(
|
|
178
|
+
message_type=MessageType.CHAT,
|
|
179
|
+
messages=messages
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
@patch('mito_ai.utils.model_utils.is_enterprise')
|
|
183
|
+
@patch('mito_ai.utils.model_utils.constants')
|
|
184
|
+
@patch('mito_ai.utils.model_utils.is_abacus_configured')
|
|
185
|
+
def test_available_models_endpoint_returns_abacus_models(self, mock_is_abacus_configured, mock_constants, mock_is_enterprise):
|
|
186
|
+
"""Test that /available-models endpoint returns Abacus models when configured."""
|
|
187
|
+
mock_is_abacus_configured.return_value = True
|
|
188
|
+
mock_is_enterprise.return_value = True
|
|
189
|
+
mock_constants.ABACUS_BASE_URL = "https://routellm.abacus.ai/v1"
|
|
190
|
+
mock_constants.ABACUS_MODELS = ["Abacus/gpt-4.1", "Abacus/claude-haiku-4-5-20251001"]
|
|
191
|
+
|
|
192
|
+
result = get_available_models()
|
|
193
|
+
|
|
194
|
+
assert result == ["Abacus/gpt-4.1", "Abacus/claude-haiku-4-5-20251001"]
|
|
140
195
|
|
|
141
196
|
|
|
142
197
|
class TestModelStorage:
|
|
@@ -22,11 +22,11 @@ class TestGetAvailableModels:
|
|
|
22
22
|
"""Test that LiteLLM models are returned when enterprise mode is enabled and LiteLLM is configured."""
|
|
23
23
|
mock_is_enterprise.return_value = True
|
|
24
24
|
mock_constants.LITELLM_BASE_URL = "https://litellm-server.com"
|
|
25
|
-
mock_constants.LITELLM_MODELS = ["openai/gpt-4o", "anthropic/claude-3-5-sonnet"]
|
|
25
|
+
mock_constants.LITELLM_MODELS = ["litellm/openai/gpt-4o", "litellm/anthropic/claude-3-5-sonnet"]
|
|
26
26
|
|
|
27
27
|
result = get_available_models()
|
|
28
28
|
|
|
29
|
-
assert result == ["openai/gpt-4o", "anthropic/claude-3-5-sonnet"]
|
|
29
|
+
assert result == ["litellm/openai/gpt-4o", "litellm/anthropic/claude-3-5-sonnet"]
|
|
30
30
|
|
|
31
31
|
@patch('mito_ai.utils.model_utils.is_enterprise')
|
|
32
32
|
@patch('mito_ai.utils.model_utils.constants')
|
|
@@ -56,7 +56,7 @@ class TestGetAvailableModels:
|
|
|
56
56
|
"""Test that standard models are returned when enterprise mode is enabled but LITELLM_BASE_URL is not set."""
|
|
57
57
|
mock_is_enterprise.return_value = True
|
|
58
58
|
mock_constants.LITELLM_BASE_URL = None
|
|
59
|
-
mock_constants.LITELLM_MODELS = ["openai/gpt-4o"]
|
|
59
|
+
mock_constants.LITELLM_MODELS = ["litellm/openai/gpt-4o"]
|
|
60
60
|
|
|
61
61
|
result = get_available_models()
|
|
62
62
|
|
|
@@ -73,6 +73,20 @@ class TestGetAvailableModels:
|
|
|
73
73
|
result = get_available_models()
|
|
74
74
|
|
|
75
75
|
assert result == STANDARD_MODELS
|
|
76
|
+
|
|
77
|
+
@patch('mito_ai.utils.model_utils.is_abacus_configured')
|
|
78
|
+
@patch('mito_ai.utils.model_utils.is_enterprise')
|
|
79
|
+
@patch('mito_ai.utils.model_utils.constants')
|
|
80
|
+
def test_returns_abacus_models_when_configured(self, mock_constants, mock_is_enterprise, mock_is_abacus_configured):
|
|
81
|
+
"""Test that Abacus models are returned when Abacus is configured (highest priority)."""
|
|
82
|
+
mock_is_abacus_configured.return_value = True
|
|
83
|
+
mock_is_enterprise.return_value = True
|
|
84
|
+
mock_constants.ABACUS_BASE_URL = "https://routellm.abacus.ai/v1"
|
|
85
|
+
mock_constants.ABACUS_MODELS = ["Abacus/gpt-4.1", "Abacus/claude-haiku-4-5-20251001"]
|
|
86
|
+
|
|
87
|
+
result = get_available_models()
|
|
88
|
+
|
|
89
|
+
assert result == ["Abacus/gpt-4.1", "Abacus/claude-haiku-4-5-20251001"]
|
|
76
90
|
|
|
77
91
|
|
|
78
92
|
class TestGetFastModelForSelectedModel:
|
|
@@ -114,51 +128,51 @@ class TestGetFastModelForSelectedModel:
|
|
|
114
128
|
[
|
|
115
129
|
# Test case 1: LiteLLM OpenAI model returns fastest overall
|
|
116
130
|
(
|
|
117
|
-
"openai/gpt-5.2",
|
|
118
|
-
["openai/gpt-4.1", "openai/gpt-5.2", "anthropic/claude-sonnet-4-5-20250929"],
|
|
119
|
-
"openai/gpt-4.1",
|
|
131
|
+
"litellm/openai/gpt-5.2",
|
|
132
|
+
["litellm/openai/gpt-4.1", "litellm/openai/gpt-5.2", "litellm/anthropic/claude-sonnet-4-5-20250929"],
|
|
133
|
+
"litellm/openai/gpt-4.1",
|
|
120
134
|
),
|
|
121
135
|
# Test case 2: LiteLLM Anthropic model returns fastest overall
|
|
122
136
|
(
|
|
123
|
-
"anthropic/claude-sonnet-4-5-20250929",
|
|
124
|
-
["openai/gpt-4.1", "anthropic/claude-sonnet-4-5-20250929", "anthropic/claude-haiku-4-5-20251001"],
|
|
125
|
-
"openai/gpt-4.1",
|
|
137
|
+
"litellm/anthropic/claude-sonnet-4-5-20250929",
|
|
138
|
+
["litellm/openai/gpt-4.1", "litellm/anthropic/claude-sonnet-4-5-20250929", "litellm/anthropic/claude-haiku-4-5-20251001"],
|
|
139
|
+
"litellm/openai/gpt-4.1",
|
|
126
140
|
),
|
|
127
141
|
# Test case 3: LiteLLM Google model returns fastest overall
|
|
128
142
|
(
|
|
129
|
-
"google/gemini-3-pro-preview",
|
|
130
|
-
["google/gemini-3-pro-preview", "google/gemini-3-flash-preview"],
|
|
131
|
-
"google/gemini-3-flash-preview",
|
|
143
|
+
"litellm/google/gemini-3-pro-preview",
|
|
144
|
+
["litellm/google/gemini-3-pro-preview", "litellm/google/gemini-3-flash-preview"],
|
|
145
|
+
"litellm/google/gemini-3-flash-preview",
|
|
132
146
|
),
|
|
133
147
|
# Test case 4: Unknown LiteLLM model returns fastest known
|
|
134
148
|
(
|
|
135
149
|
"unknown/provider/model",
|
|
136
|
-
["openai/gpt-4.1", "unknown/provider/model"],
|
|
137
|
-
"openai/gpt-4.1",
|
|
150
|
+
["litellm/openai/gpt-4.1", "unknown/provider/model"],
|
|
151
|
+
"litellm/openai/gpt-4.1",
|
|
138
152
|
),
|
|
139
153
|
# Test case 5: Single LiteLLM model returns itself
|
|
140
154
|
(
|
|
141
|
-
"openai/gpt-4o",
|
|
142
|
-
["openai/gpt-4o"],
|
|
143
|
-
"openai/gpt-4o",
|
|
155
|
+
"litellm/openai/gpt-4o",
|
|
156
|
+
["litellm/openai/gpt-4o"],
|
|
157
|
+
"litellm/openai/gpt-4o",
|
|
144
158
|
),
|
|
145
159
|
# Test case 6: Cross-provider comparison - OpenAI is faster
|
|
146
160
|
(
|
|
147
|
-
"anthropic/claude-sonnet-4-5-20250929",
|
|
161
|
+
"litellm/anthropic/claude-sonnet-4-5-20250929",
|
|
148
162
|
[
|
|
149
|
-
"openai/gpt-4.1", # Index 0 in OPENAI_MODEL_ORDER
|
|
150
|
-
"anthropic/claude-sonnet-4-5-20250929", # Index 1 in ANTHROPIC_MODEL_ORDER
|
|
163
|
+
"litellm/openai/gpt-4.1", # Index 0 in OPENAI_MODEL_ORDER
|
|
164
|
+
"litellm/anthropic/claude-sonnet-4-5-20250929", # Index 1 in ANTHROPIC_MODEL_ORDER
|
|
151
165
|
],
|
|
152
|
-
"openai/gpt-4.1",
|
|
166
|
+
"litellm/openai/gpt-4.1",
|
|
153
167
|
),
|
|
154
168
|
# Test case 7: Cross-provider comparison - Anthropic is faster
|
|
155
169
|
(
|
|
156
|
-
"openai/gpt-5.2",
|
|
170
|
+
"litellm/openai/gpt-5.2",
|
|
157
171
|
[
|
|
158
|
-
"openai/gpt-5.2", # Index 1 in OPENAI_MODEL_ORDER
|
|
159
|
-
"anthropic/claude-haiku-4-5-20251001", # Index 0 in ANTHROPIC_MODEL_ORDER
|
|
172
|
+
"litellm/openai/gpt-5.2", # Index 1 in OPENAI_MODEL_ORDER
|
|
173
|
+
"litellm/anthropic/claude-haiku-4-5-20251001", # Index 0 in ANTHROPIC_MODEL_ORDER
|
|
160
174
|
],
|
|
161
|
-
"anthropic/claude-haiku-4-5-20251001",
|
|
175
|
+
"litellm/anthropic/claude-haiku-4-5-20251001",
|
|
162
176
|
),
|
|
163
177
|
],
|
|
164
178
|
ids=[
|
|
@@ -269,3 +283,80 @@ class TestGetFastModelForSelectedModel:
|
|
|
269
283
|
for model, expected in test_cases:
|
|
270
284
|
result = get_fast_model_for_selected_model(model)
|
|
271
285
|
assert result == expected, f"Case-insensitive matching failed for {model}"
|
|
286
|
+
|
|
287
|
+
@patch('mito_ai.utils.model_utils.get_available_models')
|
|
288
|
+
@pytest.mark.parametrize(
|
|
289
|
+
"selected_model,available_models,expected_result",
|
|
290
|
+
[
|
|
291
|
+
# Test case 1: Abacus GPT model returns fastest overall
|
|
292
|
+
(
|
|
293
|
+
"Abacus/gpt-5.2",
|
|
294
|
+
["Abacus/gpt-4.1", "Abacus/gpt-5.2", "Abacus/claude-sonnet-4-5-20250929"],
|
|
295
|
+
"Abacus/gpt-4.1",
|
|
296
|
+
),
|
|
297
|
+
# Test case 2: Abacus Claude model returns fastest overall
|
|
298
|
+
(
|
|
299
|
+
"Abacus/claude-sonnet-4-5-20250929",
|
|
300
|
+
["Abacus/gpt-4.1", "Abacus/claude-sonnet-4-5-20250929", "Abacus/claude-haiku-4-5-20251001"],
|
|
301
|
+
"Abacus/gpt-4.1",
|
|
302
|
+
),
|
|
303
|
+
# Test case 3: Abacus Gemini model returns fastest overall
|
|
304
|
+
(
|
|
305
|
+
"Abacus/gemini-3-pro-preview",
|
|
306
|
+
["Abacus/gemini-3-pro-preview", "Abacus/gemini-3-flash-preview"],
|
|
307
|
+
"Abacus/gemini-3-flash-preview",
|
|
308
|
+
),
|
|
309
|
+
# Test case 4: Unknown Abacus model returns fastest known
|
|
310
|
+
(
|
|
311
|
+
"Abacus/unknown-model",
|
|
312
|
+
["Abacus/gpt-4.1", "Abacus/unknown-model"],
|
|
313
|
+
"Abacus/gpt-4.1",
|
|
314
|
+
),
|
|
315
|
+
# Test case 5: Single Abacus model returns itself
|
|
316
|
+
(
|
|
317
|
+
"Abacus/gpt-4.1",
|
|
318
|
+
["Abacus/gpt-4.1"],
|
|
319
|
+
"Abacus/gpt-4.1",
|
|
320
|
+
),
|
|
321
|
+
# Test case 6: Cross-provider comparison - OpenAI is faster
|
|
322
|
+
(
|
|
323
|
+
"Abacus/claude-sonnet-4-5-20250929",
|
|
324
|
+
[
|
|
325
|
+
"Abacus/gpt-4.1", # Index 0 in OPENAI_MODEL_ORDER
|
|
326
|
+
"Abacus/claude-sonnet-4-5-20250929", # Index 1 in ANTHROPIC_MODEL_ORDER
|
|
327
|
+
],
|
|
328
|
+
"Abacus/gpt-4.1",
|
|
329
|
+
),
|
|
330
|
+
# Test case 7: Cross-provider comparison - Anthropic is faster
|
|
331
|
+
(
|
|
332
|
+
"Abacus/gpt-5.2",
|
|
333
|
+
[
|
|
334
|
+
"Abacus/gpt-5.2", # Index 1 in OPENAI_MODEL_ORDER
|
|
335
|
+
"Abacus/claude-haiku-4-5-20251001", # Index 0 in ANTHROPIC_MODEL_ORDER
|
|
336
|
+
],
|
|
337
|
+
"Abacus/claude-haiku-4-5-20251001",
|
|
338
|
+
),
|
|
339
|
+
],
|
|
340
|
+
ids=[
|
|
341
|
+
"abacus_gpt_model_returns_fastest_overall",
|
|
342
|
+
"abacus_anthropic_model_returns_fastest_overall",
|
|
343
|
+
"abacus_google_model_returns_fastest_overall",
|
|
344
|
+
"abacus_unknown_model_returns_fastest_known",
|
|
345
|
+
"abacus_single_model_returns_itself",
|
|
346
|
+
"abacus_cross_provider_comparison_openai_faster",
|
|
347
|
+
"abacus_returns_fastest_when_anthropic_is_faster",
|
|
348
|
+
]
|
|
349
|
+
)
|
|
350
|
+
def test_abacus_model_returns_fastest(
|
|
351
|
+
self,
|
|
352
|
+
mock_get_available_models,
|
|
353
|
+
selected_model,
|
|
354
|
+
available_models,
|
|
355
|
+
expected_result,
|
|
356
|
+
):
|
|
357
|
+
"""Test that Abacus models return fastest model from all available models."""
|
|
358
|
+
mock_get_available_models.return_value = available_models
|
|
359
|
+
|
|
360
|
+
result = get_fast_model_for_selected_model(selected_model)
|
|
361
|
+
|
|
362
|
+
assert result == expected_result
|
mito_ai/utils/model_utils.py
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
from typing import List, Tuple, Union, Optional, cast
|
|
5
5
|
from mito_ai import constants
|
|
6
6
|
from mito_ai.utils.version_utils import is_enterprise
|
|
7
|
+
from mito_ai.enterprise.utils import is_abacus_configured
|
|
7
8
|
|
|
8
9
|
# Model ordering: [fastest, ..., slowest] for each provider
|
|
9
10
|
ANTHROPIC_MODEL_ORDER = [
|
|
@@ -35,15 +36,23 @@ STANDARD_MODELS = [
|
|
|
35
36
|
|
|
36
37
|
def get_available_models() -> List[str]:
|
|
37
38
|
"""
|
|
38
|
-
Determine which models are available based on enterprise mode and
|
|
39
|
+
Determine which models are available based on enterprise mode and router configuration.
|
|
40
|
+
|
|
41
|
+
Priority order:
|
|
42
|
+
1. Abacus (if configured)
|
|
43
|
+
2. LiteLLM (if configured)
|
|
44
|
+
3. Standard models
|
|
39
45
|
|
|
40
46
|
Returns:
|
|
41
|
-
List of available model names
|
|
42
|
-
returns LiteLLM models. Otherwise, returns standard models.
|
|
47
|
+
List of available model names with appropriate prefixes.
|
|
43
48
|
"""
|
|
49
|
+
# Check if enterprise mode is enabled AND Abacus is configured (highest priority)
|
|
50
|
+
if is_abacus_configured():
|
|
51
|
+
# Return Abacus models (with Abacus/ prefix)
|
|
52
|
+
return constants.ABACUS_MODELS
|
|
44
53
|
# Check if enterprise mode is enabled AND LiteLLM is configured
|
|
45
|
-
|
|
46
|
-
# Return LiteLLM models (with provider
|
|
54
|
+
elif is_enterprise() and constants.LITELLM_BASE_URL and constants.LITELLM_MODELS:
|
|
55
|
+
# Return LiteLLM models (with LiteLLM/provider/ prefix or legacy provider/ prefix)
|
|
47
56
|
return constants.LITELLM_MODELS
|
|
48
57
|
else:
|
|
49
58
|
# Return standard models
|
|
@@ -55,39 +64,50 @@ def get_fast_model_for_selected_model(selected_model: str) -> str:
|
|
|
55
64
|
Get the fastest model for the client of the selected model.
|
|
56
65
|
|
|
57
66
|
- For standard providers, returns the first (fastest) model from that provider's order.
|
|
58
|
-
- For
|
|
67
|
+
- For enterprise router models (Abacus/LiteLLM), finds the fastest available model by comparing indices.
|
|
59
68
|
"""
|
|
60
|
-
# Check if this is
|
|
61
|
-
if "/" in selected_model:
|
|
62
|
-
|
|
63
|
-
# Find the fastest model from available LiteLLM models
|
|
69
|
+
# Check if this is an enterprise router model (has "/" or router prefix)
|
|
70
|
+
if "/" in selected_model or selected_model.lower().startswith(('abacus/', 'litellm/')):
|
|
71
|
+
# Find the fastest model from available models
|
|
64
72
|
available_models = get_available_models()
|
|
65
73
|
if not available_models:
|
|
66
74
|
return selected_model
|
|
67
75
|
|
|
68
|
-
# Filter to only
|
|
69
|
-
|
|
70
|
-
if not
|
|
76
|
+
# Filter to only router models (those with "/")
|
|
77
|
+
router_models = [model for model in available_models if "/" in model]
|
|
78
|
+
if not router_models:
|
|
71
79
|
return selected_model
|
|
72
80
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
# Extract provider/model pairs for ordering
|
|
82
|
+
pairs_with_indices = []
|
|
83
|
+
for model in router_models:
|
|
84
|
+
# Strip router prefix to get underlying model info
|
|
85
|
+
model_without_router = strip_router_prefix(model)
|
|
86
|
+
|
|
87
|
+
# For Abacus: model_without_router is just the model name (e.g., "gpt-4.1")
|
|
88
|
+
# For LiteLLM: model_without_router is "provider/model" (e.g., "openai/gpt-4.1")
|
|
89
|
+
if "/" in model_without_router:
|
|
90
|
+
# LiteLLM format: provider/model
|
|
91
|
+
pair = model_without_router.split("/", 1)
|
|
92
|
+
else:
|
|
93
|
+
# Abacus format: just model name, need to determine provider
|
|
94
|
+
provider = get_underlying_model_provider(model)
|
|
95
|
+
if provider:
|
|
96
|
+
pair = [provider, model_without_router]
|
|
97
|
+
else:
|
|
98
|
+
continue
|
|
99
|
+
|
|
100
|
+
index = get_model_order_index(pair)
|
|
101
|
+
if index is not None:
|
|
102
|
+
pairs_with_indices.append((model, index))
|
|
78
103
|
|
|
79
|
-
if not
|
|
104
|
+
if not pairs_with_indices:
|
|
80
105
|
return selected_model
|
|
81
106
|
|
|
82
|
-
# Find the
|
|
83
|
-
|
|
84
|
-
fastest_model = f"{fastest_pair[0]}/{fastest_pair[1]}"
|
|
107
|
+
# Find the model with the minimum index (fastest model)
|
|
108
|
+
fastest_model, _ = min(pairs_with_indices, key=lambda x: x[1])
|
|
85
109
|
|
|
86
|
-
|
|
87
|
-
if fastest_model:
|
|
88
|
-
return fastest_model
|
|
89
|
-
else:
|
|
90
|
-
return selected_model
|
|
110
|
+
return fastest_model
|
|
91
111
|
|
|
92
112
|
# Standard provider logic - ensure we return a model from the same provider
|
|
93
113
|
model_lower = selected_model.lower()
|
|
@@ -107,42 +127,57 @@ def get_smartest_model_for_selected_model(selected_model: str) -> str:
|
|
|
107
127
|
Get the smartest model for the client of the selected model.
|
|
108
128
|
|
|
109
129
|
- For standard providers, returns the last (smartest) model from that provider's order.
|
|
110
|
-
- For
|
|
130
|
+
- For enterprise router models (Abacus/LiteLLM), finds the smartest available model by comparing indices.
|
|
111
131
|
"""
|
|
112
|
-
# Check if this is
|
|
113
|
-
if "/" in selected_model:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
132
|
+
# Check if this is an enterprise router model (has "/" or router prefix)
|
|
133
|
+
if "/" in selected_model or selected_model.lower().startswith(('abacus/', 'litellm/')):
|
|
134
|
+
# Extract underlying provider from selected model
|
|
135
|
+
selected_provider = get_underlying_model_provider(selected_model)
|
|
136
|
+
if not selected_provider:
|
|
137
|
+
return selected_model
|
|
117
138
|
|
|
118
|
-
# Find the smartest model from available
|
|
139
|
+
# Find the smartest model from available models
|
|
119
140
|
available_models = get_available_models()
|
|
120
141
|
if not available_models:
|
|
121
142
|
return selected_model
|
|
122
143
|
|
|
123
|
-
# Filter to only
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
144
|
+
# Filter to only router models with the same underlying provider
|
|
145
|
+
router_models = []
|
|
146
|
+
for model in available_models:
|
|
147
|
+
if "/" in model:
|
|
148
|
+
model_provider = get_underlying_model_provider(model)
|
|
149
|
+
if model_provider == selected_provider:
|
|
150
|
+
router_models.append(model)
|
|
127
151
|
|
|
128
|
-
|
|
152
|
+
if not router_models:
|
|
153
|
+
return selected_model
|
|
129
154
|
|
|
130
|
-
#
|
|
131
|
-
pairs_with_indices = [
|
|
132
|
-
|
|
155
|
+
# Extract provider/model pairs for ordering
|
|
156
|
+
pairs_with_indices = []
|
|
157
|
+
for model in router_models:
|
|
158
|
+
# Strip router prefix to get underlying model info
|
|
159
|
+
model_without_router = strip_router_prefix(model)
|
|
160
|
+
|
|
161
|
+
# For Abacus: model_without_router is just the model name (e.g., "gpt-4.1")
|
|
162
|
+
# For LiteLLM: model_without_router is "provider/model" (e.g., "openai/gpt-4.1")
|
|
163
|
+
if "/" in model_without_router:
|
|
164
|
+
# LiteLLM format: provider/model
|
|
165
|
+
pair = model_without_router.split("/", 1)
|
|
166
|
+
else:
|
|
167
|
+
# Abacus format: just model name, provider already determined
|
|
168
|
+
pair = [selected_provider, model_without_router]
|
|
169
|
+
|
|
170
|
+
index = get_model_order_index(pair)
|
|
171
|
+
if index is not None:
|
|
172
|
+
pairs_with_indices.append((model, index))
|
|
133
173
|
|
|
134
|
-
if not
|
|
174
|
+
if not pairs_with_indices:
|
|
135
175
|
return selected_model
|
|
136
176
|
|
|
137
|
-
# Find the
|
|
138
|
-
|
|
139
|
-
smartest_model = f"{smartest_pair[0]}/{smartest_pair[1]}"
|
|
177
|
+
# Find the model with the maximum index (smartest model)
|
|
178
|
+
smartest_model, _ = max(pairs_with_indices, key=lambda x: x[1])
|
|
140
179
|
|
|
141
|
-
|
|
142
|
-
if smartest_model:
|
|
143
|
-
return smartest_model
|
|
144
|
-
else:
|
|
145
|
-
return selected_model
|
|
180
|
+
return smartest_model
|
|
146
181
|
|
|
147
182
|
# Standard provider logic
|
|
148
183
|
model_lower = selected_model.lower()
|
|
@@ -157,6 +192,50 @@ def get_smartest_model_for_selected_model(selected_model: str) -> str:
|
|
|
157
192
|
|
|
158
193
|
return selected_model
|
|
159
194
|
|
|
195
|
+
def strip_router_prefix(model: str) -> str:
|
|
196
|
+
"""
|
|
197
|
+
Strip router prefix from model name.
|
|
198
|
+
|
|
199
|
+
Examples:
|
|
200
|
+
- "Abacus/gpt-4.1" -> "gpt-4.1"
|
|
201
|
+
- "LiteLLM/openai/gpt-4.1" -> "openai/gpt-4.1"
|
|
202
|
+
- "gpt-4.1" -> "gpt-4.1" (no prefix, return as-is)
|
|
203
|
+
"""
|
|
204
|
+
if model.lower().startswith('abacus/'):
|
|
205
|
+
return model[7:] # Strip "Abacus/"
|
|
206
|
+
elif model.lower().startswith('litellm/'):
|
|
207
|
+
return model[8:] # Strip "LiteLLM/"
|
|
208
|
+
return model
|
|
209
|
+
|
|
210
|
+
def get_underlying_model_provider(full_model_provider_id: str) -> Optional[str]:
|
|
211
|
+
"""
|
|
212
|
+
Determine the underlying AI provider from a model identifier.
|
|
213
|
+
|
|
214
|
+
For Abacus models (Abacus/model), determine the provider from model name pattern.
|
|
215
|
+
For LiteLLM models (LiteLLM/provider/model), extract the provider from the prefix.
|
|
216
|
+
|
|
217
|
+
Returns:
|
|
218
|
+
Provider name ("openai", "anthropic", "google") or None if cannot determine.
|
|
219
|
+
"""
|
|
220
|
+
# Strip router prefix first
|
|
221
|
+
model_without_router = strip_router_prefix(full_model_provider_id)
|
|
222
|
+
|
|
223
|
+
# Check if it's a LiteLLM format (provider/model)
|
|
224
|
+
if "/" in model_without_router:
|
|
225
|
+
provider, _ = model_without_router.split("/", 1)
|
|
226
|
+
return provider.lower()
|
|
227
|
+
|
|
228
|
+
# For Abacus models without provider prefix, determine from model name
|
|
229
|
+
model_lower = model_without_router.lower()
|
|
230
|
+
if model_lower.startswith('gpt'):
|
|
231
|
+
return 'openai'
|
|
232
|
+
elif model_lower.startswith('claude'):
|
|
233
|
+
return 'anthropic'
|
|
234
|
+
elif model_lower.startswith('gemini'):
|
|
235
|
+
return 'google'
|
|
236
|
+
|
|
237
|
+
return None
|
|
238
|
+
|
|
160
239
|
def get_model_order_index(pair: List[str]) -> Optional[int]:
|
|
161
240
|
provider, model_name = pair
|
|
162
241
|
if provider == "openai":
|
mito_ai/utils/open_ai_utils.py
CHANGED
|
@@ -6,30 +6,18 @@
|
|
|
6
6
|
|
|
7
7
|
# Copyright (c) Saga Inc.
|
|
8
8
|
|
|
9
|
-
import
|
|
10
|
-
import json
|
|
11
|
-
import time
|
|
12
|
-
from typing import Any, Dict, List, Optional, Final, Union, AsyncGenerator, Tuple, Callable
|
|
9
|
+
from typing import Any, Dict, List, Optional, Union, AsyncGenerator, Tuple, Callable
|
|
13
10
|
from mito_ai.utils.mito_server_utils import get_response_from_mito_server, stream_response_from_mito_server
|
|
14
|
-
from tornado.httpclient import AsyncHTTPClient
|
|
15
11
|
from openai.types.chat import ChatCompletionMessageParam
|
|
16
|
-
|
|
17
|
-
from mito_ai.utils.utils import is_running_test
|
|
18
|
-
from mito_ai.completions.models import MessageType, ResponseFormatInfo, CompletionReply, CompletionStreamChunk, CompletionItem
|
|
12
|
+
from mito_ai.completions.models import MessageType, ResponseFormatInfo, CompletionReply, CompletionStreamChunk
|
|
19
13
|
from mito_ai.utils.schema import UJ_STATIC_USER_ID, UJ_USER_EMAIL
|
|
20
14
|
from mito_ai.utils.db import get_user_field
|
|
21
|
-
from mito_ai.utils
|
|
22
|
-
from mito_ai.utils.server_limits import check_mito_server_quota
|
|
23
|
-
from mito_ai.utils.telemetry_utils import log_ai_completion_success
|
|
24
|
-
from .utils import _create_http_client
|
|
15
|
+
from mito_ai.enterprise.utils import is_abacus_configured
|
|
25
16
|
from mito_ai.constants import MITO_OPENAI_URL
|
|
26
17
|
|
|
27
|
-
|
|
28
18
|
__user_email: Optional[str] = None
|
|
29
19
|
__user_id: Optional[str] = None
|
|
30
20
|
|
|
31
|
-
FAST_OPENAI_MODEL = "gpt-4.1-nano"
|
|
32
|
-
|
|
33
21
|
def _prepare_request_data_and_headers(
|
|
34
22
|
last_message_content: Union[str, None],
|
|
35
23
|
ai_completion_data: Dict[str, Any],
|
|
@@ -171,25 +159,33 @@ def get_open_ai_completion_function_params(
|
|
|
171
159
|
# Pydantic models are supported by the OpenAI API, however, we need to be able to
|
|
172
160
|
# serialize it for requests that are going to be sent to the mito server.
|
|
173
161
|
# OpenAI expects a very specific schema as seen below.
|
|
162
|
+
# Note: Abacus only supports {"type": "json"} format, not the full JSON schema format.
|
|
174
163
|
if response_format_info:
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
"json_schema
|
|
189
|
-
"
|
|
190
|
-
|
|
191
|
-
|
|
164
|
+
# Check if we're using Abacus - it only supports simple {"type": "json"} format
|
|
165
|
+
if is_abacus_configured() or model.lower().startswith('abacus/'):
|
|
166
|
+
completion_function_params["response_format"] = {
|
|
167
|
+
"type": "json"
|
|
168
|
+
}
|
|
169
|
+
else:
|
|
170
|
+
# For OpenAI and other providers, use the full JSON schema format
|
|
171
|
+
json_schema = response_format_info.format.schema()
|
|
172
|
+
|
|
173
|
+
# Add additionalProperties: False to the top-level schema
|
|
174
|
+
json_schema["additionalProperties"] = False
|
|
175
|
+
|
|
176
|
+
# Nested object definitions in $defs need to have additionalProperties set to False also
|
|
177
|
+
if "$defs" in json_schema:
|
|
178
|
+
for def_name, def_schema in json_schema["$defs"].items():
|
|
179
|
+
if def_schema.get("type") == "object":
|
|
180
|
+
def_schema["additionalProperties"] = False
|
|
181
|
+
|
|
182
|
+
completion_function_params["response_format"] = {
|
|
183
|
+
"type": "json_schema",
|
|
184
|
+
"json_schema": {
|
|
185
|
+
"name": f"{response_format_info.name}",
|
|
186
|
+
"schema": json_schema,
|
|
187
|
+
"strict": True
|
|
188
|
+
}
|
|
192
189
|
}
|
|
193
|
-
}
|
|
194
190
|
|
|
195
191
|
return completion_function_params
|
mito_ai/utils/provider_utils.py
CHANGED
|
@@ -8,19 +8,25 @@ from mito_ai.completions.models import MessageType
|
|
|
8
8
|
|
|
9
9
|
def get_model_provider(model: str) -> Union[str, None]:
|
|
10
10
|
"""
|
|
11
|
-
Determine the model type based on the model name prefix
|
|
11
|
+
Determine the model type based on the model name prefix.
|
|
12
|
+
|
|
13
|
+
Priority order:
|
|
14
|
+
1. Check for router prefixes (Abacus/, LiteLLM/)
|
|
15
|
+
2. Check for legacy LiteLLM format (provider/model)
|
|
16
|
+
3. Check for standard model name patterns
|
|
12
17
|
"""
|
|
13
18
|
if not model:
|
|
14
19
|
return None
|
|
15
20
|
|
|
16
|
-
# Check if model is a LiteLLM model (has provider prefix)
|
|
17
|
-
if "/" in model and any(
|
|
18
|
-
model.startswith(prefix) for prefix in ["openai/", "anthropic/", "google/", "ollama/"]
|
|
19
|
-
):
|
|
20
|
-
return 'litellm'
|
|
21
|
-
|
|
22
21
|
model_lower = model.lower()
|
|
23
22
|
|
|
23
|
+
# Check for router prefixes first (highest priority)
|
|
24
|
+
if model_lower.startswith('abacus/'):
|
|
25
|
+
return 'abacus'
|
|
26
|
+
elif model_lower.startswith('litellm/'):
|
|
27
|
+
return 'litellm'
|
|
28
|
+
|
|
29
|
+
# Check for standard model name patterns
|
|
24
30
|
if model_lower.startswith('claude'):
|
|
25
31
|
return 'claude'
|
|
26
32
|
elif model_lower.startswith('gemini'):
|
{mito_ai-0.1.58.data → mito_ai-0.1.59.data}/data/share/jupyter/labextensions/mito_ai/package.json
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mito_ai",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.59",
|
|
4
4
|
"description": "AI chat for JupyterLab",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jupyter",
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
"schemaDir": "schema",
|
|
142
142
|
"themePath": "style/theme/theme.css",
|
|
143
143
|
"_build": {
|
|
144
|
-
"load": "static/remoteEntry.
|
|
144
|
+
"load": "static/remoteEntry.f7decebaf69618541e0f.js",
|
|
145
145
|
"extension": "./extension",
|
|
146
146
|
"style": "./style"
|
|
147
147
|
}
|