|
| 1 | +"""Tests for MiniMax provider upgrade to OpenAI-compatible API (M2.5 support). |
| 2 | +
|
| 3 | +These tests verify the MiniMax provider changes: |
| 4 | +1. Backend: MiniMax uses ChatOpenAICompatible (OpenAI-compatible) instead of legacy MiniMaxChat |
| 5 | +2. Frontend: Model data includes M2.5 models, default API URL updated |
| 6 | +""" |
| 7 | +import ast |
| 8 | +import json |
| 9 | +import os |
| 10 | +import unittest |
| 11 | + |
| 12 | +# Paths relative to this test file |
| 13 | +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 14 | +LLM_PY = os.path.join(BASE_DIR, '..', 'bisheng', 'llm', 'domain', 'llm', 'llm.py') |
| 15 | +AI_INIT = os.path.join(BASE_DIR, '..', 'bisheng', 'core', 'ai', '__init__.py') |
| 16 | +DATA_JSON = os.path.join(BASE_DIR, '..', '..', 'frontend', 'platform', 'public', 'models', 'data.json') |
| 17 | +CUSTOM_FORM_TSX = os.path.join(BASE_DIR, '..', '..', 'frontend', 'platform', 'src', 'pages', |
| 18 | + 'ModelPage', 'manage', 'CustomForm.tsx') |
| 19 | +EMBEDDING_PY = os.path.join(BASE_DIR, '..', 'bisheng', 'llm', 'domain', 'llm', 'embedding.py') |
| 20 | +CONST_PY = os.path.join(BASE_DIR, '..', 'bisheng', 'llm', 'domain', 'const.py') |
| 21 | +ADVANCED_PARAMS_TS = os.path.join(BASE_DIR, '..', '..', 'frontend', 'platform', 'src', 'util', |
| 22 | + 'advancedParamsTemplates.ts') |
| 23 | + |
| 24 | + |
| 25 | +class TestMiniMaxBackendConfig(unittest.TestCase): |
| 26 | + """Unit tests for MiniMax backend provider configuration via source analysis.""" |
| 27 | + |
| 28 | + def setUp(self): |
| 29 | + with open(os.path.normpath(LLM_PY)) as f: |
| 30 | + self.llm_source = f.read() |
| 31 | + |
| 32 | + def test_minimax_uses_chat_openai_compatible(self): |
| 33 | + """MiniMax factory entry should use ChatOpenAICompatible client.""" |
| 34 | + self.assertIn( |
| 35 | + "LLMServerType.MINIMAX.value: {'client': ChatOpenAICompatible", |
| 36 | + self.llm_source |
| 37 | + ) |
| 38 | + |
| 39 | + def test_minimax_uses_openai_params_handler(self): |
| 40 | + """MiniMax factory entry should use _get_openai_params handler.""" |
| 41 | + self.assertIn( |
| 42 | + "'params_handler': _get_openai_params}", |
| 43 | + self.llm_source.split('MINIMAX')[1].split('\n')[0] |
| 44 | + ) |
| 45 | + |
| 46 | + def test_no_legacy_minimax_params_handler(self): |
| 47 | + """Legacy _get_minimax_params function should be removed.""" |
| 48 | + self.assertNotIn('def _get_minimax_params', self.llm_source) |
| 49 | + |
| 50 | + def test_no_minimax_chat_import(self): |
| 51 | + """MiniMaxChat should not be imported in llm.py.""" |
| 52 | + self.assertNotIn('MiniMaxChat', self.llm_source) |
| 53 | + |
| 54 | + def test_chat_openai_compatible_imported(self): |
| 55 | + """ChatOpenAICompatible should be imported in llm.py.""" |
| 56 | + self.assertIn('ChatOpenAICompatible', self.llm_source) |
| 57 | + |
| 58 | + def test_minimax_server_type_defined(self): |
| 59 | + """MiniMax should be defined as a valid server type in const.py.""" |
| 60 | + with open(os.path.normpath(CONST_PY)) as f: |
| 61 | + const_source = f.read() |
| 62 | + self.assertIn("MINIMAX = 'minimax'", const_source) |
| 63 | + |
| 64 | + def test_web_search_support_preserved(self): |
| 65 | + """parse_kwargs should still handle web_search for MINIMAX.""" |
| 66 | + self.assertIn('LLMServerType.MINIMAX.value', self.llm_source) |
| 67 | + self.assertIn("'type': 'web_search'", self.llm_source) |
| 68 | + |
| 69 | + def test_minimax_chat_removed_from_core_ai(self): |
| 70 | + """Legacy MiniMaxChat should be removed from core.ai (no longer needed).""" |
| 71 | + with open(os.path.normpath(AI_INIT)) as f: |
| 72 | + ai_init_source = f.read() |
| 73 | + self.assertNotIn('MiniMaxChat', ai_init_source) |
| 74 | + |
| 75 | + def test_minimax_embedding_uses_openai(self): |
| 76 | + """MiniMax embedding should use OpenAIEmbeddings with _get_openai_params.""" |
| 77 | + with open(os.path.normpath(EMBEDDING_PY)) as f: |
| 78 | + embedding_source = f.read() |
| 79 | + self.assertIn('LLMServerType.MINIMAX.value', embedding_source) |
| 80 | + self.assertIn('OpenAIEmbeddings', embedding_source) |
| 81 | + |
| 82 | + |
| 83 | +class TestMiniMaxModelData(unittest.TestCase): |
| 84 | + """Unit tests for MiniMax model template data.""" |
| 85 | + |
| 86 | + def setUp(self): |
| 87 | + with open(os.path.normpath(DATA_JSON)) as f: |
| 88 | + self.model_data = json.load(f) |
| 89 | + |
| 90 | + def test_minimax_key_exists(self): |
| 91 | + """MiniMax provider should be present in data.json.""" |
| 92 | + self.assertIn('minimax', self.model_data) |
| 93 | + |
| 94 | + def test_minimax_has_m25_model(self): |
| 95 | + """MiniMax-M2.5 should be listed as an LLM model.""" |
| 96 | + model_names = [m['model_name'] for m in self.model_data['minimax']] |
| 97 | + self.assertIn('MiniMax-M2.5', model_names) |
| 98 | + |
| 99 | + def test_minimax_has_m25_highspeed_model(self): |
| 100 | + """MiniMax-M2.5-highspeed should be listed as an LLM model.""" |
| 101 | + model_names = [m['model_name'] for m in self.model_data['minimax']] |
| 102 | + self.assertIn('MiniMax-M2.5-highspeed', model_names) |
| 103 | + |
| 104 | + def test_minimax_has_text01_model(self): |
| 105 | + """MiniMax-Text-01 should still be listed for backward compatibility.""" |
| 106 | + model_names = [m['model_name'] for m in self.model_data['minimax']] |
| 107 | + self.assertIn('MiniMax-Text-01', model_names) |
| 108 | + |
| 109 | + def test_minimax_m25_is_first(self): |
| 110 | + """MiniMax-M2.5 should be the first (default) model.""" |
| 111 | + self.assertEqual(self.model_data['minimax'][0]['model_name'], 'MiniMax-M2.5') |
| 112 | + |
| 113 | + def test_minimax_models_are_llm_type(self): |
| 114 | + """All MiniMax models should be of type 'llm'.""" |
| 115 | + for model in self.model_data['minimax']: |
| 116 | + self.assertEqual(model['model_type'], 'llm') |
| 117 | + |
| 118 | + def test_minimax_model_count(self): |
| 119 | + """MiniMax should have 3 models listed.""" |
| 120 | + self.assertEqual(len(self.model_data['minimax']), 3) |
| 121 | + |
| 122 | + def test_data_json_is_valid_json(self): |
| 123 | + """data.json should be valid JSON with all expected providers.""" |
| 124 | + expected_providers = [ |
| 125 | + 'openai', 'azure_openai', 'qwen', 'deepseek', 'minimax', |
| 126 | + 'volcengine', 'silicon', |
| 127 | + ] |
| 128 | + for provider in expected_providers: |
| 129 | + self.assertIn(provider, self.model_data) |
| 130 | + |
| 131 | + |
| 132 | +class TestMiniMaxFrontendConfig(unittest.TestCase): |
| 133 | + """Unit tests for MiniMax frontend configuration.""" |
| 134 | + |
| 135 | + def setUp(self): |
| 136 | + with open(os.path.normpath(CUSTOM_FORM_TSX)) as f: |
| 137 | + self.form_source = f.read() |
| 138 | + |
| 139 | + def test_minimax_default_api_base_url(self): |
| 140 | + """Default API base URL should be https://api.minimax.io/v1 (new OpenAI-compatible API).""" |
| 141 | + self.assertIn('https://api.minimax.io/v1', self.form_source) |
| 142 | + |
| 143 | + def test_no_legacy_api_url(self): |
| 144 | + """Legacy API URL api.minimax.chat should not be present.""" |
| 145 | + self.assertNotIn('api.minimax.chat', self.form_source) |
| 146 | + |
| 147 | + def test_minimax_requires_api_key(self): |
| 148 | + """MiniMax provider form should require an API key.""" |
| 149 | + # Find minimax section and check for API key field |
| 150 | + minimax_idx = self.form_source.index('minimax:') |
| 151 | + section_end = self.form_source.index('],', minimax_idx) + 2 |
| 152 | + minimax_section = self.form_source[minimax_idx:section_end] |
| 153 | + self.assertIn('openai_api_key', minimax_section) |
| 154 | + |
| 155 | + def test_minimax_requires_api_base(self): |
| 156 | + """MiniMax provider form should require an API base URL.""" |
| 157 | + minimax_idx = self.form_source.index('minimax:') |
| 158 | + section_end = self.form_source.index('],', minimax_idx) + 2 |
| 159 | + minimax_section = self.form_source[minimax_idx:section_end] |
| 160 | + self.assertIn('openai_api_base', minimax_section) |
| 161 | + |
| 162 | + |
| 163 | +class TestMiniMaxAdvancedParams(unittest.TestCase): |
| 164 | + """Unit tests for MiniMax advanced parameters template.""" |
| 165 | + |
| 166 | + def setUp(self): |
| 167 | + with open(os.path.normpath(ADVANCED_PARAMS_TS)) as f: |
| 168 | + self.template_source = f.read() |
| 169 | + |
| 170 | + def test_minimax_llm_template_exists(self): |
| 171 | + """minimax-llm template should exist in advancedParamsTemplates.""" |
| 172 | + self.assertIn("'minimax-llm'", self.template_source) |
| 173 | + |
| 174 | + def test_minimax_mapping_exists(self): |
| 175 | + """minimax should be mapped to minimax-llm template.""" |
| 176 | + self.assertIn("'minimax': 'minimax-llm'", self.template_source) |
| 177 | + |
| 178 | + def test_minimax_embedding_template_exists(self): |
| 179 | + """minimax-embedding template should exist.""" |
| 180 | + self.assertIn("'minimax-embedding'", self.template_source) |
| 181 | + |
| 182 | + |
| 183 | +class TestMiniMaxProviderLinks(unittest.TestCase): |
| 184 | + """Unit tests for MiniMax provider documentation links.""" |
| 185 | + |
| 186 | + def setUp(self): |
| 187 | + use_link_path = os.path.join( |
| 188 | + BASE_DIR, '..', '..', 'frontend', 'platform', 'src', 'pages', |
| 189 | + 'ModelPage', 'manage', 'useLink.ts' |
| 190 | + ) |
| 191 | + with open(os.path.normpath(use_link_path)) as f: |
| 192 | + self.links_source = f.read() |
| 193 | + |
| 194 | + def test_minimax_api_key_url(self): |
| 195 | + """MiniMax should have an API key URL.""" |
| 196 | + minimax_idx = self.links_source.index('minimax:') |
| 197 | + section_end = self.links_source.index('},', minimax_idx) + 2 |
| 198 | + minimax_section = self.links_source[minimax_idx:section_end] |
| 199 | + self.assertIn('apiKeyUrl', minimax_section) |
| 200 | + self.assertIn('platform.minimaxi.com', minimax_section) |
| 201 | + |
| 202 | + def test_minimax_model_url(self): |
| 203 | + """MiniMax should have a model documentation URL.""" |
| 204 | + minimax_idx = self.links_source.index('minimax:') |
| 205 | + section_end = self.links_source.index('},', minimax_idx) + 2 |
| 206 | + minimax_section = self.links_source[minimax_idx:section_end] |
| 207 | + self.assertIn('modelUrl', minimax_section) |
| 208 | + |
| 209 | + |
| 210 | +class TestMiniMaxIntegration(unittest.TestCase): |
| 211 | + """Integration tests for MiniMax provider (require MINIMAX_API_KEY).""" |
| 212 | + |
| 213 | + @unittest.skipUnless( |
| 214 | + os.environ.get('MINIMAX_API_KEY'), |
| 215 | + 'MINIMAX_API_KEY not set' |
| 216 | + ) |
| 217 | + def test_minimax_m25_chat_completion(self): |
| 218 | + """Test actual chat completion with MiniMax-M2.5 via OpenAI-compatible API.""" |
| 219 | + from langchain_openai import ChatOpenAI |
| 220 | + |
| 221 | + llm = ChatOpenAI( |
| 222 | + model='MiniMax-M2.5', |
| 223 | + api_key=os.environ['MINIMAX_API_KEY'], |
| 224 | + base_url='https://api.minimax.io/v1', |
| 225 | + temperature=0.1, |
| 226 | + max_tokens=64, |
| 227 | + ) |
| 228 | + response = llm.invoke('Say hello in one word.') |
| 229 | + self.assertIsNotNone(response.content) |
| 230 | + self.assertTrue(len(response.content) > 0) |
| 231 | + |
| 232 | + @unittest.skipUnless( |
| 233 | + os.environ.get('MINIMAX_API_KEY'), |
| 234 | + 'MINIMAX_API_KEY not set' |
| 235 | + ) |
| 236 | + def test_minimax_m25_highspeed_chat_completion(self): |
| 237 | + """Test actual chat completion with MiniMax-M2.5-highspeed.""" |
| 238 | + from langchain_openai import ChatOpenAI |
| 239 | + |
| 240 | + llm = ChatOpenAI( |
| 241 | + model='MiniMax-M2.5-highspeed', |
| 242 | + api_key=os.environ['MINIMAX_API_KEY'], |
| 243 | + base_url='https://api.minimax.io/v1', |
| 244 | + temperature=0.1, |
| 245 | + max_tokens=64, |
| 246 | + ) |
| 247 | + response = llm.invoke('Say hello in one word.') |
| 248 | + self.assertIsNotNone(response.content) |
| 249 | + self.assertTrue(len(response.content) > 0) |
| 250 | + |
| 251 | + @unittest.skipUnless( |
| 252 | + os.environ.get('MINIMAX_API_KEY'), |
| 253 | + 'MINIMAX_API_KEY not set' |
| 254 | + ) |
| 255 | + def test_minimax_m25_streaming(self): |
| 256 | + """Test streaming chat completion with MiniMax-M2.5.""" |
| 257 | + from langchain_openai import ChatOpenAI |
| 258 | + |
| 259 | + llm = ChatOpenAI( |
| 260 | + model='MiniMax-M2.5', |
| 261 | + api_key=os.environ['MINIMAX_API_KEY'], |
| 262 | + base_url='https://api.minimax.io/v1', |
| 263 | + temperature=0.1, |
| 264 | + max_tokens=64, |
| 265 | + streaming=True, |
| 266 | + ) |
| 267 | + chunks = list(llm.stream('Say hello in one word.')) |
| 268 | + self.assertTrue(len(chunks) > 0) |
| 269 | + full_content = ''.join(c.content for c in chunks) |
| 270 | + self.assertTrue(len(full_content) > 0) |
| 271 | + |
| 272 | + |
| 273 | +if __name__ == '__main__': |
| 274 | + unittest.main() |
0 commit comments