diff --git a/core/llm/llms/Mistral.ts b/core/llm/llms/Mistral.ts index d05615db8..fee8fadac 100644 --- a/core/llm/llms/Mistral.ts +++ b/core/llm/llms/Mistral.ts @@ -1,10 +1,4 @@ -import { - ChatMessage, - CompletionOptions, - LLMOptions, - ModelProvider, -} from "../../index.js"; -import { streamSse } from "../stream.js"; +import { ChatMessage, LLMOptions, ModelProvider } from "../../index.js"; import { gptEditPrompt } from "../templates/edit.js"; import OpenAI from "./OpenAI.js"; @@ -47,38 +41,6 @@ class Mistral extends OpenAI { supportsFim(): boolean { return true; } - - async *_streamFim( - prefix: string, - suffix: string, - options: CompletionOptions, - ): AsyncGenerator { - const endpoint = new URL("fim/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", - "x-api-key": this.apiKey ?? "", - Authorization: `Bearer ${this.apiKey}`, - }, - }); - for await (const chunk of streamSse(resp)) { - yield chunk.choices[0].delta.content; - } - } } export default Mistral; diff --git a/core/llm/llms/OpenAI.ts b/core/llm/llms/OpenAI.ts index d05c3315c..08b728f2f 100644 --- a/core/llm/llms/OpenAI.ts +++ b/core/llm/llms/OpenAI.ts @@ -226,6 +226,38 @@ class OpenAI extends BaseLLM { } } + async *_streamFim( + prefix: string, + suffix: string, + options: CompletionOptions, + ): AsyncGenerator { + const endpoint = new URL("fim/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", + "x-api-key": this.apiKey ?? "", + Authorization: `Bearer ${this.apiKey}`, + }, + }); + for await (const chunk of streamSse(resp)) { + yield chunk.choices[0].delta.content; + } + } + async listModels(): Promise { const response = await this.fetch(this._getEndpoint("models"), { method: "GET", diff --git a/core/llm/llms/stubs/ContinueProxy.ts b/core/llm/llms/stubs/ContinueProxy.ts index 8db6b4518..f23ea35cc 100644 --- a/core/llm/llms/stubs/ContinueProxy.ts +++ b/core/llm/llms/stubs/ContinueProxy.ts @@ -6,6 +6,10 @@ class ContinueProxy extends OpenAI { static defaultOptions: Partial = { apiBase: "http://localhost:3000/proxy/v1", }; + + supportsFim(): boolean { + return true; + } } export default ContinueProxy;