-
Notifications
You must be signed in to change notification settings - Fork 902
feat(ai-proxy): add auto protocol compatibility for OpenAI and Claude APIs #2810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
AI代理插件新增Claude协议自动兼容功能变更概述
变更文件
💡 小贴士与 lingma-agents 交流的方式📜 直接回复评论
📜 在代码行处标记
📜 在讨论中提问
Change Overview
Test Update
Change file
💡 TipsHow to communicate with lingma-agents📜 Reply to comments directly
**📜 Mark ** at line of code
📜 Ask a question during discussion
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2810 +/- ##
==========================================
+ Coverage 35.91% 45.31% +9.40%
==========================================
Files 69 82 +13
Lines 11576 13224 +1648
==========================================
+ Hits 4157 5992 +1835
+ Misses 7104 6886 -218
- Partials 315 346 +31 🚀 New features to boost your workflow:
|
Overview
This PR implements automatic protocol compatibility that enables seamless support for both OpenAI and Claude API protocols without requiring user configuration. The plugin now intelligently detects the incoming request protocol and automatically handles protocol conversion when needed.
Key Features
✨ Auto Protocol Detection
/v1/chat/completionspath/v1/messagespath🧠 Intelligent Protocol Conversion
🔄 Backward Compatibility
protocolfield is now optional and ignored for auto-detectionTechnical Implementation
Core Components
main.go): Path-based protocol detection inonHttpRequestHeaderprovider/claude_to_openai.go): Bidirectional conversion between Claude and OpenAI formatsprovider/provider.go):IsSupportedAPImethod for checking native protocol supportneedClaudeResponseConversionto track conversion state across request lifecycleRequest Flow
Incoming Request → Protocol Detection → Provider Capability Check → Smart Conversion → Target Provider
↓
Response Conversion ← Protocol Detection ← Provider Response ← Target Provider
Usage Examples
Supported Request Formats
Code Changes
New Files
provider/claude_to_openai.go: Protocol conversion logicModified Files
main.go: Auto-detection logic and response conversionprovider/provider.go: Removed unused Claude protocol configuration, added capability checksRemoved Code
protocolClaudeconstant and related configuration logicIsClaudeProtocol()methodTesting
claudetype) work without conversionqwentype) auto-convert Claude requestsBenefits
Migration Guide
No action required - existing configurations will continue to work. Users can optionally remove the
protocolfield from their configurations as it's no longer needed.This change transforms the AI proxy plugin into a truly "protocol-agnostic" gateway, dramatically simplifying the user experience while maintaining full backward compatibility.