Merge pull request #2804 from cblh/feat/tei-reranker-api-key

feat: add API key support for TEI reranker
This commit is contained in:
Nate Sesti 2024-11-05 18:36:17 -08:00 • committed by GitHub
commit dc65e0850f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 1 deletions

View file

@ -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<string, string> = {
"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,

View file

@ -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": "<TEI_API_KEY>",
"truncate": true,
"truncation_direction": "Right"
}

View file

@ -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.",