From 5f1c3c7e5f2c4267f53f2a2c829211fb24993d8b Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 30 Mar 2025 13:40:46 -0700 Subject: [PATCH] inception provider --- core/llm/llms/Inception.ts | 48 ++++++++++++++++++++++++++++++++++++++ core/llm/llms/index.ts | 2 ++ 2 files changed, 50 insertions(+) create mode 100644 core/llm/llms/Inception.ts diff --git a/core/llm/llms/Inception.ts b/core/llm/llms/Inception.ts new file mode 100644 index 000000000..3d9f992ad --- /dev/null +++ b/core/llm/llms/Inception.ts @@ -0,0 +1,48 @@ +import { CompletionOptions, LLMOptions } from "../../index.js"; +import { streamSse } from "../stream.js"; + +import OpenAI from "./OpenAI.js"; + +class Inception extends OpenAI { + static providerName = "inception"; + static defaultOptions: Partial = {}; + + supportsFim(): boolean { + return true; + } + + async *_streamFim( + prefix: string, + suffix: string, + signal: AbortSignal, + options: CompletionOptions, + ): AsyncGenerator { + const endpoint = new URL("completions", this.apiBase); + const resp = await this.fetch(endpoint, { + method: "POST", + body: JSON.stringify({ + model: options.model, + prompt: prefix, + suffix, + max_tokens: options.maxTokens, + temperature: options.temperature, + top_p: options.topP, + frequency_penalty: options.frequencyPenalty, + presence_penalty: options.presencePenalty, + stop: options.stop, + stream: true, + }), + headers: { + "Content-Type": "application/json", + Accept: "application/json", + Authorization: `Bearer ${this.apiKey}`, + }, + signal, + }); + for await (const chunk of streamSse(resp)) { + yield chunk.choices[0].text; + } + } +} + +export default Inception; diff --git a/core/llm/llms/index.ts b/core/llm/llms/index.ts index e6a33a9a8..5f6657a68 100644 --- a/core/llm/llms/index.ts +++ b/core/llm/llms/index.ts @@ -26,6 +26,7 @@ import Gemini from "./Gemini"; import Groq from "./Groq"; import HuggingFaceInferenceAPI from "./HuggingFaceInferenceAPI"; import HuggingFaceTGI from "./HuggingFaceTGI"; +import Inception from "./Inception"; import Kindo from "./Kindo"; import LlamaCpp from "./LlamaCpp"; import Llamafile from "./Llamafile"; @@ -104,6 +105,7 @@ export const LLMClasses = [ SiliconFlow, Scaleway, Relace, + Inception, ]; export async function llmFromDescription(