diff --git a/README.md b/README.md index 3eb3a73..080b296 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,8 @@ MiniMax provides both global and China platforms. Choose based on your network e | Version | Platform | API Base | | ---------- | -------------------------------------------------------------- | -------------------------- | -| **Global** | [https://platform.minimax.io](https://platform.minimax.io) | `https://api.minimax.io` | -| **China** | [https://platform.minimaxi.com](https://platform.minimaxi.com) | `https://api.minimaxi.com` | +| **Global** | [https://platform.minimax.io](https://platform.minimax.io) | `https://api.minimax.io/anthropic` | +| **China** | [https://platform.minimaxi.com](https://platform.minimaxi.com) | `https://api.minimaxi.com/anthropic` | **Steps to get API Key:** 1. Visit the corresponding platform to register and login @@ -56,7 +56,7 @@ MiniMax provides both global and China platforms. Choose based on your network e 3. Click **"Create New Key"** 4. Copy and save it securely (key is only shown once) -> 💡 **Tip**: Remember the API Base address corresponding to your chosen platform, you'll need it for configuration +> 💡 **Tip**: Use the full provider-specific API Base in config (e.g., `/anthropic` for provider `anthropic`, `/v1` for provider `openai`). ### 2. Choose Your Usage Mode @@ -113,8 +113,9 @@ Fill in your API Key and corresponding API Base: ```yaml api_key: "YOUR_API_KEY_HERE" # API Key from step 1 -api_base: "https://api.minimax.io" # Global -# api_base: "https://api.minimaxi.com" # China +api_base: "https://api.minimax.io/anthropic" # Global (Anthropic-compatible) +# api_base: "https://api.minimaxi.com/anthropic" # China (Anthropic-compatible) +# If provider is "openai", use: https://api.minimax.io/v1 or https://api.minimaxi.com/v1 model: "MiniMax-M2" ``` @@ -180,8 +181,9 @@ Fill in your API Key and corresponding API Base: ```yaml api_key: "YOUR_API_KEY_HERE" # API Key from step 1 -api_base: "https://api.minimax.io" # Global -# api_base: "https://api.minimaxi.com" # China +api_base: "https://api.minimax.io/anthropic" # Global (Anthropic-compatible) +# api_base: "https://api.minimaxi.com/anthropic" # China (Anthropic-compatible) +# If provider is "openai", use: https://api.minimax.io/v1 or https://api.minimaxi.com/v1 model: "MiniMax-M2" max_steps: 100 workspace_dir: "./workspace" diff --git a/README_CN.md b/README_CN.md index 7512bae..fa411c1 100644 --- a/README_CN.md +++ b/README_CN.md @@ -47,8 +47,8 @@ MiniMax 提供国内和海外两个平台,请根据您的网络环境选择: | 版本 | 平台地址 | API Base | | ---------- | -------------------------------------------------------------- | -------------------------- | -| **国内版** | [https://platform.minimaxi.com](https://platform.minimaxi.com) | `https://api.minimaxi.com` | -| **海外版** | [https://platform.minimax.io](https://platform.minimax.io) | `https://api.minimax.io` | +| **国内版** | [https://platform.minimaxi.com](https://platform.minimaxi.com) | `https://api.minimaxi.com/anthropic` | +| **海外版** | [https://platform.minimax.io](https://platform.minimax.io) | `https://api.minimax.io/anthropic` | **获取步骤:** 1. 访问相应平台注册并登录 @@ -56,7 +56,7 @@ MiniMax 提供国内和海外两个平台,请根据您的网络环境选择: 3. 点击 **"创建新密钥"** 4. 复制并妥善保存(密钥仅显示一次) -> 💡 **提示**:请记住您所选平台对应的 API Base 地址,后续配置时会用到。 +> 💡 **提示**:配置时请填写完整的、与 provider 匹配的 API Base(如 provider 为 `anthropic` 时使用 `/anthropic`,provider 为 `openai` 时使用 `/v1`)。 ### 2. 选择使用模式 @@ -113,8 +113,9 @@ nano ~/.mini-agent/config/config.yaml ```yaml api_key: "YOUR_API_KEY_HERE" # 填入第 1 步获取的 API Key -api_base: "https://api.minimaxi.com" # 国内版 -# api_base: "https://api.minimax.io" # 海外版(如使用海外平台,请取消本行注释) +api_base: "https://api.minimaxi.com/anthropic" # 国内版(Anthropic 兼容) +# api_base: "https://api.minimax.io/anthropic" # 海外版(Anthropic 兼容) +# 若 provider 为 "openai",请使用:https://api.minimax.io/v1 或 https://api.minimaxi.com/v1 model: "MiniMax-M2" ``` @@ -180,8 +181,9 @@ vim mini_agent/config/config.yaml # 或使用您偏好的编辑器 ```yaml api_key: "YOUR_API_KEY_HERE" # 填入第 1 步获取的 API Key -api_base: "https://api.minimaxi.com" # 国内版 -# api_base: "https://api.minimax.io" # 海外版(如使用海外平台,请修改此行) +api_base: "https://api.minimaxi.com/anthropic" # 国内版(Anthropic 兼容) +# api_base: "https://api.minimax.io/anthropic" # 海外版(Anthropic 兼容) +# 若 provider 为 "openai",请使用:https://api.minimax.io/v1 或 https://api.minimaxi.com/v1 model: "MiniMax-M2" max_steps: 100 workspace_dir: "./workspace" diff --git a/mini_agent/config.py b/mini_agent/config.py index bcd86e6..f3ab45a 100644 --- a/mini_agent/config.py +++ b/mini_agent/config.py @@ -23,7 +23,7 @@ class LLMConfig(BaseModel): """LLM configuration""" api_key: str - api_base: str = "https://api.minimax.io" + api_base: str = "https://api.minimax.io/anthropic" model: str = "MiniMax-M2" provider: str = "anthropic" # "anthropic" or "openai" retry: RetryConfig = Field(default_factory=RetryConfig) @@ -115,7 +115,7 @@ def from_yaml(cls, config_path: str | Path) -> "Config": llm_config = LLMConfig( api_key=data["api_key"], - api_base=data.get("api_base", "https://api.minimax.io"), + api_base=data.get("api_base", "https://api.minimax.io/anthropic"), model=data.get("model", "MiniMax-M2"), provider=data.get("provider", "anthropic"), retry=retry_config, diff --git a/mini_agent/config/config-example.yaml b/mini_agent/config/config-example.yaml index 9d259ce..49448ec 100644 --- a/mini_agent/config/config-example.yaml +++ b/mini_agent/config/config-example.yaml @@ -1,5 +1,5 @@ # Mini Agent Configuration Example -# +# # Configuration File Locations (in priority order): # 1) mini_agent/config/config.yaml - Development mode (current directory) # 2) ~/.mini-agent/config/config.yaml - User config directory @@ -16,39 +16,39 @@ # - Global: https://platform.minimax.io -> api_base: https://api.minimax.io # - China: https://platform.minimaxi.com -> api_base: https://api.minimaxi.com # Please choose based on your network environment and get API key from corresponding platform -api_key: "YOUR_API_KEY_HERE" # Replace with your MiniMax API Key -api_base: "https://api.minimax.io" # Global users (default) +api_key: "YOUR_API_KEY_HERE" # Replace with your MiniMax API Key +api_base: "https://api.minimax.io/anthropic" # Global users (default) # api_base: "https://api.minimaxi.com" # China users model: "MiniMax-M2" # LLM provider: "anthropic" or "openai" -# The LLMClient will automatically append /anthropic or /v1 to api_base based on provider -provider: "anthropic" # Default: anthropic +provider: "anthropic" # Default: anthropic # ===== Retry Configuration ===== retry: - enabled: true # Enable retry mechanism - max_retries: 3 # Maximum number of retries - initial_delay: 1.0 # Initial delay time (seconds) - max_delay: 60.0 # Maximum delay time (seconds) - exponential_base: 2.0 # Exponential backoff base (delay = initial_delay * base^attempt) + enabled: true # Enable retry mechanism + max_retries: 3 # Maximum number of retries + initial_delay: 1.0 # Initial delay time (seconds) + max_delay: 60.0 # Maximum delay time (seconds) + exponential_base: 2.0 # Exponential backoff base (delay = initial_delay * base^attempt) # ===== Agent Configuration ===== -max_steps: 100 # Maximum execution steps -workspace_dir: "./workspace" # Working directory -system_prompt_path: "system_prompt.md" # System prompt file (same config directory) +max_steps: 100 # Maximum execution steps +workspace_dir: "./workspace" # Working directory +system_prompt_path: "system_prompt.md" # System prompt file (same config directory) # ===== Tools Configuration ===== tools: # Basic tool switches - enable_file_tools: true # File read/write/edit tools (ReadTool, WriteTool, EditTool) - enable_bash: true # Bash command execution tool - enable_note: true # Session note tool (SessionNoteTool) - + enable_file_tools: true # File read/write/edit tools (ReadTool, WriteTool, EditTool) + enable_bash: true # Bash command execution tool + enable_note: true # Session note tool (SessionNoteTool) + # Claude Skills - enable_skills: true # Enable Skills - skills_dir: "./skills" # Skills directory path - + enable_skills: true # Enable Skills + skills_dir: "./skills" # Skills directory path + # MCP Tools - enable_mcp: true # Enable MCP tools - mcp_config_path: "mcp.json" # MCP configuration file (same config directory) - # Note: API Keys for MCP tools are configured in mcp.json + enable_mcp: true # Enable MCP tools + mcp_config_path: + "mcp.json" # MCP configuration file (same config directory) + # Note: API Keys for MCP tools are configured in mcp.json diff --git a/mini_agent/llm/llm_wrapper.py b/mini_agent/llm/llm_wrapper.py index 8250fb7..a33a399 100644 --- a/mini_agent/llm/llm_wrapper.py +++ b/mini_agent/llm/llm_wrapper.py @@ -19,19 +19,21 @@ class LLMClient: """LLM Client wrapper supporting multiple providers. This class provides a unified interface for different LLM providers. - It automatically instantiates the correct underlying client based on - the provider parameter and appends the appropriate API endpoint suffix. + It instantiates the correct underlying client based on the provider + parameter. The given api_base is passed through as-is. Supported providers: - - anthropic: Appends /anthropic to api_base - - openai: Appends /v1 to api_base + - anthropic: api_base should point to the Anthropic-compatible root + (e.g., https://api.minimaxi.com/anthropic) + - openai: api_base should point to the OpenAI-compatible root + (e.g., https://api.minimaxi.com/v1) """ def __init__( self, api_key: str, provider: LLMProvider = LLMProvider.ANTHROPIC, - api_base: str = "https://api.minimaxi.com", + api_base: str = "https://api.minimax.io/anthropic", model: str = "MiniMax-M2", retry_config: RetryConfig | None = None, ): @@ -40,8 +42,7 @@ def __init__( Args: api_key: API key for authentication provider: LLM provider (anthropic or openai) - api_base: Base URL for the API (default: https://api.minimaxi.com) - Will be automatically suffixed with /anthropic or /v1 based on provider + api_base: Base URL for the API. Must be the full provider-specific base. model: Model name to use retry_config: Optional retry configuration """ @@ -50,39 +51,31 @@ def __init__( self.model = model self.retry_config = retry_config or RetryConfig() - # for backward compatibility - api_base = api_base.replace("/anthropic", "") - - # Append provider-specific suffix to api_base - if provider == LLMProvider.ANTHROPIC: - full_api_base = f"{api_base.rstrip('/')}/anthropic" - elif provider == LLMProvider.OPENAI: - full_api_base = f"{api_base.rstrip('/')}/v1" - else: + if provider not in (LLMProvider.ANTHROPIC, LLMProvider.OPENAI): raise ValueError(f"Unsupported provider: {provider}") - self.api_base = full_api_base + self.api_base = api_base # Instantiate the appropriate client self._client: LLMClientBase if provider == LLMProvider.ANTHROPIC: self._client = AnthropicClient( api_key=api_key, - api_base=full_api_base, + api_base=api_base, model=model, retry_config=retry_config, ) elif provider == LLMProvider.OPENAI: self._client = OpenAIClient( api_key=api_key, - api_base=full_api_base, + api_base=api_base, model=model, retry_config=retry_config, ) else: raise ValueError(f"Unsupported provider: {provider}") - logger.info("Initialized LLM client with provider: %s, api_base: %s", provider, full_api_base) + logger.info("Initialized LLM client with provider: %s, api_base: %s", provider, api_base) @property def retry_callback(self): diff --git a/tests/test_integration.py b/tests/test_integration.py index 7a2a36a..047e332 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -46,9 +46,12 @@ async def test_basic_agent_usage(): else: system_prompt = "You are a helpful AI assistant." + from mini_agent.schema import LLMProvider + provider = LLMProvider.ANTHROPIC if config.llm.provider.lower() == "anthropic" else LLMProvider.OPENAI # Initialize LLM client llm_client = LLMClient( api_key=config.llm.api_key, + provider=provider, api_base=config.llm.api_base, model=config.llm.model, )