feat(providers): add default_headers support for custom providers#1552
feat(providers): add default_headers support for custom providers#1552nphenix wants to merge 2 commits intoagentscope-ai:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the flexibility and compatibility of custom providers by enabling the configuration of custom HTTP headers. This change addresses the need for specific headers, such as Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature by adding support for custom HTTP headers to providers, enhancing API compatibility. The changes are well-implemented across both the frontend and backend. The backend logic for handling, storing, and merging headers is robust. The frontend provides a clear user interface for managing these headers. I have a couple of minor suggestions for the frontend code to improve maintainability and adherence to React best practices.
console/src/pages/Settings/Models/components/modals/CustomProviderModal.tsx
Outdated
Show resolved
Hide resolved
console/src/pages/Settings/Models/components/modals/ProviderConfigModal.tsx
Outdated
Show resolved
Hide resolved
console/src/pages/Settings/Models/components/modals/ProviderConfigModal.tsx
Outdated
Show resolved
Hide resolved
Add custom HTTP headers support to custom providers, enabling Kimi Coding Plan and other providers requiring special headers. Backend changes: - CustomProviderData: add default_headers field (Dict[str, str]) - ProviderInfo/Provider: add default_headers field - OpenAIProvider: use default_headers in _client() and get_chat_model_instance() - Provider.update_config(): support updating default_headers - Provider.get_info(): include default_headers in response - providers.py API: add default_headers to ProviderConfigRequest, CreateCustomProviderRequest, TestModelRequest - test_provider/test_model: apply headers during connection testing Frontend changes: - ProviderInfo/ProviderConfigRequest/CreateCustomProviderRequest/ TestProviderRequest/TestModelRequest: add default_headers field - CustomProviderModal: add headers configuration UI with User-Agent prefill - ProviderConfigModal: add headers editing UI with add/remove functionality - RemoteModelManageModal: pass default_headers when testing models This allows users to configure Kimi Coding Plan via custom provider with User-Agent header set to KimiCLI/0.77.
0d2053c to
841cbff
Compare
…feature - Add unique 'id' field to HeaderItem interface to fix React key anti-pattern - Use crypto.randomUUID() to generate stable identifiers for headers - Extract headersToObject() helper function to eliminate DRY violation - Update updateHeader type to exclude 'id' field - Fix black formatting in providers.py
Summary
Add custom HTTP headers support to custom providers for better API compatibility. This enables providers that require special headers (e.g., authentication headers, custom
User-Agent) to work with CoPaw.Motivation
Some OpenAI-compatible APIs require custom HTTP headers for proper functionality:
User-Agentto identify client typesChanges
Backend
CustomProviderData: adddefault_headersfield (Dict[str, str])ProviderInfo/Provider: adddefault_headersfield with backward-compatible defaultsOpenAIProvider: mergedefault_headersinto API client requestsProvider.update_config(): support updatingdefault_headersProvider.get_info(): includedefault_headersin responseproviders.pyAPI: adddefault_headerstoProviderConfigRequest,CreateCustomProviderRequest,TestModelRequesttest_provider/test_model: apply headers during connection testingFrontend
default_headerstoProviderInfo,ProviderConfigRequest,CreateCustomProviderRequest,TestProviderRequest,TestModelRequestCustomProviderModal: add headers configuration UI with smart prefill (first header suggestsUser-Agent)ProviderConfigModal: add headers editing UI with add/remove functionalityRemoteModelManageModal: passdefault_headerswhen testing model connectionsTesting
pytest tests/unit/providers/)npm run build)User-Agent: KimiCLI/0.77)Backward Compatibility
Fully backward compatible:
default_headerscontinue to work normally{}is the default (no behavioral change)Usage Example
For providers requiring custom headers:
User-Agent: CustomClient/1.0)