|
| 1 | +package openai |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/songquanpeng/one-api/relay/channeltype" |
| 7 | + "github.com/songquanpeng/one-api/relay/meta" |
| 8 | +) |
| 9 | + |
| 10 | +func TestGetRequestURL_Minimax(t *testing.T) { |
| 11 | + adaptor := &Adaptor{} |
| 12 | + |
| 13 | + tests := []struct { |
| 14 | + name string |
| 15 | + baseURL string |
| 16 | + requestPath string |
| 17 | + model string |
| 18 | + expected string |
| 19 | + }{ |
| 20 | + { |
| 21 | + name: "M2.7 model with standard base URL", |
| 22 | + baseURL: "https://api.minimax.io/v1", |
| 23 | + requestPath: "/v1/chat/completions", |
| 24 | + model: "MiniMax-M2.7", |
| 25 | + expected: "https://api.minimax.io/v1/v1/chat/completions", |
| 26 | + }, |
| 27 | + { |
| 28 | + name: "M2.7-highspeed with standard base URL", |
| 29 | + baseURL: "https://api.minimax.io", |
| 30 | + requestPath: "/v1/chat/completions", |
| 31 | + model: "MiniMax-M2.7-highspeed", |
| 32 | + expected: "https://api.minimax.io/v1/chat/completions", |
| 33 | + }, |
| 34 | + { |
| 35 | + name: "Legacy abab model with standard base URL", |
| 36 | + baseURL: "https://api.minimax.io", |
| 37 | + requestPath: "/v1/chat/completions", |
| 38 | + model: "abab6.5-chat", |
| 39 | + expected: "https://api.minimax.io/v1/chat/completions", |
| 40 | + }, |
| 41 | + { |
| 42 | + name: "China base URL", |
| 43 | + baseURL: "https://api.minimaxi.com", |
| 44 | + requestPath: "/v1/chat/completions", |
| 45 | + model: "MiniMax-M2.7", |
| 46 | + expected: "https://api.minimaxi.com/v1/chat/completions", |
| 47 | + }, |
| 48 | + } |
| 49 | + |
| 50 | + for _, tt := range tests { |
| 51 | + t.Run(tt.name, func(t *testing.T) { |
| 52 | + m := &meta.Meta{ |
| 53 | + ChannelType: channeltype.Minimax, |
| 54 | + BaseURL: tt.baseURL, |
| 55 | + RequestURLPath: tt.requestPath, |
| 56 | + ActualModelName: tt.model, |
| 57 | + } |
| 58 | + adaptor.Init(m) |
| 59 | + |
| 60 | + url, err := adaptor.GetRequestURL(m) |
| 61 | + if err != nil { |
| 62 | + t.Fatalf("unexpected error: %v", err) |
| 63 | + } |
| 64 | + if url != tt.expected { |
| 65 | + t.Errorf("expected URL %q, got %q", tt.expected, url) |
| 66 | + } |
| 67 | + }) |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +func TestGetRequestURL_MinimaxUsesOpenAICompatFormat(t *testing.T) { |
| 72 | + // Verify MiniMax no longer uses the deprecated /v1/text/chatcompletion_v2 endpoint |
| 73 | + adaptor := &Adaptor{} |
| 74 | + m := &meta.Meta{ |
| 75 | + ChannelType: channeltype.Minimax, |
| 76 | + BaseURL: "https://api.minimax.io", |
| 77 | + RequestURLPath: "/v1/chat/completions", |
| 78 | + ActualModelName: "MiniMax-M2.7", |
| 79 | + } |
| 80 | + adaptor.Init(m) |
| 81 | + |
| 82 | + url, err := adaptor.GetRequestURL(m) |
| 83 | + if err != nil { |
| 84 | + t.Fatalf("unexpected error: %v", err) |
| 85 | + } |
| 86 | + |
| 87 | + // Should NOT contain the deprecated endpoint |
| 88 | + if url == "https://api.minimax.io/v1/text/chatcompletion_v2" { |
| 89 | + t.Error("MiniMax should use OpenAI-compatible /v1/chat/completions, not deprecated /v1/text/chatcompletion_v2") |
| 90 | + } |
| 91 | + |
| 92 | + // Should contain the standard OpenAI path |
| 93 | + expected := "https://api.minimax.io/v1/chat/completions" |
| 94 | + if url != expected { |
| 95 | + t.Errorf("expected %q, got %q", expected, url) |
| 96 | + } |
| 97 | +} |
0 commit comments