WIP: Add Claude (Anthropic) model support #15

Draft
Copilot wants to merge 4 commits from copilot/add-claude-support-latest-model into main
Copilot commented 2025-12-06 00:31:39 +07:00 (Migrated from github.com)

Adds support for Anthropic's Claude models including the latest Claude 4 and Claude 3.5 variants.

Models Added

  • anthropic/claude-sonnet-4-20250514
  • anthropic/claude-opus-4-20250514
  • anthropic/claude-3.5-sonnet
  • anthropic/claude-3.5-haiku

Changes

New Claude API Integration (src/utils/claude_utils.py)

  • Message format conversion (OpenAI → Claude format, handles system prompt extraction and consecutive message merging)
  • Tool definitions translated to Claude schema
  • Image handling with data URL parsing

Configuration

  • ANTHROPIC_API_KEY env var support
  • Model pricing and token limits for Claude models
  • Added to MODEL_OPTIONS and PDF_ALLOWED_MODELS

Bot Integration

  • Anthropic client initialization in bot.py
  • Route Claude requests in message_handler.py with full tool support
  • /search and /web commands handle Claude models

Usage

# Model detection
from src.utils.claude_utils import is_claude_model
is_claude_model("anthropic/claude-3.5-sonnet")  # True

# Set via Discord
/set_model anthropic/claude-sonnet-4-20250514

Claude models require ANTHROPIC_API_KEY in .env. Bot gracefully degrades if key is not configured.

Original prompt

Add claude support for newest model and up-to-date api, code,....


Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Adds support for Anthropic's Claude models including the latest Claude 4 and Claude 3.5 variants. ## Models Added - `anthropic/claude-sonnet-4-20250514` - `anthropic/claude-opus-4-20250514` - `anthropic/claude-3.5-sonnet` - `anthropic/claude-3.5-haiku` ## Changes ### New Claude API Integration (`src/utils/claude_utils.py`) - Message format conversion (OpenAI → Claude format, handles system prompt extraction and consecutive message merging) - Tool definitions translated to Claude schema - Image handling with data URL parsing ### Configuration - `ANTHROPIC_API_KEY` env var support - Model pricing and token limits for Claude models - Added to `MODEL_OPTIONS` and `PDF_ALLOWED_MODELS` ### Bot Integration - Anthropic client initialization in `bot.py` - Route Claude requests in `message_handler.py` with full tool support - `/search` and `/web` commands handle Claude models ## Usage ```python # Model detection from src.utils.claude_utils import is_claude_model is_claude_model("anthropic/claude-3.5-sonnet") # True # Set via Discord /set_model anthropic/claude-sonnet-4-20250514 ``` Claude models require `ANTHROPIC_API_KEY` in `.env`. Bot gracefully degrades if key is not configured. <!-- START COPILOT CODING AGENT SUFFIX --> <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > Add claude support for newest model and up-to-date api, code,.... </details> <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/Coder-Vippro/ChatGPT-Discord-Bot/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.
cauvang32 (Migrated from github.com) reviewed 2025-12-06 00:31:39 +07:00
coderabbitai[bot] commented 2025-12-06 00:32:06 +07:00 (Migrated from github.com)

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- This is an auto-generated comment: skip review by coderabbit.ai --> > [!IMPORTANT] > ## Review skipped > > Bot user detected. > > To trigger a single review, invoke the `@coderabbitai review` command. > > You can disable this status message by setting the `reviews.review_status` to `false` in the CodeRabbit configuration file. <!-- end of auto-generated comment: skip review by coderabbit.ai --> <!-- tips_start --> --- <sub>Comment `@coderabbitai help` to get the list of available commands and usage tips.</sub> <!-- tips_end -->
This pull request has changes conflicting with the target branch.
  • requirements.txt
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin copilot/add-claude-support-latest-model:copilot/add-claude-support-latest-model
git checkout copilot/add-claude-support-latest-model
Sign in to join this conversation.