Elffuss BraidHub

kikocis/continue public

71fd2e7d4456 · 1.8 KiBRawPermalink
1import { streamSse } from "@continuedev/fetch";
2import { ChatCompletionChunk, Model } from "openai/resources/index";
3import { InceptionConfig } from "../types.js";
4import { chatChunk, customFetch } from "../util.js";
5import { OpenAIApi } from "./OpenAI.js";
6import { FimCreateParamsStreaming } from "./base.js";
7
8export class InceptionApi extends OpenAIApi {
9 apiBase: string = "https://api.inceptionlabs.ai/v1/";
10 constructor(config: InceptionConfig) {
11 super({
12 ...config,
13 provider: "openai",
14 });
15 }
16
17 async *fimStream(
18 body: FimCreateParamsStreaming,
19 signal: AbortSignal,
20 ): AsyncGenerator<ChatCompletionChunk, any, unknown> {
21 const endpoint = new URL("completions", this.apiBase);
22 const resp = await customFetch(this.config.requestOptions)(endpoint, {
23 method: "POST",
24 body: JSON.stringify({
25 model: body.model,
26 prompt: body.prompt,
27 suffix: body.suffix.trim() === "" ? "<|endoftext|>" : body.suffix,
28 max_tokens: body.max_tokens ?? 150, // Only want this for /fim, not chat
29 temperature: body.temperature,
30 top_p: body.top_p,
31 frequency_penalty: body.frequency_penalty,
32 presence_penalty: body.presence_penalty,
33 stop: [...(body.stop ?? []), "\n\n", "\n \n"],
34 stream: true,
35 }),
36 headers: {
37 "Content-Type": "application/json",
38 Accept: "application/json",
39 Authorization: `Bearer ${this.config.apiKey}`,
40 },
41 signal,
42 });
43 for await (const chunk of streamSse(resp as any)) {
44 if (!chunk.choices[0]) {
45 continue;
46 }
47 yield chatChunk({
48 content: chunk.choices[0].text,
49 finish_reason: null,
50 model: body.model,
51 });
52 }
53 }
54
55 list(): Promise<Model[]> {
56 throw new Error("Method not implemented.");
57 }
58}