Elffuss BraidHub

kikocis/continue public

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