Merge branch 'nate/autodetect-models' into preview

This commit is contained in:
Nate Sesti 2024-02-07 22:14:33 -08:00
commit 3587a96f2f
11 changed files with 167 additions and 43 deletions

View file

@ -164,19 +164,56 @@ async function intermediateToFinalConfig(
): Promise<ContinueConfig> {
const models: BaseLLM[] = [];
for (const desc of config.models) {
let llm: BaseLLM | undefined;
if (isModelDescription(desc)) {
llm = await llmFromDescription(
const llm = await llmFromDescription(
desc,
readFile,
config.completionOptions,
config.systemMessage
);
if (!llm) continue;
if (llm.model === "AUTODETECT") {
const modelNames = await llm.listModels();
const detectedModels = await Promise.all(
modelNames.map(async (modelName) => {
return await llmFromDescription(
{
...desc,
model: modelName,
title: llm.title + " - " + modelName,
},
readFile,
config.completionOptions,
config.systemMessage
);
})
);
models.push(
...(detectedModels.filter(
(x) => typeof x !== "undefined"
) as BaseLLM[])
);
} else {
models.push(llm);
}
} else {
llm = new CustomLLMClass(desc);
const llm = new CustomLLMClass(desc);
if (llm.model === "AUTODETECT") {
const modelNames = await llm.listModels();
const models = modelNames.map(
(modelName) =>
new CustomLLMClass({
...desc,
options: { ...desc.options, model: modelName },
})
);
models.push(...models);
} else {
models.push(llm);
}
}
if (!llm) continue;
models.push(llm);
}
let autocompleteLlm: BaseLLM | undefined = undefined;

6
core/index.d.ts vendored
View file

@ -68,6 +68,8 @@ export interface ILLM extends LLMOptions {
countTokens(text: string): number;
supportsImages(): boolean;
listModels(): Promise<string[]>;
}
export type ContextProviderType = "normal" | "query" | "submenu";
@ -264,6 +266,9 @@ export interface CustomLLMWithOptionals {
options: CompletionOptions,
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
) => AsyncGenerator<string>;
listModels?: (
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
) => Promise<string[]>;
}
/**
@ -429,6 +434,7 @@ type ModelProvider =
| "flowise";
export type ModelName =
| "AUTODETECT"
// OpenAI
| "gpt-3.5-turbo"
| "gpt-3.5-turbo-16k"

View file

@ -123,6 +123,10 @@ export abstract class BaseLLM implements ILLM {
this.projectId = options.projectId;
}
listModels(): Promise<string[]> {
return Promise.resolve([]);
}
private _compileChatMessages(
options: CompletionOptions,
messages: ChatMessage[],

View file

@ -87,6 +87,16 @@ class FreeTrial extends BaseLLM {
};
}
}
async listModels(): Promise<string[]> {
return [
"gpt-3.5-turbo",
"gpt-4",
"gemini-pro",
"gpt-4-vision-preview",
"codellama-70b",
];
}
}
export default FreeTrial;

View file

@ -18,6 +18,9 @@ class Ollama extends BaseLLM {
constructor(options: LLMOptions) {
super(options);
if (options.model === "AUTODETECT") {
return;
}
this.fetch(`${this.apiBase}/api/show`, {
method: "POST",
body: JSON.stringify({ name: this._getModel() }),

View file

@ -74,9 +74,12 @@ class OpenAI extends BaseLLM {
return completion;
}
private _getCompletionUrl() {
private _getEndpoint(
endpoint: "/chat/completions" | "/completions" | "/models"
) {
if (this.apiType === "azure") {
return `${this.apiBase}/openai/deployments/${this.engine}/completions?api-version=${this.apiVersion}`;
return `${this.apiBase}/openai/deployments/${this.engine}${endpoint}?api-version=${this.apiVersion}`;
} else {
let url = this.apiBase;
if (!url) {
@ -88,7 +91,7 @@ class OpenAI extends BaseLLM {
url = url.slice(0, -1);
}
return url + "/completions";
return url + endpoint;
}
}
@ -112,7 +115,7 @@ class OpenAI extends BaseLLM {
args.prompt = prompt;
delete args.messages;
const response = await this.fetch(this._getCompletionUrl(), {
const response = await this.fetch(this._getEndpoint("/completions"), {
method: "POST",
headers: {
"Content-Type": "application/json",
@ -132,24 +135,6 @@ class OpenAI extends BaseLLM {
}
}
private _getChatUrl() {
if (this.apiType === "azure") {
return `${this.apiBase}/openai/deployments/${this.engine}/chat/completions?api-version=${this.apiVersion}`;
} else {
let url = this.apiBase;
if (!url) {
throw new Error(
"No API base URL provided. Please set the 'apiBase' option in config.json"
);
}
if (url.endsWith("/")) {
url = url.slice(0, -1);
}
return url + "/chat/completions";
}
}
protected async *_streamChat(
messages: ChatMessage[],
options: CompletionOptions
@ -176,7 +161,7 @@ class OpenAI extends BaseLLM {
...m,
content: m.content === "" ? " " : m.content,
})) as any;
const response = await this.fetch(this._getChatUrl(), {
const response = await this.fetch(this._getEndpoint("/chat/completions"), {
method: "POST",
headers: {
"Content-Type": "application/json",
@ -192,6 +177,19 @@ class OpenAI extends BaseLLM {
}
}
}
async listModels(): Promise<string[]> {
const response = await this.fetch(this._getEndpoint("/models"), {
method: "GET",
headers: {
Authorization: `Bearer ${this.apiKey}`,
"api-key": this.apiKey || "", // For Azure
},
});
const data = await response.json();
return data.data.map((m: any) => m.id);
}
}
export default OpenAI;

View file

@ -335,7 +335,8 @@
"gpt-4",
"gpt-3.5-turbo-0613",
"gpt-4-32k",
"gpt-4-0125-preview"
"gpt-4-0125-preview",
"AUTODETECT"
]
}
}
@ -388,7 +389,8 @@
"phind-codellama-34b",
"gemini-pro",
"gpt-4-vision-preview",
"codellama-70b"
"codellama-70b",
"AUTODETECT"
]
}
}
@ -441,7 +443,8 @@
"deepseek-1b",
"stable-code-3b",
"starcoder-1b",
"starcoder-3b"
"starcoder-3b",
"AUTODETECT"
]
},
{ "type": "string" }
@ -622,7 +625,8 @@
"deepseek-1b",
"stable-code-3b",
"starcoder-1b",
"starcoder-3b"
"starcoder-3b",
"AUTODETECT"
]
},
{ "type": "string" }

View file

@ -1 +1,2 @@
media
media
textmate-syntaxes

View file

@ -335,7 +335,8 @@
"gpt-4",
"gpt-3.5-turbo-0613",
"gpt-4-32k",
"gpt-4-0125-preview"
"gpt-4-0125-preview",
"AUTODETECT"
]
}
}
@ -388,7 +389,8 @@
"phind-codellama-34b",
"gemini-pro",
"gpt-4-vision-preview",
"codellama-70b"
"codellama-70b",
"AUTODETECT"
]
}
}
@ -441,7 +443,8 @@
"deepseek-1b",
"stable-code-3b",
"starcoder-1b",
"starcoder-3b"
"starcoder-3b",
"AUTODETECT"
]
},
{ "type": "string" }
@ -622,7 +625,8 @@
"deepseek-1b",
"stable-code-3b",
"starcoder-1b",
"starcoder-3b"
"starcoder-3b",
"AUTODETECT"
]
},
{ "type": "string" }

View file

@ -121,9 +121,10 @@ const StyledListboxOptions = styled(Listbox.Options)`
position: absolute;
bottom: calc(100% - 16px);
max-width: 100%;
max-height: 80vh;
border-radius: ${defaultBorderRadius};
overflow: hidden;
overflow: scroll;
`;
const StyledListboxOption = styled(Listbox.Option)<{ selected: boolean }>`

View file

@ -433,7 +433,7 @@ const deepseek: ModelPackage = {
model: "deepseek-33b",
title: "DeepSeek-33b",
},
}
},
},
],
providerOptions: ["ollama", "lmstudio", "llamacpp"],
@ -552,6 +552,16 @@ const chatBison: ModelPackage = {
icon: "google-palm.png",
};
const AUTODETECT: ModelPackage = {
title: "Autodetect",
description:
"Automatically populate the model list by calling the /models endpoint of the server",
params: {
model: "AUTODETECT",
} as any,
providerOptions: [],
};
export const MODEL_INFO: ModelPackage[] = [
gpt4,
gpt35turbo,
@ -579,7 +589,19 @@ export const PROVIDER_INFO: { [key: string]: ModelInfo } = {
"Use gpt-4, gpt-3.5-turbo, or any other OpenAI model. See [here](https://openai.com/product#made-for-developers) to obtain an API key.",
icon: "openai.png",
tags: [ModelProviderTag["Requires API Key"]],
packages: [gpt4, gpt35turbo, gpt4turbo, gpt4vision],
packages: [
gpt4,
gpt35turbo,
gpt4turbo,
gpt4vision,
{
...AUTODETECT,
params: {
...AUTODETECT.params,
title: "OpenAI",
},
},
],
collectInputFor: [
{
inputType: CollectInputType.text,
@ -636,7 +658,16 @@ export const PROVIDER_INFO: { [key: string]: ModelInfo } = {
'To get started with Ollama, follow these steps:\n1. Download from [ollama.ai](https://ollama.ai/) and open the application\n2. Open a terminal and run `ollama pull <MODEL_NAME>`. Example model names are `codellama:7b-instruct` or `llama2:7b-text`. You can find the full list [here](https://ollama.ai/library).\n3. Make sure that the model name used in step 2 is the same as the one in config.py (e.g. `model="codellama:7b-instruct"`)\n4. Once the model has finished downloading, you can start asking questions through Continue.',
icon: "ollama.png",
tags: [ModelProviderTag["Local"], ModelProviderTag["Open-Source"]],
packages: osModels,
packages: [
{
...AUTODETECT,
params: {
...AUTODETECT.params,
title: "Ollama",
},
},
...osModels,
],
collectInputFor: [
...completionParamsInputs,
{ ...apiBaseInput, defaultValue: "http://localhost:11434" },
@ -724,7 +755,16 @@ export const PROVIDER_INFO: { [key: string]: ModelInfo } = {
params: {
apiBase: "http://localhost:1234/v1",
},
packages: osModels,
packages: [
{
...AUTODETECT,
params: {
...AUTODETECT.params,
title: "LM Studio",
},
},
...osModels,
],
collectInputFor: [...completionParamsInputs],
},
replicate: {
@ -830,7 +870,16 @@ After it's up and running, you can start using Continue.`,
],
icon: "openai.png",
tags: [ModelProviderTag.Local, ModelProviderTag["Open-Source"]],
packages: osModels,
packages: [
{
...AUTODETECT,
params: {
...AUTODETECT.params,
title: "OpenAI",
},
},
...osModels,
],
},
freetrial: {
title: "Continue limited free trial",
@ -849,6 +898,13 @@ After it's up and running, you can start using Continue.`,
{ ...gpt4vision, title: "GPT-4 Vision (trial)" },
{ ...phindCodeLlama, title: "Phind CodeLlama (trial)" },
{ ...gemini, title: "Gemini Pro (trial)" },
{
...AUTODETECT,
params: {
...AUTODETECT.params,
title: "Free Trial",
},
},
],
collectInputFor: [...completionParamsInputs],
},