Amux

适配器概览

Amux 支持的所有官方适配器

Amux 提供了 8 个官方适配器,支持主流的 LLM 提供商。每个适配器负责在提供商特定格式和统一的中间表示 (IR) 之间进行双向转换。

官方适配器

功能对比

适配器流式传输工具调用视觉多模态推理JSON 模式
OpenAI
Anthropic
DeepSeek
Moonshot
Zhipu
Qwen
Gemini
MiniMax

选择适配器

按功能选择

视觉和多模态

  • OpenAI (GPT-4o)、Anthropic (Claude 3)、Qwen (通义千问 VL)、Gemini (Gemini Pro Vision)、Zhipu (GLM-4V)

长上下文

  • Gemini (1M+ tokens)、Anthropic (200K)、Moonshot (200K)

编程能力

  • MiniMax (MiniMax-M2.1)、DeepSeek (DeepSeek Coder)、OpenAI (GPT-4)、Anthropic (Claude 3.5 Sonnet)

推理能力

  • MiniMax (Interleaved Thinking)、OpenAI Responses API (o3、o4-mini)、DeepSeek (DeepSeek Reasoner)、Moonshot (Kimi K2 Thinking)

按价格选择

最经济: DeepSeek、Qwen

中等价格: OpenAI GPT-3.5、Moonshot

高端模型: OpenAI GPT-4、Anthropic Claude、Gemini Pro

按 OpenAI 兼容性

以下适配器兼容 OpenAI 格式,可以无缝替换:

  • DeepSeek (完全兼容)
  • MiniMax (完全兼容)
  • Moonshot (完全兼容)
  • Zhipu (完全兼容)
  • Qwen (基本兼容,有细微差异)
  • Gemini (需要格式转换)

快速开始

pnpm add @amux.ai/llm-bridge @amux.ai/adapter-openai @amux.ai/adapter-anthropic

基本使用

import { createBridge } from '@amux.ai/llm-bridge'
import { openaiAdapter } from '@amux.ai/adapter-openai'
import { anthropicAdapter } from '@amux.ai/adapter-anthropic'

// 接受 OpenAI 格式,调用 Claude API
const bridge = createBridge({
  inbound: openaiAdapter,
  outbound: anthropicAdapter,
  config: {
    apiKey: process.env.ANTHROPIC_API_KEY
  }
})

const response = await bridge.chat({
  model: 'gpt-4',
  messages: [{ role: 'user', content: '你好!' }]
})

创建自定义适配器

需要支持其他 LLM 提供商?创建自定义适配器:

import type { LLMAdapter } from '@amux.ai/llm-bridge'

export const myAdapter: LLMAdapter = {
  name: 'my-provider',
  version: '1.0.0',
  capabilities: {
    streaming: true,
    tools: true,
    vision: false,
    multimodal: false,
    systemPrompt: true,
    toolChoice: true
  },
  inbound: {
    parseRequest: (request) => { /* ... */ },
    parseResponse: (response) => { /* ... */ },
    parseStream: (stream) => { /* ... */ },
    parseError: (error) => { /* ... */ }
  },
  outbound: {
    buildRequest: (ir) => { /* ... */ },
    buildResponse: (ir) => { /* ... */ }
  },
  getInfo() {
    return {
      name: this.name,
      version: this.version,
      capabilities: this.capabilities,
      endpoint: {
        baseURL: 'https://api.my-provider.com',
        chatPath: '/v1/chat'
      }
    }
  }
}

查看自定义适配器指南获取完整教程。

下一步

On this page