| 1 | import { streamSse } from "@continuedev/fetch"; |
| 2 | import { CompletionOptions, LLMOptions } from "../../index.js"; |
| 3 | import { osModelsEditPrompt } from "../templates/edit.js"; |
| 4 | |
| 5 | import OpenAI from "./OpenAI.js"; |
| 6 | |
| 7 | class Deepseek extends OpenAI { |
| 8 | static providerName = "deepseek"; |
| 9 | static defaultOptions: Partial<LLMOptions> = { |
| 10 | apiBase: "https://api.deepseek.com/", |
| 11 | model: "deepseek-coder", |
| 12 | promptTemplates: { |
| 13 | edit: osModelsEditPrompt, |
| 14 | }, |
| 15 | useLegacyCompletionsEndpoint: false, |
| 16 | }; |
| 17 | maxStopWords: number | undefined = 16; |
| 18 | |
| 19 | supportsFim(): boolean { |
| 20 | return true; |
| 21 | } |
| 22 | |
| 23 | async *_streamFim( |
| 24 | prefix: string, |
| 25 | suffix: string, |
| 26 | signal: AbortSignal, |
| 27 | options: CompletionOptions, |
| 28 | ): AsyncGenerator<string> { |
| 29 | const endpoint = new URL("beta/completions", this.apiBase); |
| 30 | const resp = await this.fetch(endpoint, { |
| 31 | method: "POST", |
| 32 | body: JSON.stringify({ |
| 33 | model: options.model, |
| 34 | prompt: prefix, |
| 35 | suffix, |
| 36 | max_tokens: options.maxTokens, |
| 37 | temperature: options.temperature, |
| 38 | top_p: options.topP, |
| 39 | frequency_penalty: options.frequencyPenalty, |
| 40 | presence_penalty: options.presencePenalty, |
| 41 | stop: options.stop, |
| 42 | stream: true, |
| 43 | }), |
| 44 | headers: { |
| 45 | "Content-Type": "application/json", |
| 46 | Accept: "application/json", |
| 47 | Authorization: `Bearer ${this.apiKey}`, |
| 48 | }, |
| 49 | signal, |
| 50 | }); |
| 51 | for await (const chunk of streamSse(resp)) { |
| 52 | yield chunk.choices[0].text; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | export default Deepseek; |