| 1 | import { streamSse } from "@continuedev/fetch"; |
| 2 | import { CompletionOptions, LLMOptions } from "../../index.js"; |
| 3 | |
| 4 | import OpenAI from "./OpenAI.js"; |
| 5 | |
| 6 | /** |
| 7 | * Inception Labs provider |
| 8 | * |
| 9 | * Integrates with Inception Labs' OpenAI-compatible API endpoints. |
| 10 | * Provides access to Mercury models for autocomplete and other tasks. |
| 11 | * |
| 12 | * Different models use different API endpoints: |
| 13 | * - mercury-editor-mini-experimental: zaragoza.api.inceptionlabs.ai |
| 14 | * - mercury-editor-small-experimental: copenhagen.api.inceptionlabs.ai |
| 15 | * |
| 16 | * More information at: https://docs.inceptionlabs.ai/ |
| 17 | */ |
| 18 | class Inception extends OpenAI { |
| 19 | static providerName = "inception"; |
| 20 | static defaultOptions: Partial<LLMOptions> = { |
| 21 | apiBase: "https://api.inceptionlabs.ai/v1/", |
| 22 | model: "mercury-coder-small", |
| 23 | completionOptions: { |
| 24 | temperature: 0.0, |
| 25 | presencePenalty: 1.5, |
| 26 | stop: ["<|endoftext|>"], |
| 27 | model: "mercury-editor-small-experimental", // Added model to fix TypeScript error |
| 28 | }, |
| 29 | }; |
| 30 | |
| 31 | supportsFim(): boolean { |
| 32 | return true; |
| 33 | } |
| 34 | |
| 35 | async *_streamFim( |
| 36 | prefix: string, |
| 37 | suffix: string, |
| 38 | signal: AbortSignal, |
| 39 | options: CompletionOptions, |
| 40 | ): AsyncGenerator<string> { |
| 41 | const endpoint = new URL("completions", this.apiBase); |
| 42 | const resp = await this.fetch(endpoint, { |
| 43 | method: "POST", |
| 44 | body: JSON.stringify({ |
| 45 | model: options.model, |
| 46 | prompt: prefix, |
| 47 | suffix: suffix.trim() === "" ? "<|endoftext|>" : suffix, |
| 48 | max_tokens: options.maxTokens ?? 150, // Only want this for /fim, not chat |
| 49 | temperature: options.temperature, |
| 50 | top_p: options.topP, |
| 51 | frequency_penalty: options.frequencyPenalty, |
| 52 | presence_penalty: options.presencePenalty, |
| 53 | stop: [...(options.stop ?? []), "\n\n", "\n \n"], |
| 54 | stream: true, |
| 55 | }), |
| 56 | headers: { |
| 57 | "Content-Type": "application/json", |
| 58 | Accept: "application/json", |
| 59 | Authorization: `Bearer ${this.apiKey}`, |
| 60 | }, |
| 61 | signal, |
| 62 | }); |
| 63 | for await (const chunk of streamSse(resp)) { |
| 64 | if (!chunk.choices[0]) { |
| 65 | continue; |
| 66 | } |
| 67 | yield chunk.choices[0].text; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | export default Inception; |