diff --git a/core/config/load.ts b/core/config/load.ts index a26d2c2c6..a55f5e9c7 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -164,19 +164,56 @@ async function intermediateToFinalConfig( ): Promise { 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; diff --git a/core/index.d.ts b/core/index.d.ts index 7d8a1f6d4..1e3a00d94 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -68,6 +68,8 @@ export interface ILLM extends LLMOptions { countTokens(text: string): number; supportsImages(): boolean; + + listModels(): Promise; } export type ContextProviderType = "normal" | "query" | "submenu"; @@ -264,6 +266,9 @@ export interface CustomLLMWithOptionals { options: CompletionOptions, fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise ) => AsyncGenerator; + listModels?: ( + fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise + ) => Promise; } /** @@ -429,6 +434,7 @@ type ModelProvider = | "flowise"; export type ModelName = + | "AUTODETECT" // OpenAI | "gpt-3.5-turbo" | "gpt-3.5-turbo-16k" diff --git a/core/llm/index.ts b/core/llm/index.ts index 0a406d992..b0d40e20b 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -123,6 +123,10 @@ export abstract class BaseLLM implements ILLM { this.projectId = options.projectId; } + listModels(): Promise { + return Promise.resolve([]); + } + private _compileChatMessages( options: CompletionOptions, messages: ChatMessage[], diff --git a/core/llm/llms/FreeTrial.ts b/core/llm/llms/FreeTrial.ts index 13cec060f..c9e1b770e 100644 --- a/core/llm/llms/FreeTrial.ts +++ b/core/llm/llms/FreeTrial.ts @@ -87,6 +87,16 @@ class FreeTrial extends BaseLLM { }; } } + + async listModels(): Promise { + return [ + "gpt-3.5-turbo", + "gpt-4", + "gemini-pro", + "gpt-4-vision-preview", + "codellama-70b", + ]; + } } export default FreeTrial; diff --git a/core/llm/llms/Ollama.ts b/core/llm/llms/Ollama.ts index a4e90026e..225d2c560 100644 --- a/core/llm/llms/Ollama.ts +++ b/core/llm/llms/Ollama.ts @@ -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() }), diff --git a/core/llm/llms/OpenAI.ts b/core/llm/llms/OpenAI.ts index ff2f1f664..248862b53 100644 --- a/core/llm/llms/OpenAI.ts +++ b/core/llm/llms/OpenAI.ts @@ -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 { + 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; diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index fe257170a..b0dc99bca 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -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" } diff --git a/extensions/vscode/.continueignore b/extensions/vscode/.continueignore index 27949aaf3..bdb320509 100644 --- a/extensions/vscode/.continueignore +++ b/extensions/vscode/.continueignore @@ -1 +1,2 @@ -media \ No newline at end of file +media +textmate-syntaxes \ No newline at end of file diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index fe257170a..b0dc99bca 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -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" } diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index 1d164ea6f..25a7adcc7 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -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 }>` diff --git a/gui/src/util/modelData.ts b/gui/src/util/modelData.ts index 71abe678d..f712d8950 100644 --- a/gui/src/util/modelData.ts +++ b/gui/src/util/modelData.ts @@ -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 `. 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], },