Repository navigation
feat(minimax): add MiniMax provider with M3 as default #3165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
581f974
bc6d6a6
9417be7
ead9bbe
92278c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Qwen | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
| import type OpenAI from 'openai'; | ||
| import { MiniMaxOpenAICompatibleProvider } from './minimax.js'; | ||
| import type { ContentGeneratorConfig } from '../../contentGenerator.js'; | ||
| import type { Config } from '../../../config/config.js'; | ||
|
|
||
| // Mock OpenAI client to avoid real network calls | ||
| vi.mock('openai', () => ({ | ||
| default: vi.fn().mockImplementation((config) => ({ | ||
| config, | ||
| })), | ||
| })); | ||
|
|
||
| describe('MiniMaxOpenAICompatibleProvider', () => { | ||
| let provider: MiniMaxOpenAICompatibleProvider; | ||
| let mockContentGeneratorConfig: ContentGeneratorConfig; | ||
| let mockCliConfig: Config; | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
|
|
||
| mockContentGeneratorConfig = { | ||
| apiKey: 'test-minimax-api-key', | ||
| baseUrl: 'https://api.minimax.io/v1', | ||
| model: 'MiniMax-M2.7', | ||
| } as ContentGeneratorConfig; | ||
|
|
||
| mockCliConfig = { | ||
| getCliVersion: vi.fn().mockReturnValue('1.0.0'), | ||
| getProxy: vi.fn().mockReturnValue(undefined), | ||
| } as unknown as Config; | ||
|
|
||
| provider = new MiniMaxOpenAICompatibleProvider( | ||
| mockContentGeneratorConfig, | ||
| mockCliConfig, | ||
| ); | ||
| }); | ||
|
|
||
| describe('isMiniMaxProvider', () => { | ||
| it('returns true when baseUrl contains api.minimax.io', () => { | ||
| const result = MiniMaxOpenAICompatibleProvider.isMiniMaxProvider( | ||
| mockContentGeneratorConfig, | ||
| ); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it('returns true when baseUrl contains api.minimaxi.com', () => { | ||
| const config = { | ||
| ...mockContentGeneratorConfig, | ||
| baseUrl: 'https://api.minimaxi.com/v1', | ||
| } as ContentGeneratorConfig; | ||
| expect(MiniMaxOpenAICompatibleProvider.isMiniMaxProvider(config)).toBe( | ||
| true, | ||
| ); | ||
| }); | ||
|
|
||
| it('returns false for non-MiniMax baseUrl', () => { | ||
| const config = { | ||
| ...mockContentGeneratorConfig, | ||
| baseUrl: 'https://api.openai.com/v1', | ||
| } as ContentGeneratorConfig; | ||
| expect(MiniMaxOpenAICompatibleProvider.isMiniMaxProvider(config)).toBe( | ||
| false, | ||
| ); | ||
| }); | ||
|
|
||
| it('returns false when baseUrl is undefined', () => { | ||
| const config = { | ||
| ...mockContentGeneratorConfig, | ||
| baseUrl: undefined, | ||
| } as ContentGeneratorConfig; | ||
| expect(MiniMaxOpenAICompatibleProvider.isMiniMaxProvider(config)).toBe( | ||
| false, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getDefaultGenerationConfig', () => { | ||
| it('returns temperature 1.0 as default', () => { | ||
| expect(provider.getDefaultGenerationConfig()).toEqual({ | ||
| temperature: 1.0, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('buildRequest', () => { | ||
| const userPromptId = 'prompt-123'; | ||
|
|
||
| it('removes response_format from request', () => { | ||
| const request = { | ||
| model: 'MiniMax-M2.7', | ||
| messages: [{ role: 'user' as const, content: 'Hello' }], | ||
| response_format: { type: 'json_object' as const }, | ||
| } as OpenAI.Chat.ChatCompletionCreateParams; | ||
|
|
||
| const result = provider.buildRequest(request, userPromptId); | ||
| expect(result).not.toHaveProperty('response_format'); | ||
| }); | ||
|
|
||
| it('sets temperature to 1.0 when temperature is 0', () => { | ||
| const request: OpenAI.Chat.ChatCompletionCreateParams = { | ||
| model: 'MiniMax-M2.7', | ||
| messages: [{ role: 'user', content: 'Hello' }], | ||
| temperature: 0, | ||
| }; | ||
|
|
||
| const result = provider.buildRequest(request, userPromptId); | ||
| expect(result.temperature).toBe(1.0); | ||
| }); | ||
|
|
||
| it('sets temperature to 1.0 when temperature is undefined', () => { | ||
| const request: OpenAI.Chat.ChatCompletionCreateParams = { | ||
| model: 'MiniMax-M2.7', | ||
| messages: [{ role: 'user', content: 'Hello' }], | ||
| }; | ||
|
|
||
| const result = provider.buildRequest(request, userPromptId); | ||
| expect(result.temperature).toBe(1.0); | ||
| }); | ||
|
|
||
| it('preserves valid temperature values', () => { | ||
| const request: OpenAI.Chat.ChatCompletionCreateParams = { | ||
| model: 'MiniMax-M2.7', | ||
| messages: [{ role: 'user', content: 'Hello' }], | ||
| temperature: 0.7, | ||
| }; | ||
|
|
||
| const result = provider.buildRequest(request, userPromptId); | ||
| expect(result.temperature).toBe(0.7); | ||
| }); | ||
|
|
||
| it('preserves messages unchanged', () => { | ||
| const request: OpenAI.Chat.ChatCompletionCreateParams = { | ||
| model: 'MiniMax-M2.7', | ||
| messages: [ | ||
| { role: 'user', content: 'Hello' }, | ||
| { role: 'assistant', content: 'Hi there' }, | ||
| ], | ||
| }; | ||
|
|
||
| const result = provider.buildRequest(request, userPromptId); | ||
| expect(result.messages).toHaveLength(2); | ||
| expect(result.messages?.[0].content).toBe('Hello'); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,83 @@ | ||||||||||||||
| /** | ||||||||||||||
| * @license | ||||||||||||||
| * Copyright 2025 Qwen | ||||||||||||||
| * SPDX-License-Identifier: Apache-2.0 | ||||||||||||||
| */ | ||||||||||||||
|
|
||||||||||||||
| import type OpenAI from 'openai'; | ||||||||||||||
| import type { GenerateContentConfig } from '@google/genai'; | ||||||||||||||
| import type { Config } from '../../../config/config.js'; | ||||||||||||||
| import type { ContentGeneratorConfig } from '../../contentGenerator.js'; | ||||||||||||||
| import { DefaultOpenAICompatibleProvider } from './default.js'; | ||||||||||||||
|
|
||||||||||||||
| const MINIMAX_DEFAULT_BASE_URL = 'https://api.minimax.io/v1'; | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Provider for MiniMax API (OpenAI-compatible interface). | ||||||||||||||
| * | ||||||||||||||
| * MiniMax-specific constraints: | ||||||||||||||
| * - temperature must be in the range (0.0, 1.0]; 0 is not allowed, default is 1.0 | ||||||||||||||
| * - response_format is not supported and must be removed from requests | ||||||||||||||
| */ | ||||||||||||||
| export class MiniMaxOpenAICompatibleProvider extends DefaultOpenAICompatibleProvider { | ||||||||||||||
| constructor( | ||||||||||||||
| contentGeneratorConfig: ContentGeneratorConfig, | ||||||||||||||
| cliConfig: Config, | ||||||||||||||
| ) { | ||||||||||||||
| super(contentGeneratorConfig, cliConfig); | ||||||||||||||
| // Use MiniMax default base URL if not explicitly configured | ||||||||||||||
| if (!this.contentGeneratorConfig.baseUrl) { | ||||||||||||||
| this.contentGeneratorConfig = { | ||||||||||||||
| ...this.contentGeneratorConfig, | ||||||||||||||
| baseUrl: MINIMAX_DEFAULT_BASE_URL, | ||||||||||||||
| }; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Checks if the configuration targets the MiniMax API. | ||||||||||||||
| */ | ||||||||||||||
| static isMiniMaxProvider(config: ContentGeneratorConfig): boolean { | ||||||||||||||
| const baseUrl = config.baseUrl ?? ''; | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Nice to have] A URL like — qwen3.6-plus via Qwen Code /review |
||||||||||||||
| return ( | ||||||||||||||
| baseUrl.includes('api.minimax.io') || baseUrl.includes('api.minimaxi.com') | ||||||||||||||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * MiniMax default generation config. | ||||||||||||||
| * Temperature defaults to 1.0 because MiniMax does not accept temperature = 0. | ||||||||||||||
| */ | ||||||||||||||
| override getDefaultGenerationConfig(): GenerateContentConfig { | ||||||||||||||
| return { | ||||||||||||||
| temperature: 1.0, | ||||||||||||||
| }; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Build a MiniMax-compatible request by: | ||||||||||||||
| * 1. Ensuring temperature is within the allowed range (0.0, 1.0] | ||||||||||||||
| * 2. Removing unsupported `response_format` parameter | ||||||||||||||
| */ | ||||||||||||||
| override buildRequest( | ||||||||||||||
| request: OpenAI.Chat.ChatCompletionCreateParams, | ||||||||||||||
| userPromptId: string, | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The method casts to
Suggested change
— qwen3.6-plus via Qwen Code /review |
||||||||||||||
| ): OpenAI.Chat.ChatCompletionCreateParams { | ||||||||||||||
| const baseRequest = super.buildRequest(request, userPromptId); | ||||||||||||||
|
|
||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||||||||||
| const result: any = { ...baseRequest }; | ||||||||||||||
|
|
||||||||||||||
| // MiniMax does not support temperature = 0; default to 1.0 | ||||||||||||||
| if (result.temperature === 0 || result.temperature === undefined) { | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] Temperature check doesn't guard against The OpenAI SDK types temperature as
Suggested change
— qwen3.6-plus via Qwen Code /review |
||||||||||||||
| result.temperature = 1.0; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // MiniMax does not support response_format | ||||||||||||||
| if ('response_format' in result) { | ||||||||||||||
| delete result.response_format; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| return result as OpenAI.Chat.ChatCompletionCreateParams; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] Constructor mutates
this.contentGeneratorConfigafter thesuper()call.Sibling providers (DashScope, DeepSeek) leave the config unchanged and apply defaults in
buildClient()via destructuring fallback. If any code holds a reference to the original config object, it won't see the updatedbaseUrl.Consider applying the default URL in
buildClient()or via a protected getter, matching sibling patterns.— qwen3.6-plus via Qwen Code /review