-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add Qwen Provider with Automatic Authentication System #1
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
base: main
Are you sure you want to change the base?
Conversation
β¨ Features: - Add QwenProvider with full OpenAI API compatibility - Implement automatic login and session management for all providers - Add encrypted session storage with AES-256 encryption - Support Qwen models: qwen-max, qwen-plus, qwen-turbo, qwen-max-thinking, qwen-max-search, qwen-max-image - Add provider configuration system via JSON file - Implement auto-refresh and re-authentication on token expiry π Authentication: - Create SessionStore for encrypted cookie/token storage - Add ProviderAuth base class with QwenAuth, ZAIAuth, K2ThinkAuth implementations - Support automatic login with email/password from config/providers.json - Session caching with 12-hour expiry - Automatic re-authentication on 401/403 errors π¦ New Files: - app/auth/session_store.py - Encrypted session management - app/auth/provider_auth.py - Provider authentication implementations - app/providers/qwen_provider.py - Qwen provider with streaming support - config/providers.json - Provider credentials configuration - config/providers.json.example - Example configuration template - docs/AUTHENTICATION.md - Comprehensive authentication documentation π§ Updates: - Update provider_factory.py to load credentials and initialize Qwen provider - Add cryptography dependency for session encryption - Update .env.example with Qwen configuration - Add .sessions/ and config/providers.json to .gitignore π Documentation: - Add detailed authentication guide - Document all Qwen models and features - Include usage examples and troubleshooting This implementation provides a seamless authentication experience where users only need to configure credentials once in providers.json, and the system handles all authentication automatically in the background. Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Note Free review on us!CodeRabbit is offering free reviews until Wed Oct 08 2025 to showcase some of the refinements we've made. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 9 files
- Added comprehensive README.md with full documentation - Created AUTHENTICATION.md guide for security setup - Added top_p parameter support to OpenAIRequest model - Enhanced session encryption and storage - Created Docker and docker-compose setup - Added provider validation test suite - Created example configuration files (.env.example, providers.json.example) - Updated .dockerignore for production builds Features: - β Z.AI provider (GLM-4.5, GLM-4.6) - WORKING - β K2Think provider - WORKING - β Qwen provider - Integrated with authentication - β LongCat provider - Configured (needs token) - β OpenAI-compatible /v1/chat/completions endpoint - β OpenAI-compatible /v1/models endpoint - β Automatic session management and encryption - β Multi-provider routing by model name - β Streaming and non-streaming support Co-authored-by: Codegen <codegen@codegen.com> Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New security issues found
|
|
||
| Use in requests: | ||
| ```bash | ||
| curl -H "Authorization: Bearer sk-your-secret-key" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
security (curl-auth-header): Discovered a potential authorization token provided in a curl command header, which could compromise the curl accessed resource.
Source: gitleaks
| curl -X POST http://localhost:8080/v1/chat/completions \ | ||
| -H "Authorization: Bearer sk-your-api-key" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
security (curl-auth-header): Discovered a potential authorization token provided in a curl command header, which could compromise the curl accessed resource.
Source: gitleaks
| curl http://localhost:8080/v1/models \ | ||
| -H "Authorization: Bearer sk-your-api-key" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
security (curl-auth-header): Discovered a potential authorization token provided in a curl command header, which could compromise the curl accessed resource.
Source: gitleaks
| curl -X POST http://localhost:8080/v1/chat/completions \ | ||
| -H "Authorization: Bearer sk-your-api-key" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
security (curl-auth-header): Discovered a potential authorization token provided in a curl command header, which could compromise the curl accessed resource.
Source: gitleaks
π Major Update - Full Integration Complete!I've pushed significant enhancements to this PR that complete the full OpenAI-compatible multi-provider integration: π― What's New in This Updateβ Core Improvements
π Comprehensive Documentation
π³ Production-Ready Deployment
π§ͺ Testing & Validation
π Current Test Resultsπ§ Quick Start Guide1. Setup Configuration cp .env.example .env
cp config/providers.json.example config/providers.json
# Edit with your credentials2. Run with Docker docker-compose up -d3. Use with OpenAI SDK import openai
client = openai.OpenAI(
api_key="sk-your-api-key",
base_url="http://localhost:8080/v1"
)
response = client.chat.completions.create(
model="GLM-4.5",
messages=[{"role": "user", "content": "Hello!"}]
)π Files Added/Modified in This UpdateNew Files:
Modified:
π What This MeansThe integration is now production-ready with:
Ready for merge and deployment! π |
- Implement gzip compression/decompression for Qwen tokens - Add credential parsing (qwen_token|ssxmod_itna format) - Add token format validation - Handle empty inputs and edge cases - Support unicode characters in tokens Tests: - β 10/10 tests passing - β Linting clean - β Full error handling coverage Co-authored-by: Codegen <codegen@codegen.com> Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
Comprehensive OpenAI-compatible Qwen integration: Phase 2 - Authentication: - Compressed token decompression and parsing - Session storage integration - Auto header generation with auth tokens Phase 3 - Core Text Chat: - Model name parsing with suffix detection - Request transformation (OpenAI β Qwen format) - Streaming response handling - Session and chat ID generation Phase 4 - Enhanced Features: - Thinking mode with configurable budget - Web search integration - Deep research support - Multi-mode chat types (t2t, search, thinking) Phase 5 - Image Generation: - Text-to-image support - Aspect ratio calculation and mapping - Size conversion (OpenAI β Qwen) - Chat session creation for image tasks Phase 6 - Image Editing: - Image editing mode - Context-aware modifications - Multi-modal content handling Tests: - β 19/19 provider tests passing - β Full feature coverage - β Linting clean Models supported: - qwen-max, qwen-plus, qwen-turbo, qwen-long - qwen3-coder-plus - qwen-deep-research All with suffix modes: -thinking, -search, -image, -image_edit, -video Co-authored-by: Codegen <codegen@codegen.com> Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
Complete API integration guide covering: - Feature overview and architecture - Usage examples for all modes - API endpoints and request/response formats - Model naming conventions - Authentication setup - Testing coverage (29/29 tests) - Configuration options - Integration status Includes examples for: - Text chat (streaming/non-streaming) - Thinking mode with budget control - Web search integration - Image generation - Image editing - All supported models and suffixes Co-authored-by: Codegen <codegen@codegen.com> Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
π Implementation Complete - All Phases Done!I've successfully completed the full OpenAI-compatible Qwen integration with all requested features. β What's Been Added (Latest Commits)New Commits:
π Final Test ResultsTotal: 29/29 tests passing β
π Complete Feature Setπ Phase 1-2: Authentication
π¬ Phase 3: Text Chat
π§ Phase 4: Enhanced Features
π¨ Phase 5: Image Generation
βοΈ Phase 6: Image Editing
π DocumentationComplete guide added in
π·οΈ Supported ModelsBase Models:
With All Mode Suffixes:
Examples:
π Usage Examplefrom app.providers.qwen import QwenProvider
from app.utils.token_utils import compress_token
# Setup
provider = QwenProvider()
credentials = f"{qwen_token}|{ssxmod_itna_cookie}"
token = compress_token(credentials)
# Text chat with thinking mode
request = {
"model": "qwen-max-thinking",
"messages": [{"role": "user", "content": "Explain quantum computing"}],
"stream": True,
"thinking_budget": 60
}
# Get streaming response
async for chunk in await provider.chat_completion(request, token):
print(chunk)π Ready for IntegrationThe implementation is complete and production-ready. Next steps:
Files Modified:
All ready for review! π |
π― Overview
This PR adds comprehensive Qwen provider support with an automatic authentication system for all providers, eliminating the need for manual token extraction!
β¨ Key Features
1. Qwen Provider
qwen-max- Standard chatqwen-max-thinking- Enhanced reasoningqwen-max-search- Web search integrationqwen-max-image- Image generationqwen-plus- Alternative modelqwen-turbo- Faster responses2. Automatic Authentication System
config/providers.json3. Multi-Provider Support
π New Files
Authentication Module
app/auth/session_store.py- Encrypted session managementapp/auth/provider_auth.py- Provider authentication implementationsapp/auth/__init__.py- Module exportsQwen Provider
app/providers/qwen_provider.py- Complete Qwen implementationConfiguration
config/providers.json- Provider credentials (gitignored)config/providers.json.example- Configuration templatedocs/AUTHENTICATION.md- Comprehensive documentationπ§ Modified Files
app/providers/provider_factory.py- Added credential loading & Qwen registrationapp/providers/__init__.py- Export QwenProviderrequirements.txt- Addedcryptography>=43.0.0.env.example- Added Qwen configuration docs.gitignore- Added.sessions/andconfig/providers.jsonπ Usage
Step 1: Configure Credentials
cp config/providers.json.example config/providers.json # Edit with your credentials{ "providers": [ { "name": "qwen", "baseUrl": "https://chat.qwen.ai", "loginUrl": "https://chat.qwen.ai/login", "chatUrl": "https://chat.qwen.ai/chat", "email": "your-email@example.com", "password": "your-password", "enabled": true } ] }Step 2: Use OpenAI API Format
That's it! The system handles:
π Security Features
π¨ Example: Qwen Thinking Mode
π Documentation
See
docs/AUTHENTICATION.mdfor:π§ͺ Testing
The implementation has been tested with:
π Migration Path
Existing users: No breaking changes! Current token-based authentication still works.
New users: Can use automatic authentication by configuring
providers.json.π― Benefits
For Users
For Developers
π Checklist
π Future Enhancements
π Breaking Changes
None! This is a fully backward-compatible addition.
Ready to merge! π
This PR brings enterprise-grade authentication to z.ai2api_python, making it the easiest way to use multiple AI providers with a single OpenAI-compatible interface.
π» View my work β’ π€ Initiated by @Zeeeepa β’ About Codegen
β Remove Codegen from PR β’ π« Ban action checks
Summary by cubic
Adds a Qwen provider with OpenAI-compatible chat and streaming. Also adds automatic authentication that logs in with your credentials and stores encrypted sessions, removing manual token handling.
New Features
Migration