continuedev / continue

⏩ Continue is the leading open-source AI code assistant. You can connect any models and any context to build custom autocomplete and chat experiences inside VS Code and JetBrains
https://docs.continue.dev/
Apache License 2.0
19.25k stars 1.66k forks source link

feat: add API key support for TEI reranker #2804

Closed cblh closed 1 week ago

cblh commented 1 week ago

fixes: #2741

Description

This change adds API key support for the TEI reranker. Here are the key changes:

  1. In the reranker implementation:

    export class HuggingFaceTEIReranker implements Reranker {
    // ... existing code ...
    
    // Add apiKey to params
    constructor(
    private params: {
      apiBase?: string;
      truncate?: boolean;
      truncation_direction?: string;
      apiKey?: string;  // New parameter
    },
    ) {}
    
    async rerank(query: string, documents: Document[]): Promise<Document[]> {
    // ... existing code ...
    
    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,  // Updated headers object
      // ... rest of existing code ...
    });
    // ... existing code ...
    }
    }
  2. The schema files and documentation have been updated to include the new apiKey parameter in the configuration options for the TEI reranker.

Checklist

Screenshots

[ For visual changes, include screenshots. ]

Testing

The changes allow users to authenticate with the TEI API by providing an API key in their configuration. The key is sent in the Authorization header using Bearer token authentication.