From 3c7821630aa9cd4fd6101cdb632c4f8aafd6fc14 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 19 Dec 2023 01:21:19 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Mistral=20LLM=20Provider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config/types.ts | 40 ++++++++++--- core/index.d.ts | 6 +- extensions/vscode/config_schema.json | 20 ++++++- gui/src/util/modelData.ts | 87 +++++++++++++++++++++++++++- 4 files changed, 142 insertions(+), 11 deletions(-) diff --git a/core/config/types.ts b/core/config/types.ts index 5cc1d9844..3b69d212c 100644 --- a/core/config/types.ts +++ b/core/config/types.ts @@ -24,6 +24,8 @@ declare global { region?: string; projectId?: string; + _fetch?: (input: any, init?: RequestInit) => Promise; + complete(prompt: string, options?: LLMFullCompletionOptions): Promise; streamComplete( @@ -36,6 +38,11 @@ declare global { options?: LLMFullCompletionOptions ): AsyncGenerator; + chat( + messages: ChatMessage[], + options?: LLMFullCompletionOptions + ): Promise; + countTokens(text: string): number; } @@ -123,6 +130,14 @@ declare global { } export interface ContextItem { + content: string; + name: string; + description: string; + editing?: boolean; + editable?: boolean; + } + + export interface ContextItemWithId { content: string; name: string; description: string; @@ -133,7 +148,7 @@ declare global { export interface ChatHistoryItem { message: ChatMessage; - contextItems: ContextItem[]; + contextItems: ContextItemWithId[]; promptLogs?: [string, string][]; // [prompt, completion] } @@ -193,11 +208,13 @@ declare global { options?: LLMOptions; streamCompletion?: ( prompt: string, - options: CompletionOptions + options: CompletionOptions, + fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise ) => AsyncGenerator; streamChat?: ( messages: ChatMessage[], - options: CompletionOptions + options: CompletionOptions, + fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise ) => AsyncGenerator; } @@ -216,7 +233,7 @@ declare global { getConfigJsUrl(): Promise; getDiff(): Promise; getTerminalContents(): Promise; - listWorkspaceContents(): Promise; + listWorkspaceContents(directory?: string): Promise; getWorkspaceDirs(): Promise; writeFile(path: string, contents: string): Promise; showVirtualFile(title: string, contents: string): Promise; @@ -230,6 +247,7 @@ declare global { newContents: string, stepIndex: number ): Promise; + getOpenFiles(): Promise; } // Slash Commands @@ -237,11 +255,11 @@ declare global { export interface ContinueSDK { ide: IDE; llm: ILLM; - addContextItem: (item: ContextItem) => void; + addContextItem: (item: ContextItemWithId) => void; history: ChatMessage[]; input: string; params?: any; - contextItems: ContextItem[]; + contextItems: ContextItemWithId[]; } export interface SlashCommand { @@ -273,7 +291,8 @@ declare global { | "google" | "search" | "url" - | "tree"; + | "tree" + | "http"; type TemplateType = | "llama2" @@ -331,7 +350,11 @@ declare global { // Google PaLM | "chat-bison-001" // Gemini - | "gemini-pro"; + | "gemini-pro" + // Mistral + | "mistral-tiny" + | "mistral-small" + | "mistral-medium"; export interface RequestOptions { timeout?: number; @@ -458,6 +481,7 @@ declare global { disableIndexing?: boolean; userToken?: string; } + } export {}; diff --git a/core/index.d.ts b/core/index.d.ts index f55d1bce4..17d9fcc54 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -348,7 +348,11 @@ export type ModelName = // Google PaLM | "chat-bison-001" // Gemini - | "gemini-pro"; + | "gemini-pro" + // Mistral + | "mistral-tiny" + | "mistral-small" + | "mistral-medium"; export interface RequestOptions { timeout?: number; diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 289601bc8..082bc9fee 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -107,7 +107,8 @@ "text-gen-webui", "google-palm", "lmstudio", - "llamafile" + "llamafile", + "mistral" ], "type": "string" }, @@ -544,6 +545,23 @@ } } }, + { + "if": { + "properties": { + "provider": { + "enum": ["mistral"] + } + }, + "required": ["provider"] + }, + "then": { + "properties": { + "model": { + "enum": ["mistral-tiny", "mistral-small", "mistral-medium"] + } + } + } + }, { "if": { "properties": { diff --git a/gui/src/util/modelData.ts b/gui/src/util/modelData.ts index 3e9594a20..9829a2cf7 100644 --- a/gui/src/util/modelData.ts +++ b/gui/src/util/modelData.ts @@ -283,7 +283,7 @@ const mistral: ModelPackage = { params: { title: "Mistral", model: "mistral-7b", - contextLength: 2048, + contextLength: 4096, }, dimensions: [ { @@ -305,6 +305,62 @@ const mistral: ModelPackage = { providerOptions: ["ollama", "lmstudio", "together", "llamacpp", "replicate"], }; +const mistralTiny: ModelPackage = { + title: "Mistral Tiny (7b)", + description: "An 7b parameter model created by Mistral AI", + params: { + title: "Mistral", + model: "mistral-tiny", + contextLength: 4096, + }, + icon: "mistral.png", + providerOptions: [ + "ollama", + "lmstudio", + "together", + "llamacpp", + "replicate", + "mistral", + ], +}; +const mistralSmall: ModelPackage = { + title: "Mixtral (8x7b)", + description: + "An 8x7b parameter Mixture of Experts model created by Mistral AI (a.k.a Mistral Small)", + params: { + title: "Mixtral", + model: "mistral-small", + contextLength: 4096, + }, + icon: "mistral.png", + providerOptions: [ + "ollama", + "lmstudio", + "together", + "llamacpp", + "replicate", + "mistral", + ], +}; +const mistralMedium: ModelPackage = { + title: "Mistral Medium", + description: "A highly capable model created by Mistral AI", + params: { + title: "Mistral Medium", + model: "mistral-medium", + contextLength: 4096, + }, + icon: "mistral.png", + providerOptions: [ + "ollama", + "lmstudio", + "together", + "llamacpp", + "replicate", + "mistral", + ], +}; + const gemini: ModelPackage = { title: "Gemini Pro", description: "A highly capable model created by Google DeepMind", @@ -520,6 +576,35 @@ export const PROVIDER_INFO: { [key: string]: ModelInfo } = { { ...apiBaseInput, defaultValue: "http://localhost:11434" }, ], }, + mistral: { + title: "Mistral API", + provider: "mistral", + description: + "The Mistral API provides hosted access to their models, including Mistral-7b, Mixtral, and the very capable mistral-medium", + icon: "mistral.png", + longDescription: `To get access to the Mistral API, obtain your API key from the [Mistral platform](https://docs.mistral.ai/)`, + tags: [ + ModelProviderTag["Requires API Key"], + ModelProviderTag["Open-Source"], + ], + params: { + apiKey: "", + }, + collectInputFor: [ + { + inputType: CollectInputType.text, + key: "apiKey", + label: "API Key", + placeholder: "Enter your Mistral API key", + required: true, + }, + ...completionParamsInputs, + ], + packages: [mistralTiny, mistralSmall, mistralMedium].map((p) => { + p.params.contextLength = 4096; + return p; + }), + }, llamafile: { title: "llamafile", provider: "llamafile",