diff --git a/core/config/types.ts b/core/config/types.ts index 97083bcd5..659907a97 100644 --- a/core/config/types.ts +++ b/core/config/types.ts @@ -489,6 +489,7 @@ declare global { | "flowise" | "groq" | "custom" + | "nvidia" | "msty"; export type ModelName = diff --git a/core/index.d.ts b/core/index.d.ts index ab06f27fd..93b5db918 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -619,7 +619,8 @@ type ModelProvider = | "openai-aiohttp" | "msty" | "watsonx" - | "openrouter"; + | "openrouter" + | "nvidia"; export type ModelName = | "AUTODETECT" diff --git a/core/llm/index.test.ts b/core/llm/index.test.ts index 926b61209..35a287fd5 100644 --- a/core/llm/index.test.ts +++ b/core/llm/index.test.ts @@ -104,6 +104,9 @@ describe("BaseLLM", () => { baseLLM.apiBase = "api.groq.com"; expect(baseLLM.supportsCompletions()).toBe(false); + baseLLM.apiBase = "integrate.api.nvidia.com"; + expect(baseLLM.supportsCompletions()).toBe(false); + baseLLM.apiBase = "api.mistral.ai"; expect(baseLLM.supportsCompletions()).toBe(false); diff --git a/core/llm/index.ts b/core/llm/index.ts index 946ac9c47..b6cbb65b8 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -68,6 +68,7 @@ export abstract class BaseLLM implements ILLM { this.apiBase?.includes("api.groq.com") || this.apiBase?.includes("api.mistral.ai") || this.apiBase?.includes(":1337") || + this.apiBase?.includes("integrate.api.nvidia.com") || this._llmOptions.useLegacyCompletionsEndpoint?.valueOf() === false ) { // Jan + Groq + Mistral don't support completions : ( diff --git a/core/llm/llms/Nvidia.ts b/core/llm/llms/Nvidia.ts new file mode 100644 index 000000000..ccfd1d19e --- /dev/null +++ b/core/llm/llms/Nvidia.ts @@ -0,0 +1,33 @@ +import { LLMOptions, ModelProvider, ChatMessage } from "../../index.js"; +import OpenAI from "./OpenAI.js"; + +class Nvidia extends OpenAI { + // NVIDIA NIMs currently limits the number of stops for Starcoder 2 to 4 + // https://docs.api.nvidia.com/nim/reference/bigcode-starcoder2-7b-infer + protected maxStopWordsStarCoder = 4; + static providerName: ModelProvider = "nvidia"; + static defaultOptions: Partial = { + apiBase: "https://integrate.api.nvidia.com/v1/", + useLegacyCompletionsEndpoint: false, + }; + + protected _convertArgs(options: any, messages: ChatMessage[]) { + const url = new URL(this.apiBase!); + const finalOptions = { + messages: messages.map(this._convertMessage), + model: this._convertModelName(options.model), + max_tokens: options.maxTokens, + temperature: options.temperature, + top_p: options.topP, + frequency_penalty: options.frequencyPenalty, + presence_penalty: options.presencePenalty, + stop: options.model.includes("starcoder2") + ? options.stop?.slice(0, this.maxStopWordsStarCoder) + : options.stop, + }; + + return finalOptions; + } +} + +export default Nvidia; diff --git a/core/llm/llms/index.ts b/core/llm/llms/index.ts index 84c23c9bb..a311b6527 100644 --- a/core/llm/llms/index.ts +++ b/core/llm/llms/index.ts @@ -38,6 +38,7 @@ import TextGenWebUI from "./TextGenWebUI"; import Together from "./Together"; import WatsonX from "./WatsonX"; import ContinueProxy from "./stubs/ContinueProxy"; +import Nvidia from "./Nvidia"; const LLMs = [ Anthropic, @@ -70,6 +71,7 @@ const LLMs = [ Azure, WatsonX, OpenRouter, + Nvidia, ]; export async function llmFromDescription( diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index daa0e5f01..0d085493d 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -191,7 +191,8 @@ "azure", "msty", "watsonx", - "openrouter" + "openrouter", + "nvidia" ], "markdownEnumDescriptions": [ "### OpenAI\nUse 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.\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/openai)", @@ -219,7 +220,8 @@ "### Azure OpenAI\n Azure OpenAI lets you securely run OpenAI's models on Azure. To get started, follow the steps [here](https://docs.continue.dev/reference/Model%20Providers/azure)", "### Msty\nMsty is the simplest way to get started with online or local LLMs on all desktop platforms - Windows, Mac, and Linux. No fussing around, one-click and you are up and running. To get started, follow these steps:\n1. Download from [Msty.app](https://msty.app/), open the application, and click 'Setup Local AI'.\n2. Go to the Local AI Module page and download a model of your choice.\n3. Once the model has finished downloading, you can start asking questions through Continue.\n> [Reference](https://continue.dev/docs/reference/Model%20Providers/Msty)", "### IBM watsonx\nwatsonx, developed by IBM, offers a variety of pre-trained AI foundation models that can be used for natural language processing (NLP), computer vision, and speech recognition tasks.", - "### OpenRouter\nOpenRouter offers a single API to access almost any language model. To get started, obtain an API key from [their console](https://openrouter.ai/settings/keys)." + "### OpenRouter\nOpenRouter offers a single API to access almost any language model. To get started, obtain an API key from [their console](https://openrouter.ai/settings/keys).", + "### NVIDIA NIMs\nNVIDIA offers a single API to access almost any language model. To find out more, visit the [LLM APIs Documentation](https://docs.api.nvidia.com/nim/reference/llm-apis).\nFor information specific to getting a key, please check out the [docs here](https://docs.nvidia.com/nim/large-language-models/latest/getting-started.html#option-1-from-api-catalog)" ], "type": "string" }, diff --git a/extensions/intellij/src/main/resources/config_schema.json b/extensions/intellij/src/main/resources/config_schema.json index daa0e5f01..109004403 100644 --- a/extensions/intellij/src/main/resources/config_schema.json +++ b/extensions/intellij/src/main/resources/config_schema.json @@ -191,7 +191,8 @@ "azure", "msty", "watsonx", - "openrouter" + "openrouter", + "nvidia" ], "markdownEnumDescriptions": [ "### OpenAI\nUse 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.\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/openai)", @@ -219,8 +220,8 @@ "### Azure OpenAI\n Azure OpenAI lets you securely run OpenAI's models on Azure. To get started, follow the steps [here](https://docs.continue.dev/reference/Model%20Providers/azure)", "### Msty\nMsty is the simplest way to get started with online or local LLMs on all desktop platforms - Windows, Mac, and Linux. No fussing around, one-click and you are up and running. To get started, follow these steps:\n1. Download from [Msty.app](https://msty.app/), open the application, and click 'Setup Local AI'.\n2. Go to the Local AI Module page and download a model of your choice.\n3. Once the model has finished downloading, you can start asking questions through Continue.\n> [Reference](https://continue.dev/docs/reference/Model%20Providers/Msty)", "### IBM watsonx\nwatsonx, developed by IBM, offers a variety of pre-trained AI foundation models that can be used for natural language processing (NLP), computer vision, and speech recognition tasks.", - "### OpenRouter\nOpenRouter offers a single API to access almost any language model. To get started, obtain an API key from [their console](https://openrouter.ai/settings/keys)." - ], + "### OpenRouter\nOpenRouter offers a single API to access almost any language model. To get started, obtain an API key from [their console](https://openrouter.ai/settings/keys).", + "### NVIDIA NIMs\nNVIDIA offers a single API to access almost any language model. To find out more, visit the [LLM APIs Documentation](https://docs.api.nvidia.com/nim/reference/llm-apis).\nFor information specific to getting a key, please check out the [docs here](https://docs.nvidia.com/nim/large-language-models/latest/getting-started.html#option-1-from-api-catalog)" ], "type": "string" }, "model": { diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index daa0e5f01..109004403 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -191,7 +191,8 @@ "azure", "msty", "watsonx", - "openrouter" + "openrouter", + "nvidia" ], "markdownEnumDescriptions": [ "### OpenAI\nUse 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.\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/openai)", @@ -219,8 +220,8 @@ "### Azure OpenAI\n Azure OpenAI lets you securely run OpenAI's models on Azure. To get started, follow the steps [here](https://docs.continue.dev/reference/Model%20Providers/azure)", "### Msty\nMsty is the simplest way to get started with online or local LLMs on all desktop platforms - Windows, Mac, and Linux. No fussing around, one-click and you are up and running. To get started, follow these steps:\n1. Download from [Msty.app](https://msty.app/), open the application, and click 'Setup Local AI'.\n2. Go to the Local AI Module page and download a model of your choice.\n3. Once the model has finished downloading, you can start asking questions through Continue.\n> [Reference](https://continue.dev/docs/reference/Model%20Providers/Msty)", "### IBM watsonx\nwatsonx, developed by IBM, offers a variety of pre-trained AI foundation models that can be used for natural language processing (NLP), computer vision, and speech recognition tasks.", - "### OpenRouter\nOpenRouter offers a single API to access almost any language model. To get started, obtain an API key from [their console](https://openrouter.ai/settings/keys)." - ], + "### OpenRouter\nOpenRouter offers a single API to access almost any language model. To get started, obtain an API key from [their console](https://openrouter.ai/settings/keys).", + "### NVIDIA NIMs\nNVIDIA offers a single API to access almost any language model. To find out more, visit the [LLM APIs Documentation](https://docs.api.nvidia.com/nim/reference/llm-apis).\nFor information specific to getting a key, please check out the [docs here](https://docs.nvidia.com/nim/large-language-models/latest/getting-started.html#option-1-from-api-catalog)" ], "type": "string" }, "model": { diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index 1a197c512..fd9020723 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -194,7 +194,8 @@ "azure", "msty", "watsonx", - "openrouter" + "openrouter", + "nvidia" ], "markdownEnumDescriptions": [ "### OpenAI\nUse 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.\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/openai)", @@ -222,7 +223,8 @@ "### Azure OpenAI\n Azure OpenAI lets you securely run OpenAI's models on Azure. To get started, follow the steps [here](https://docs.continue.dev/reference/Model%20Providers/azure)", "### Msty\nMsty is the simplest way to get started with online or local LLMs on all desktop platforms - Windows, Mac, and Linux. No fussing around, one-click and you are up and running. To get started, follow these steps:\n1. Download from [Msty.app](https://msty.app/), open the application, and click 'Setup Local AI'.\n2. Go to the Local AI Module page and download a model of your choice.\n3. Once the model has finished downloading, you can start asking questions through Continue.\n> [Reference](https://continue.dev/docs/reference/Model%20Providers/Msty)", "### IBM watsonx\nwatsonx, developed by IBM, offers a variety of pre-trained AI foundation models that can be used for natural language processing (NLP), computer vision, and speech recognition tasks.", - "### OpenRouter\nOpenRouter offers a single API to access almost any language model. To get started, obtain an API key from [their console](https://openrouter.ai/settings/keys)." + "### OpenRouter\nOpenRouter offers a single API to access almost any language model. To get started, obtain an API key from [their console](https://openrouter.ai/settings/keys).", + "### NVIDIA NIMs\nNVIDIA offers a single API to access almost any language model. To find out more, visit the [LLM APIs Documentation](https://docs.api.nvidia.com/nim/reference/llm-apis).\nFor information specific to getting a key, please check out the [docs here](https://docs.nvidia.com/nim/large-language-models/latest/getting-started.html#option-1-from-api-catalog)" ], "type": "string" }, diff --git a/packages/openai-adapters/src/index.ts b/packages/openai-adapters/src/index.ts index 8882ad42a..3a47980bc 100644 --- a/packages/openai-adapters/src/index.ts +++ b/packages/openai-adapters/src/index.ts @@ -53,6 +53,11 @@ export function constructLlmApi(config: LlmApiConfig): BaseLlmApi { ...config, apiBase: "https://api.groq.com/openai/v1/", }); + case "nvidia": + return new OpenAIApi({ + ...config, + apiBase: "https://integrate.api.nvidia.com/v1/", + }); case "fireworks": return new OpenAIApi({ ...config,