Skip to content

feat: Add support for Anthropic SDK (Claude) and multi-provider switching#38

Open
SmartisanNaive wants to merge 1 commit into666ghj:mainfrom
SmartisanNaive:feat/anthropic-sdk
Open

feat: Add support for Anthropic SDK (Claude) and multi-provider switching#38
SmartisanNaive wants to merge 1 commit into666ghj:mainfrom
SmartisanNaive:feat/anthropic-sdk

Conversation

@SmartisanNaive
Copy link

This PR introduces native support for the Anthropic (Claude) SDK to MiroFish!

While the project already supports various models via the OpenAI-compatible interface, integrating the official Anthropic SDK allows us to better leverage the capabilities of models like Claude 4 Sonnet. It also ensures compatibility with providers that follow the Anthropic protocol (e.g., Zhipu AI's GLM-4.7 endpoint).

🛠️ Key Changes

  1. Refactored LLMClient (backend/app/utils/llm_client.py):

    • Introduced an LLM_PROVIDER mechanism, allowing seamless switching between openai (default) and anthropic.
    • JSON Mode Adaptation: Since the Claude SDK lacks a native json_object mode, I implemented a fallback strategy within the client using System Prompt injection and Markdown parsing. This ensures a consistent chat_json experience for the upper layers.
  2. Configuration Enhancements (backend/app/config.py & .env.example):

    • Added new config options: ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL, etc.
    • Organized .env.example to clearly distinguish between provider configurations.
  3. Documentation:

    • Added backend/LLM_README.md with detailed instructions on how to configure and switch providers.

🧪 How to Test

  1. Update dependencies:

    cd backend
    uv sync  # or uv pip install -r requirements.txt
  2. Update .env to switch to Anthropic:

    LLM_PROVIDER=anthropic
    ANTHROPIC_API_KEY=your_key
    # ANTHROPIC_BASE_URL=... (optional, for custom endpoints)
  3. Start the backend service and trigger a prediction task to verify that the logs output correctly.

Verified locally using Zhipu GLM-4.7 (Anthropic protocol) - communication works as expected.

Ready for review! Thanks 🚀

@666ghj
Copy link
Owner

666ghj commented Jan 24, 2026

I appreciate it, but considering that supporting an additional API format would bring unnecessary workload to the subsequent update plans, I will keep this PR to provide ideas for everyone, but it will not be merged before the release of version 1.0.

@SmartisanNaive
Copy link
Author

SmartisanNaive commented Jan 24, 2026 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants