From 5dc25b5eb3b1f914d106a18bbb34f7d28e3039f3 Mon Sep 17 00:00:00 2001 From: burlinchen Date: Mon, 4 Nov 2024 16:22:30 +0800 Subject: [PATCH] feat: add API key support for TEI reranker --- core/context/rerankers/tei.ts | 11 ++++++++++- docs/docs/customize/model-types/reranking.md | 1 + extensions/vscode/config_schema.json | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/context/rerankers/tei.ts b/core/context/rerankers/tei.ts index 61f38b98b..2d3f9ab12 100644 --- a/core/context/rerankers/tei.ts +++ b/core/context/rerankers/tei.ts @@ -15,6 +15,7 @@ export class HuggingFaceTEIReranker implements Reranker { apiBase?: string; truncate?: boolean; truncation_direction?: string; + apiKey?: string; }, ) {} @@ -24,9 +25,17 @@ export class HuggingFaceTEIReranker implements Reranker { apiBase += "/"; } + const headers: Record = { + "Content-Type": "application/json", + }; + + if (this.params.apiKey) { + headers["Authorization"] = `Bearer ${this.params.apiKey}`; + } + const resp = await fetch(new URL("rerank", apiBase), { method: "POST", - headers: { "Content-Type": "application/json" }, + headers, body: JSON.stringify({ query: query, return_text: false, diff --git a/docs/docs/customize/model-types/reranking.md b/docs/docs/customize/model-types/reranking.md index 4aceade4a..a87918cb2 100644 --- a/docs/docs/customize/model-types/reranking.md +++ b/docs/docs/customize/model-types/reranking.md @@ -72,6 +72,7 @@ The `"modelTitle"` field must match one of the models in your "models" array in "name": "huggingface-tei", "params": { "apiBase": "http://localhost:8080", + "apiKey": "", "truncate": true, "truncation_direction": "Right" } diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index c0a734b02..dc9fc66fa 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -2637,6 +2637,9 @@ "type": "string", "default": "http://localhost:8080" }, + "apiKey": { + "type": "string" + }, "truncate": { "type": "boolean", "description": "Whether to truncate long sequences to the maximum allowed context length.",