diff --git a/core/config/types.ts b/core/config/types.ts index ef0a14ed5..8fc855779 100644 --- a/core/config/types.ts +++ b/core/config/types.ts @@ -301,6 +301,7 @@ declare global { | "phind" | "anthropic" | "chatml" + | "none" | "deepseek"; type ModelProvider = diff --git a/core/index.d.ts b/core/index.d.ts index d0863cbfd..3b81aef68 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -299,6 +299,7 @@ type TemplateType = | "phind" | "anthropic" | "chatml" + | "none" | "deepseek"; type ModelProvider = diff --git a/core/llm/index.ts b/core/llm/index.ts index adfcd2e68..41d180d11 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -92,6 +92,7 @@ function autodetectTemplateFunction( anthropic: anthropicTemplateMessages, chatml: chatmlTemplateMessages, deepseek: deepseekTemplateMessages, + none: null, }; return mapping[templateType]; @@ -262,9 +263,9 @@ export abstract class BaseLLM implements ILLM { .join("\n"); return `Settings: ${settings} - + ############################################ - + ${prompt}`; } diff --git a/core/llm/llms/OpenAI.ts b/core/llm/llms/OpenAI.ts index 3f682728b..4599121f0 100644 --- a/core/llm/llms/OpenAI.ts +++ b/core/llm/llms/OpenAI.ts @@ -46,6 +46,13 @@ class OpenAI extends BaseLLM { return completion; } + private _getCompletionUrl() { + if (this.apiType === "azure") { + return `${this.apiBase}/openai/deployments/${this.engine}/completions?api-version=${this.apiVersion}`; + } else { + return this.apiBase + "/v1/completions"; + } + } protected async *_streamComplete( prompt: string, @@ -59,6 +66,39 @@ class OpenAI extends BaseLLM { } } + protected async *_legacystreamComplete( + prompt: string, + options: CompletionOptions + ): AsyncGenerator { + const response = await this.fetch(this._getCompletionUrl(), { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${this.apiKey}`, + "api-key": this.apiKey || "", // For Azure + }, + body: JSON.stringify({ + ...{ + prompt, + model: options.model, + max_tokens: options.maxTokens, + temperature: options.temperature, + top_p: options.topP, + frequency_penalty: options.frequencyPenalty, + presence_penalty: options.presencePenalty, + stop: options.stop, + }, + stream: true, + }), + }); + + for await (const value of streamSse(response)) { + if (value.choices?.[0]?.text) { + yield value.choices[0].text; + } + } + } + private _getChatUrl() { if (this.apiType === "azure") { return `${this.apiBase}/openai/deployments/${this.engine}/chat/completions?api-version=${this.apiVersion}`; diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index f42ac71af..295279ade 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -135,7 +135,7 @@ }, "template": { "title": "Template", - "description": "The chat template used to format messages. This is auto-detected for most models, but can be overridden here.", + "description": "The chat template used to format messages. This is auto-detected for most models, but can be overridden here. Choose none if you are using vLLM or another server that automatically handles prompting.", "enum": [ "llama2", "alpaca", @@ -143,6 +143,7 @@ "phind", "anthropic", "chatml", + "none", "deepseek" ], "type": "string"