minimax

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2026 License: None detected not legal advice Imports: 0 Imported by: 0

Documentation

Overview

Package minimax 实现 MiniMax 官方 API 的 ModelProvider.

MiniMax 提供三种 API 接入方式:

  1. Native API - /v1/text/chatcompletion_v2(官方路径,本实现默认)
  2. OpenAI 兼容 - /v1/chat/completions
  3. Anthropic 兼容 - /anthropic/v1/messages(MiniMax 对外推广,但实测效果不稳定)

默认使用 Native 模式,原因:

  • Native 是 MiniMax 的第一方 API,语义最完整
  • 实测 Anthropic 兼容端点在编程类 Agent 场景下表现较差 (可能是 Anthropic 特有的 beta headers / system prompt 格式未完全兼容)
  • OpenAI 兼容和 Native 的 SSE 格式相同,切换成本低

Native API 的 SSE 格式与 OpenAI 完全相同(data: {...}, data: [DONE]), 因此我们复用 internal/wire/openai_compat.go,只需修改端点路径.

历史包袱(LEGACY): flysafe 早期通过 BaseURL="https://api.minimaxi.com/anthropic" 使用 MiniMax,走的是 Anthropic 兼容端点. 迁移路径:flysafe 改用 minimax.New(Config{APIKey: "..."}) 即可, 无需关心底层使用哪种格式.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// APIKey 是 MiniMax API 密钥(从 platform.minimax.io 获取).
	APIKey string

	// Region 控制使用国际节点还是中国节点(默认 RegionChina).
	// MiniMax 主要面向中国市场,默认使用国内节点(api.minimaxi.com).
	// 如需使用国际节点(api.minimax.io),显式设置 RegionGlobal.
	Region Region

	// Mode 控制使用哪种 API 格式(默认 ModeNative).
	Mode Mode

	// ThinkingBudget 启用思考模式(仅 M2.1+ 支持).
	// 0 = 禁用.推荐值:5000-16000.
	// ModeNative/ModeOpenAI 时通过 reasoning_split 参数传递.
	// ModeAnthropic 时通过 thinking.budget_tokens 传递.
	ThinkingBudget int

	// HTTPClient 注入自定义 HTTP 客户端.
	// nil = 使用默认 http.Client (带 Timeout 字段配置的 ResponseHeaderTimeout).
	// 非 nil 时 consumer 完全接管超时责任, 下面的 Timeout 字段被忽略.
	//
	// 精妙之处(CLEVER): minimax 的 HTTPClient 会被双模式 (ModeAnthropic / ModeNative|OpenAI)
	// 两个独立客户端同时使用 - 消费者注入的 client 会被两边共享.这是 MiniMax 特有的,
	// 因为同一个 Provider 实例只会选一种 Mode, 不会同时用两个 client.
	HTTPClient *http.Client

	// Timeout 限制"从请求发出到收到响应首字节"的时间.
	//
	// 通过 http.Transport.ResponseHeaderTimeout 实现, **不影响** SSE 流式响应的后续
	// body 读取 - MiniMax 长思考模式 (M2.7 Thinking) 可以正常读完.
	//
	// 精妙之处(CLEVER): 不要误用 http.Client.Timeout - 那会把 SSE 流砍死.
	// MiniMax 的双模式 (ModeAnthropic / ModeNative|OpenAI) 都从这一个字段读超时,
	// 两个底层 client 独立应用, 语义保持等价.
	//
	// 0 = 使用 defaultTimeout (60s, 适合 MiniMax 云端).
	// 仅当 HTTPClient 为 nil 时生效; 提供自定义 HTTPClient 时此字段被忽略.
	Timeout time.Duration

	// ModelOverrides 覆盖静态模型表.
	ModelOverrides []flyto.ModelInfo
}

Config 是 MiniMax provider 的配置.

func (Config) GoString

func (c Config) GoString() string

GoString 实现 fmt.GoStringer,防止 %#v 打印时泄露 APIKey. 升华改进(ELEVATED): 参见 anthropic.Config.GoString 的说明,同理.

type Mode

type Mode string

Mode 是 MiniMax API 接入模式.

const (
	// ModeNative 使用 MiniMax 官方 API(/v1/text/chatcompletion_v2).
	// 推荐:语义最完整,SSE 格式与 OpenAI 相同,思考内容通过 delta.reasoning 字段传递.
	ModeNative Mode = "native"

	// ModeOpenAI 使用 MiniMax 的 OpenAI 兼容端点(/v1/chat/completions).
	// 与 ModeNative 几乎等价,端点路径不同.
	ModeOpenAI Mode = "openai"

	// ModeAnthropic 使用 MiniMax 的 Anthropic 兼容端点(/anthropic/v1/messages).
	// 注意:实测在编程类 Agent 场景下效果可能不如 Native.
	// 仅在明确需要 Anthropic 格式特性(如 cache_control 细粒度控制)时使用.
	ModeAnthropic Mode = "anthropic"
)

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider 是 MiniMax ModelProvider 实现.

func New

func New(cfg Config) *Provider

New 创建 MiniMax ModelProvider.

func (*Provider) Models

func (p *Provider) Models(_ context.Context) ([]flyto.ModelInfo, error)

Models 返回 MiniMax 可用模型列表(静态表).

func (*Provider) Name

func (p *Provider) Name() string

Name 返回 provider 标识.

func (*Provider) Stream

func (p *Provider) Stream(ctx context.Context, req *flyto.Request) (<-chan flyto.Event, error)

Stream 向 MiniMax API 发起流式请求.

升华改进(ELEVATED): data-driven-capabilities RFC PR2.6 - Stream dispatcher 层统一处理 max_tools 检查 + want×can 检测.两条 stream path(streamOpenAI / streamAnthropic)原本 各自做一份检查,提到 dispatcher 层 DRY + 行为一致.能力决策是模型级属性,和序列化格式无关.

type Region

type Region string

Region 是 MiniMax API 地区.

const (
	// RegionGlobal 使用国际节点(api.minimax.io).
	RegionGlobal Region = "global"

	// RegionChina 使用中国节点(api.minimaxi.com).
	RegionChina Region = "china"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL