-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathminimax_integration_test.go
More file actions
209 lines (179 loc) · 6.43 KB
/
minimax_integration_test.go
File metadata and controls
209 lines (179 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package azure
import (
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
func setupTestRouter() *gin.Engine {
gin.SetMode(gin.TestMode)
r := gin.New()
return r
}
// closeNotifierRecorder wraps httptest.ResponseRecorder to implement http.CloseNotifier,
// which gin's reverse proxy requires.
type closeNotifierRecorder struct {
*httptest.ResponseRecorder
closeCh chan bool
}
func newCloseNotifierRecorder() *closeNotifierRecorder {
return &closeNotifierRecorder{
ResponseRecorder: httptest.NewRecorder(),
closeCh: make(chan bool, 1),
}
}
func (c *closeNotifierRecorder) CloseNotify() <-chan bool {
return c.closeCh
}
// TestIntegrationMiniMaxChatCompletions verifies that a chat/completions request
// for a MiniMax model is proxied to the MiniMax endpoint with correct auth.
func TestIntegrationMiniMaxChatCompletions(t *testing.T) {
// Create a mock MiniMax API server
mockMiniMax := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Verify the request is properly formatted
assert.Equal(t, "/v1/chat/completions", r.URL.Path)
assert.Equal(t, "Bearer test-minimax-key", r.Header.Get("Authorization"))
assert.Empty(t, r.Header.Get("api-key"), "api-key header should not be present for MiniMax")
assert.Empty(t, r.URL.Query().Get("api-version"), "api-version should not be present for MiniMax")
// Return a mock response
resp := map[string]interface{}{
"id": "chatcmpl-mock",
"object": "chat.completion",
"model": "MiniMax-M2.7",
"choices": []map[string]interface{}{{"message": map[string]string{"role": "assistant", "content": "Hello from MiniMax!"}}},
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(resp)
}))
defer mockMiniMax.Close()
// Save original state
originalConfig := make(map[string]DeploymentConfig)
for k, v := range ModelDeploymentConfig {
originalConfig[k] = v
}
defer func() {
ModelDeploymentConfig = originalConfig
}()
// Configure MiniMax deployment pointing to mock server
mockURL, _ := url.Parse(mockMiniMax.URL)
ModelDeploymentConfig = map[string]DeploymentConfig{
"MiniMax-M2.7": {
ModelName: "MiniMax-M2.7",
Endpoint: mockMiniMax.URL,
EndpointUrl: mockURL,
ApiKey: "test-minimax-key",
ProviderType: "minimax",
},
}
// Set up the route
r := setupTestRouter()
stripPrefixConverter := NewStripPrefixConverter("/v1")
r.POST("/v1/chat/completions", ProxyWithConverter(stripPrefixConverter))
// Make the request using closeNotifierRecorder
body := `{"model":"MiniMax-M2.7","messages":[{"role":"user","content":"Hello"}],"temperature":0.7}`
req := httptest.NewRequest(http.MethodPost, "/v1/chat/completions", strings.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer test-minimax-key")
w := newCloseNotifierRecorder()
r.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
var respBody map[string]interface{}
err := json.Unmarshal(w.Body.Bytes(), &respBody)
assert.NoError(t, err)
assert.Equal(t, "MiniMax-M2.7", respBody["model"])
}
// TestIntegrationMiniMaxModelList verifies that /v1/models returns MiniMax models.
func TestIntegrationMiniMaxModelList(t *testing.T) {
// Save original state
originalConfig := make(map[string]DeploymentConfig)
for k, v := range ModelDeploymentConfig {
originalConfig[k] = v
}
defer func() {
ModelDeploymentConfig = originalConfig
}()
// Configure only MiniMax models (no Azure)
endpointURL, _ := url.Parse("https://api.minimax.io/v1")
ModelDeploymentConfig = map[string]DeploymentConfig{
"MiniMax-M2.7": {
ModelName: "MiniMax-M2.7",
Endpoint: "https://api.minimax.io/v1",
EndpointUrl: endpointURL,
ApiKey: "test-key",
ProviderType: "minimax",
},
"MiniMax-M2.5-highspeed": {
ModelName: "MiniMax-M2.5-highspeed",
Endpoint: "https://api.minimax.io/v1",
EndpointUrl: endpointURL,
ApiKey: "test-key",
ProviderType: "minimax",
},
}
r := setupTestRouter()
r.GET("/v1/models", ModelProxy)
req := httptest.NewRequest(http.MethodGet, "/v1/models", nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
var respBody DeploymentInfo
err := json.Unmarshal(w.Body.Bytes(), &respBody)
assert.NoError(t, err)
assert.Equal(t, "list", respBody.Object)
assert.Len(t, respBody.Data, 2)
// Verify MiniMax models are present
modelIDs := make(map[string]bool)
for _, model := range respBody.Data {
modelIDs[model["id"].(string)] = true
assert.Equal(t, "minimax", model["owned_by"])
}
assert.True(t, modelIDs["MiniMax-M2.7"])
assert.True(t, modelIDs["MiniMax-M2.5-highspeed"])
}
// TestIntegrationMiniMaxStreamingProxy verifies that streaming requests to MiniMax work.
func TestIntegrationMiniMaxStreamingProxy(t *testing.T) {
mockMiniMax := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/v1/chat/completions", r.URL.Path)
assert.Equal(t, "Bearer test-key", r.Header.Get("Authorization"))
// Read request body to verify stream=true
bodyBytes, _ := io.ReadAll(r.Body)
assert.Contains(t, string(bodyBytes), `"stream":true`)
w.Header().Set("Content-Type", "text/event-stream")
w.WriteHeader(http.StatusOK)
w.Write([]byte("data: {\"choices\":[{\"delta\":{\"content\":\"Hi\"}}]}\n\n"))
w.Write([]byte("data: [DONE]\n\n"))
}))
defer mockMiniMax.Close()
originalConfig := make(map[string]DeploymentConfig)
for k, v := range ModelDeploymentConfig {
originalConfig[k] = v
}
defer func() {
ModelDeploymentConfig = originalConfig
}()
mockURL, _ := url.Parse(mockMiniMax.URL)
ModelDeploymentConfig = map[string]DeploymentConfig{
"MiniMax-M2.7": {
ModelName: "MiniMax-M2.7",
Endpoint: mockMiniMax.URL,
EndpointUrl: mockURL,
ApiKey: "test-key",
ProviderType: "minimax",
},
}
r := setupTestRouter()
r.POST("/v1/chat/completions", ProxyWithConverter(NewStripPrefixConverter("/v1")))
body := `{"model":"MiniMax-M2.7","messages":[{"role":"user","content":"Hello"}],"stream":true}`
req := httptest.NewRequest(http.MethodPost, "/v1/chat/completions", strings.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer test-key")
w := newCloseNotifierRecorder()
r.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
assert.Contains(t, w.Body.String(), "data:")
}