Elffuss BraidHub

kikocis/continue public

main · 1.6 KiBRawPermalink
1import { LLMOptions } from "../../index.js";
2
3import OpenAI from "./OpenAI.js";
4
5class FunctionNetwork extends OpenAI {
6 static providerName = "function-network";
7 static defaultOptions: Partial<LLMOptions> = {
8 apiBase: "https://api.function.network/v1/",
9 model: "meta/llama-3.1-70b-instruct",
10 maxEmbeddingBatchSize: 128,
11 };
12
13 private static modelConversion: { [key: string]: string } = {
14 "mistral-7b": "mistral/mistral-7b-instruct-v0.1",
15 "llama3-8b": "meta/llama-3-8b-instruct",
16 "llama3.1-8b": "meta/llama-3.1-8b-instruct",
17 "llama3.1-70b": "meta/llama-3.1-70b-instruct",
18 "deepseek-7b": "thebloke/deepseek-coder-6.7b-instruct-awq",
19 };
20
21 constructor(options: LLMOptions) {
22 super(options);
23 }
24
25 protected _convertModelName(model: string): string {
26 return FunctionNetwork.modelConversion[model] ?? model;
27 }
28
29 public supportsFim(): boolean {
30 return false;
31 }
32
33 public supportsCompletions(): boolean {
34 return false;
35 }
36
37 public supportsPrefill(): boolean {
38 return false;
39 }
40
41 protected async _embed(chunks: string[]): Promise<number[][]> {
42 const resp = await this.fetch(new URL("embeddings", this.apiBase), {
43 method: "POST",
44 body: JSON.stringify({
45 input: chunks,
46 model: this.model,
47 }),
48 headers: {
49 Authorization: `Bearer ${this.apiKey}`,
50 "Content-Type": "application/json",
51 },
52 });
53
54 if (!resp.ok) {
55 throw new Error(await resp.text());
56 }
57
58 const data = (await resp.json()) as any;
59 return data.data.map((result: { embedding: number[] }) => result.embedding);
60 }
61}
62
63export default FunctionNetwork;