|
| 1 | +""" |
| 2 | +Integration tests for MiniMax LLM provider in SQLBot. |
| 3 | +
|
| 4 | +These tests validate that the MiniMax API is reachable and functioning |
| 5 | +correctly via the OpenAI-compatible protocol. |
| 6 | +
|
| 7 | +Requires MINIMAX_API_KEY environment variable to be set. |
| 8 | +""" |
| 9 | + |
| 10 | +import json |
| 11 | +import os |
| 12 | +import unittest |
| 13 | + |
| 14 | +import requests |
| 15 | + |
| 16 | +MINIMAX_API_KEY = os.environ.get("MINIMAX_API_KEY", "") |
| 17 | +MINIMAX_BASE_URL = "https://api.minimax.io/v1" |
| 18 | + |
| 19 | + |
| 20 | +def skip_without_api_key(func): |
| 21 | + """Skip test if MINIMAX_API_KEY is not set.""" |
| 22 | + return unittest.skipUnless(MINIMAX_API_KEY, "MINIMAX_API_KEY not set")(func) |
| 23 | + |
| 24 | + |
| 25 | +class TestMiniMaxAPIConnectivity(unittest.TestCase): |
| 26 | + """Test MiniMax API endpoint reachability.""" |
| 27 | + |
| 28 | + @skip_without_api_key |
| 29 | + def test_api_endpoint_reachable(self): |
| 30 | + """MiniMax API endpoint should be reachable (chat completions).""" |
| 31 | + resp = requests.post( |
| 32 | + f"{MINIMAX_BASE_URL}/chat/completions", |
| 33 | + headers={ |
| 34 | + "Authorization": f"Bearer {MINIMAX_API_KEY}", |
| 35 | + "Content-Type": "application/json", |
| 36 | + }, |
| 37 | + json={ |
| 38 | + "model": "MiniMax-M2.5-highspeed", |
| 39 | + "messages": [{"role": "user", "content": "Hi"}], |
| 40 | + "max_tokens": 1, |
| 41 | + }, |
| 42 | + timeout=15, |
| 43 | + ) |
| 44 | + self.assertEqual(resp.status_code, 200) |
| 45 | + |
| 46 | + @skip_without_api_key |
| 47 | + def test_chat_completions_basic(self): |
| 48 | + """MiniMax chat completions should return a valid response.""" |
| 49 | + resp = requests.post( |
| 50 | + f"{MINIMAX_BASE_URL}/chat/completions", |
| 51 | + headers={ |
| 52 | + "Authorization": f"Bearer {MINIMAX_API_KEY}", |
| 53 | + "Content-Type": "application/json", |
| 54 | + }, |
| 55 | + json={ |
| 56 | + "model": "MiniMax-M2.5-highspeed", |
| 57 | + "messages": [{"role": "user", "content": "Say hello in one word."}], |
| 58 | + "temperature": 0.7, |
| 59 | + "max_tokens": 10, |
| 60 | + }, |
| 61 | + timeout=30, |
| 62 | + ) |
| 63 | + self.assertEqual(resp.status_code, 200) |
| 64 | + data = resp.json() |
| 65 | + self.assertIn("choices", data) |
| 66 | + self.assertGreater(len(data["choices"]), 0) |
| 67 | + content = data["choices"][0]["message"]["content"] |
| 68 | + self.assertTrue(len(content) > 0, "Response content should not be empty") |
| 69 | + |
| 70 | + @skip_without_api_key |
| 71 | + def test_temperature_zero_accepted(self): |
| 72 | + """MiniMax API should accept temperature=0.""" |
| 73 | + resp = requests.post( |
| 74 | + f"{MINIMAX_BASE_URL}/chat/completions", |
| 75 | + headers={ |
| 76 | + "Authorization": f"Bearer {MINIMAX_API_KEY}", |
| 77 | + "Content-Type": "application/json", |
| 78 | + }, |
| 79 | + json={ |
| 80 | + "model": "MiniMax-M2.5-highspeed", |
| 81 | + "messages": [{"role": "user", "content": "Reply with OK."}], |
| 82 | + "temperature": 0, |
| 83 | + "max_tokens": 5, |
| 84 | + }, |
| 85 | + timeout=30, |
| 86 | + ) |
| 87 | + self.assertEqual(resp.status_code, 200) |
| 88 | + |
| 89 | + |
| 90 | +if __name__ == "__main__": |
| 91 | + unittest.main() |
0 commit comments