Skip to content

Custom header for custom Endpoint and HF /embed endpoint - #504

Open
Patrick-DE wants to merge 15 commits into
nashsu:mainfrom
Patrick-DE:main
Open

Custom header for custom Endpoint and HF /embed endpoint#504
Patrick-DE wants to merge 15 commits into
nashsu:mainfrom
Patrick-DE:main

Conversation

@Patrick-DE

Copy link
Copy Markdown

Hi,

I just added two features so support my usage.
If you like the additions you can merge my pull request.

Changes:

  • added support for custom headers in custom LLM endpoints (385fd41)
  • added support for Hugging Face TEI /embed endpoints (cc85b01)

Copilot AI review requested due to automatic review settings June 29, 2026 12:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the custom provider.
  • Add TEI /embed request/response handling in fetchEmbedding.
  • Factor header text parsing/formatting into a shared http-headers utility 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.

Comment thread src/components/settings/sections/llm-provider-section.tsx Outdated
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 thread src/lib/http-headers.ts
Comment on lines +1 to +7
export const RESERVED_HEADER_NAMES = new Set([
"authorization",
"content-type",
"host",
"content-length",
"x-goog-api-key",
])
Comment thread src/lib/embedding.ts Outdated
Comment on lines +251 to +253
function isTeiEmbeddingConfig(cfg: EmbeddingConfig): boolean {
return cfg.endpoint.replace(/\/+$/, "").toLowerCase().endsWith("/embed")
}
Comment thread src/lib/embedding.ts Outdated
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 thread src/lib/llm-providers.ts
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) => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants