Custom header for custom Endpoint and HF /embed endpoint - #504
Open
Patrick-DE wants to merge 15 commits into
Open
Custom header for custom Endpoint and HF /embed endpoint#504Patrick-DE wants to merge 15 commits into
Patrick-DE wants to merge 15 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds configurability for advanced gateway setups by letting users specify extra HTTP headers for custom LLM endpoints, and expands the embedding pipeline to understand Hugging Face TEI /embed endpoints.
Changes:
- Extend LLM config/presets to carry
customHeaders, and merge them into requests for thecustomprovider. - Add TEI
/embedrequest/response handling infetchEmbedding. - Factor header text parsing/formatting into a shared
http-headersutility and reuse it in settings UI.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/stores/wiki-store.ts | Adds customHeaders fields to config/override types for persistence and typing. |
| src/lib/llm-providers.ts | Merges customHeaders into outgoing headers for custom LLM endpoints (Anthropic + OpenAI-compatible modes). |
| src/lib/http-headers.ts | New shared helper to parse/render user-entered header text. |
| src/lib/embedding.ts | Adds TEI /embed detection + request/response shape handling. |
| src/components/settings/sections/llm-provider-section.tsx | Adds a textarea for custom headers on custom LLM presets. |
| src/components/settings/sections/embedding-section.tsx | Refactors embedding header textarea to use the shared helper. |
| src/components/settings/preset-resolver.ts | Wires customHeaders through resolveConfig() for custom presets. |
| src/components/settings/llm-presets.ts | Extends preset type to support customHeaders. |
| package-lock.json | Updates lockfile (includes changes beyond the two described features). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const [testState, setTestState] = useState<ProviderTestState>({ kind: "idle" }) | ||
| const hasConfig = !!apiKey || !!ov.baseUrl || !!ov.model || !!ov.azureApiVersion || !!ov.azureModelFamily | ||
| const [headersText, setHeadersText] = useState<string>(() => headersToText(ov.customHeaders ?? preset.customHeaders ?? {})) | ||
| const hasConfig = !!apiKey || !!ov.baseUrl || !!ov.model || !!ov.azureApiVersion || !!ov.azureModelFamily || !!ov.customHeaders |
Comment on lines
+1
to
+7
| export const RESERVED_HEADER_NAMES = new Set([ | ||
| "authorization", | ||
| "content-type", | ||
| "host", | ||
| "content-length", | ||
| "x-goog-api-key", | ||
| ]) |
Comment on lines
+251
to
+253
| function isTeiEmbeddingConfig(cfg: EmbeddingConfig): boolean { | ||
| return cfg.endpoint.replace(/\/+$/, "").toLowerCase().endsWith("/embed") | ||
| } |
Comment on lines
+151
to
+157
| @@ -151,17 +152,31 @@ export async function fetchEmbedding( | |||
| ? googleEmbeddingBody(cfg.model, current, cfg.outputDimensionality) | |||
| : isDoubaoMultimodal | |||
| ? doubaoMultimodalEmbeddingBody(cfg.model, current) | |||
| : { model: cfg.model, input: current }, | |||
| : isTei | |||
| ? { inputs: current } | |||
| : { model: cfg.model, input: current }, | |||
Comment on lines
934
to
939
| if (mode === "anthropic_messages") { | ||
| const url = buildAnthropicUrl(customEndpoint) | ||
| return { | ||
| url, | ||
| headers: buildAnthropicHeaders(apiKey, url), | ||
| headers: { ...buildAnthropicHeaders(apiKey, url), ...(config.customHeaders ?? {}) }, | ||
| buildBody: (messages, overrides) => { |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
I just added two features so support my usage.
If you like the additions you can merge my pull request.
Changes: