Elffuss BraidHub

kikocis/continue public

main · 1.1 KiBRawPermalink
1import { LLMOptions } from "../../index.js";
2
3import OpenAI from "./OpenAI.js";
4
5class Nvidia extends OpenAI {
6 // NVIDIA NIMs currently limits the number of stops for Starcoder 2 to 4
7 // https://docs.api.nvidia.com/nim/reference/bigcode-starcoder2-7b-infer
8 maxStopWords = 4;
9 static providerName = "nvidia";
10 static defaultOptions: Partial<LLMOptions> = {
11 apiBase: "https://integrate.api.nvidia.com/v1/",
12 useLegacyCompletionsEndpoint: false,
13 maxEmbeddingBatchSize: 96,
14 };
15
16 protected async _embed(chunks: string[]): Promise<number[][]> {
17 const resp = await this.fetch(new URL("embeddings", this.apiBase), {
18 method: "POST",
19 body: JSON.stringify({
20 input: chunks,
21 model: this.model,
22 input_type: "passage",
23 truncate: "END",
24 }),
25 headers: {
26 Authorization: `Bearer ${this.apiKey}`,
27 "Content-Type": "application/json",
28 },
29 });
30
31 if (!resp.ok) {
32 throw new Error(await resp.text());
33 }
34
35 const data = (await resp.json()) as any;
36 return data.data.map((result: { embedding: number[] }) => result.embedding);
37 }
38}
39
40export default Nvidia;