🐛 use legacy completions endpoint for autocomplete with OpenAI-compatible providers

This commit is contained in:
Nate Sesti 2024-02-08 11:00:14 -08:00
parent e2abe3b059
commit deab7c5132
7 changed files with 21 additions and 12 deletions

View file

@ -22,6 +22,8 @@ const NON_CHAT_MODELS = [
];
class OpenAI extends BaseLLM {
public useLegacyCompletionsEndpoint = false;
static providerName: ModelProvider = "openai";
static defaultOptions: Partial<LLMOptions> = {
apiBase: "https://api.openai.com/v1",
@ -139,7 +141,10 @@ class OpenAI extends BaseLLM {
messages: ChatMessage[],
options: CompletionOptions
): AsyncGenerator<ChatMessage> {
if (NON_CHAT_MODELS.includes(options.model)) {
if (
NON_CHAT_MODELS.includes(options.model) ||
this.useLegacyCompletionsEndpoint
) {
for await (const content of this._legacystreamComplete(
stripImages(messages[messages.length - 1]?.content || ""),
options

View file

@ -17,7 +17,7 @@
"fastest-levenshtein": "^1.0.16",
"handlebars": "^4.7.8",
"js-tiktoken": "^1.0.8",
"llm-code-highlighter": "^0.0.3",
"llm-code-highlighter": "^0.0.5",
"node-fetch": "^3.3.2",
"node-html-markdown": "^1.3.0",
"ollama": "^0.4.6",
@ -4771,9 +4771,9 @@
"dev": true
},
"node_modules/llm-code-highlighter": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/llm-code-highlighter/-/llm-code-highlighter-0.0.3.tgz",
"integrity": "sha512-l/R+m6ngXRTYxzoCzqpBk5TiSVpS4Ek9fKx/PIy25HV6XDbCC6iOfVITPPSTGkh7NlI+tN5vWjdqUfN3YW+HwQ==",
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/llm-code-highlighter/-/llm-code-highlighter-0.0.5.tgz",
"integrity": "sha512-rzizZgdEXRJhS0p75fwjhtlRYblq8F9zss4cCavZNEliYTFVqt1sEDmCCmjCTGkJp7hK1z77PrzcrT7KXqxhGA==",
"dependencies": {
"graphology": "^0.25.4",
"graphology-metrics": "^2.2.0",

View file

@ -2703,10 +2703,10 @@ lines-and-columns@^1.1.6:
resolved "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz"
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==
llm-code-highlighter@^0.0.3:
version "0.0.3"
resolved "https://registry.npmjs.org/llm-code-highlighter/-/llm-code-highlighter-0.0.3.tgz"
integrity sha512-l/R+m6ngXRTYxzoCzqpBk5TiSVpS4Ek9fKx/PIy25HV6XDbCC6iOfVITPPSTGkh7NlI+tN5vWjdqUfN3YW+HwQ==
llm-code-highlighter@^0.0.5:
version "0.0.5"
resolved "https://registry.npmjs.org/llm-code-highlighter/-/llm-code-highlighter-0.0.5.tgz"
integrity sha512-rzizZgdEXRJhS0p75fwjhtlRYblq8F9zss4cCavZNEliYTFVqt1sEDmCCmjCTGkJp7hK1z77PrzcrT7KXqxhGA==
dependencies:
graphology "^0.25.4"
graphology-metrics "^2.2.0"

View file

@ -92,7 +92,7 @@
"fastest-levenshtein": "^1.0.16",
"handlebars": "^4.7.8",
"js-tiktoken": "^1.0.8",
"llm-code-highlighter": "^0.0.3",
"llm-code-highlighter": "^0.0.5",
"node-fetch": "^3.3.2",
"node-html-markdown": "^1.3.0",
"ollama": "^0.4.6",

View file

@ -13,6 +13,7 @@ import {
import { DEFAULT_AUTOCOMPLETE_OPTS } from "core/autocomplete/parameters";
import { getTemplateForModel } from "core/autocomplete/templates";
import { streamLines } from "core/diff/util";
import OpenAI from "core/llm/llms/OpenAI";
import Handlebars from "handlebars";
import { v4 as uuidv4 } from "uuid";
import * as vscode from "vscode";
@ -253,6 +254,9 @@ async function getTabCompletion(
try {
// Model
const llm = await TabAutocompleteModel.get();
if (llm instanceof OpenAI) {
llm.useLegacyCompletionsEndpoint = true;
}
if (!llm) return;
// Prompt

View file

@ -2304,7 +2304,7 @@ core-util-is@1.0.2:
fastest-levenshtein "^1.0.16"
handlebars "^4.7.8"
js-tiktoken "^1.0.8"
llm-code-highlighter "^0.0.3"
llm-code-highlighter "^0.0.5"
node-fetch "^3.3.2"
node-html-markdown "^1.3.0"
ollama "^0.4.6"

2
gui/package-lock.json generated
View file

@ -81,7 +81,7 @@
"fastest-levenshtein": "^1.0.16",
"handlebars": "^4.7.8",
"js-tiktoken": "^1.0.8",
"llm-code-highlighter": "^0.0.3",
"llm-code-highlighter": "^0.0.5",
"node-fetch": "^3.3.2",
"node-html-markdown": "^1.3.0",
"ollama": "^0.4.6",