diff --git a/core/index.d.ts b/core/index.d.ts index 26471b95a..b279a94a7 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -646,7 +646,8 @@ type ModelProvider = | "nvidia" | "vllm" | "mock" - | "cerebras"; + | "cerebras" + | "askSage"; export type ModelName = diff --git a/core/llm/llms/Asksage.ts b/core/llm/llms/Asksage.ts new file mode 100644 index 000000000..85fb19184 --- /dev/null +++ b/core/llm/llms/Asksage.ts @@ -0,0 +1,168 @@ +import { + ChatMessage, + CompletionOptions, + LLMOptions, + ModelProvider, +} from "../../index.js"; +import { BaseLLM } from "../index.js"; + +class Asksage extends BaseLLM { + static providerName: ModelProvider = "askSage"; + static defaultOptions: Partial = { + apiBase: "https://api.asksage.ai/server/", + model: "gpt-4o", + }; + + private static modelConversion: { [key: string]: string } = { + "gpt-4o": "gpt-4o", + "gpt-4o-mini": "gpt-4o-mini", + "gpt4-gov": "gpt4-gov", + "gpt-4o-gov": "gpt-4o-gov", + "gpt-3.5-turbo": "gpt35-16k", + "mistral-large-latest": "mistral-large", + "llama3-70b": "llma3", + "gemini-1.5-pro-latest": "google-gemini-pro", + "claude-3-5-sonnet-20240620": "claude-35-sonnet", + "claude-3-opus-20240229": "claude-3-opus", + "claude-3-sonnet-20240229": "claude-3-sonnet", + }; + + constructor(options: LLMOptions) { + super(options); + this.apiVersion = options.apiVersion ?? "v1.2.4"; + } + + protected _convertModelName(model: string): string { + return Asksage.modelConversion[model] ?? model; + } + + protected _convertMessage(message: ChatMessage) { + return { + user: message.role === "assistant" ? "gpt" : "me", + message: + typeof message.content === "string" + ? message.content + : message.content.map((part) => part.text).join(""), + }; + } + + protected _convertArgs(options: any, messages: ChatMessage[]) { + let formattedMessage: any; + if (messages.length === 1) { + formattedMessage = messages[0].content; + } else { + formattedMessage = messages.map(this._convertMessage); + } + + const args: any = { + message: formattedMessage, + persona: options.persona ?? "default", + dataset: options.dataset ?? "none", + limit_references: options.limitReferences ?? 0, + temperature: options.temperature ?? 0.0, + live: options.live ?? 0, + model: this._convertModelName(options.model), + system_prompt: options.systemPrompt ?? "You are an expert software developer. You give helpful and concise responses.", + tools: options.tools, + tool_choice: options.toolChoice, + }; + + Object.keys(args).forEach( + (key) => args[key] === undefined && delete args[key] + ); + + return args; + } + + protected _getHeaders() { + const headers: Record = { + "Content-Type": "application/json", + }; + + if (this.apiKey) { + headers["x-access-tokens"] = this.apiKey; + } + + return headers; + } + + protected _getEndpoint(endpoint: string) { + if (!this.apiBase) { + throw new Error( + "No API base URL provided. Please set the 'apiBase' option." + ); + } + + return new URL(endpoint, this.apiBase); + } + + protected async _complete( + prompt: string, + options: CompletionOptions + ): Promise { + if (typeof prompt !== "string" || prompt.trim() === "") { + throw new Error("Prompt must be a non-empty string."); + } + + const messages: ChatMessage[] = [{ role: "user", content: prompt }]; + + const args = this._convertArgs(options, messages); + + const response = await this.fetch(this._getEndpoint("query"), { + method: "POST", + headers: this._getHeaders(), + body: JSON.stringify(args), + }); + + if (!response.ok) { + throw new Error( + `API request failed with status ${response.status}: ${response.statusText}` + ); + } + + const data = await response.json(); + return data.message; + } + + protected async *_streamComplete( + prompt: string, + options: CompletionOptions + ): AsyncGenerator { + const completion = await this._complete(prompt, options); + yield completion; + } + + protected async *_streamChat( + messages: ChatMessage[], + options: CompletionOptions + ): AsyncGenerator { + const args = this._convertArgs(options, messages); + + const response = await this.fetch(this._getEndpoint("query"), { + method: "POST", + headers: this._getHeaders(), + body: JSON.stringify(args), + }); + + if (!response.ok) { + throw new Error( + `API request failed with status ${response.status}: ${response.statusText}` + ); + } + + const data = await response.json(); + + const assistantMessage: ChatMessage = { + role: "assistant", + content: data.message, + }; + + yield assistantMessage; + } + + async listModels(): Promise { + return Object.keys(Asksage.modelConversion); + } +} + +export default Asksage; \ No newline at end of file diff --git a/core/llm/llms/index.ts b/core/llm/llms/index.ts index b504aa900..27e1a31b9 100644 --- a/core/llm/llms/index.ts +++ b/core/llm/llms/index.ts @@ -45,6 +45,7 @@ import Together from "./Together"; import Vllm from "./Vllm"; import WatsonX from "./WatsonX"; import ContinueProxy from "./stubs/ContinueProxy"; +import Asksage from "./Asksage"; const LLMs = [ Anthropic, @@ -85,6 +86,7 @@ const LLMs = [ SambaNova, Mock, Cerebras, + Asksage, ]; export async function llmFromDescription( diff --git a/docs/docs/customize/model-providers/more/asksage.md b/docs/docs/customize/model-providers/more/asksage.md new file mode 100644 index 000000000..c5ba9218c --- /dev/null +++ b/docs/docs/customize/model-providers/more/asksage.md @@ -0,0 +1,61 @@ +# Ask Sage + +:::info + +To get an Ask Sage API key login to the Ask Sage platform (If you don't have an account, you can create one [here](https://chat.asksage.ai/)) and follow the instructions in the Ask Sage Docs:[Ask Sage API Key](https://docs.asksage.ai/docs/api-documentation/api-documentation.html) + +::: + +## Configuration + +To use the Ask Sage models, the following configuration is required to the `config.json` file: + +```json +{ + "models": [ + { + "apiKey": "YOUR_API_KEY", + "apiBase": "https://api.asksage.ai/server/", // apiBase will be the same for all models, but will vary based on tenant. + "model": "gpt4-gov", + "title": "GPT-4 gov", + "provider": "askSage" + } + ] +} +``` + +The `apiBase` will be listed on the Ask Sage platform when you generate an `API key`. You will see context as shown below: + +> Server API for query/training etc.: +> - Documentation: https://app.swaggerhub.com/apis-docs/NICOLASCHAILLAN_1/server_ask-sage_api/1.0 +> - URL for this API is: https://api.asksage.ai/server/ + +## Usage + +Currently, the setup for the models provided by Ask Sage is to support the following two functionalities provided by Continue.Dev: + +- `Chat` to understand and iterate on code in the sidebar +- `Edit` to modify code without leaving your current file + +More models, functionalities and documentation will be added in the future for Ask Sage Integration. + +> We recommend to utilize the`OpenAI` or `Anthropic` models for the best performance and results for the `Chat` and `Edit` functionalities. + +## Current Models From Ask Sage Supported + +The current Models available provided by Ask Sage are: + +| Model | Added | +|--------------------|-------| +| Gov GPT-4.0 | Yes | +| Gov GPT-4o | Yes | +| GPT-4o | Yes | +| GPT-4o-mini | Yes | +| GPT-3.5-16K | Yes | +| Calude 3 Opus | Yes | +| Calude 3 Sonet | Yes | +| Calude 3.5 Sonnet | Yes | +| Gemini Pro | Yes | +| llama 3 | Yes | +| Mistral Large | Yes | + diff --git a/extensions/intellij/src/main/resources/config_schema.json b/extensions/intellij/src/main/resources/config_schema.json index 90a0623a8..0a968f0b4 100644 --- a/extensions/intellij/src/main/resources/config_schema.json +++ b/extensions/intellij/src/main/resources/config_schema.json @@ -198,7 +198,8 @@ "sambanova", "nvidia", "vllm", - "cerebras" + "cerebras", + "askSage" ], "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)", @@ -232,7 +233,8 @@ "### 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)", "### vLLM\nvLLM is a highly performant way of hosting LLMs for a team. To get started, follow their [quickstart](https://docs.vllm.ai/en/latest/getting_started/quickstart.html) to set up your server.", - "### Cerebras\nCerebras Inference uses specialized silicon to provides superfast inference. To get started, get your API keys from [their console](https://cloud.cerebras.ai/)." + "### Cerebras\nCerebras Inference uses specialized silicon to provides superfast inference. To get started, get your API keys from [their console](https://cloud.cerebras.ai/).", + "### Ask Sage\nAsk Sage is an agnostic hosted service that provides language models. To get started with Ask Sage:\n1. Obtain an API key from your account. For more information, visit [Ask Sage](https://docs.asksage.ai/).\n2. Paste the API key below.\n3. Select a model preset.\n> [Reference](https://docs.asksage.ai/)" ], "type": "string" }, @@ -1521,6 +1523,41 @@ } } } + }, + { + "if": { + "properties": { + "provider": { + "enum": ["ask-sage"] + } + }, + "required": ["provider"] + }, + "then": { + "properties": { + "model": { + "anyOf": [ + { + "enum": [ + "gpt-4o", + "gpt-4o-mini", + "gpt-4gov", + "gpt-4ogov", + "claude-3.5-sonnet", + "claude-3-opus", + "mistral-large", + "llama-3-chat", + "gemini-pro", + "AUTODETECT" + ] + }, + { + "type": "string" + } + ] + } + } + } } ] }, diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 470cae9bc..945d0277f 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -198,7 +198,8 @@ "sambanova", "nvidia", "vllm", - "cerebras" + "cerebras", + "askSage" ], "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)", @@ -232,7 +233,8 @@ "### 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)", "### vLLM\nvLLM is a highly performant way of hosting LLMs for a team. To get started, follow their [quickstart](https://docs.vllm.ai/en/latest/getting_started/quickstart.html) to set up your server.", - "### Cerebras\nCerebras Inference uses specialized silicon to provides superfast inference. To get started, get your API keys from [their console](https://cloud.cerebras.ai/)." + "### Cerebras\nCerebras Inference uses specialized silicon to provides superfast inference. To get started, get your API keys from [their console](https://cloud.cerebras.ai/).", + "### Ask Sage\nAsk Sage is an agnostic hosted service that provides language models. To get started with Ask Sage:\n1. Obtain an API key from your account. For more information, visit [Ask Sage](https://docs.asksage.ai/).\n2. Paste the API key below.\n3. Select a model preset.\n> [Reference](https://docs.asksage.ai/)" ], "type": "string" }, @@ -1521,6 +1523,41 @@ } } } + }, + { + "if": { + "properties": { + "provider": { + "enum": ["ask-sage"] + } + }, + "required": ["provider"] + }, + "then": { + "properties": { + "model": { + "anyOf": [ + { + "enum": [ + "gpt-4o", + "gpt-4o-mini", + "gpt-4gov", + "gpt-4ogov", + "claude-3.5-sonnet", + "claude-3-opus", + "mistral-large", + "llama-3-chat", + "gemini-pro", + "AUTODETECT" + ] + }, + { + "type": "string" + } + ] + } + } + } } ] }, diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index ed4f2f0d9..15333eeb3 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -201,7 +201,8 @@ "sambanova", "nvidia", "vllm", - "cerebras" + "cerebras", + "askSage" ], "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)", @@ -235,7 +236,8 @@ "### 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)", "### vLLM\nvLLM is a highly performant way of hosting LLMs for a team. To get started, follow their [quickstart](https://docs.vllm.ai/en/latest/getting_started/quickstart.html) to set up your server.", - "### Cerebras\nCerebras Inference uses specialized silicon to provides superfast inference. To get started, get your API keys from [their console](https://cloud.cerebras.ai/)." + "### Cerebras\nCerebras Inference uses specialized silicon to provides superfast inference. To get started, get your API keys from [their console](https://cloud.cerebras.ai/).", + "### Ask Sage\nAsk Sage is an agnostic hosted service that provides language models. To get started with Ask Sage:\n1. Obtain an API key from your account. For more information, visit [Ask Sage](https://docs.asksage.ai/).\n2. Paste the API key below.\n3. Select a model preset.\n> [Reference](https://docs.asksage.ai/)" ], "type": "string" }, @@ -1706,6 +1708,45 @@ } } } + }, + { + "if": { + "properties": { + "provider": { + "enum": [ + "ask-sage" + ] + } + }, + "required": [ + "provider" + ] + }, + "then": { + "properties": { + "model": { + "anyOf": [ + { + "enum": [ + "gpt-4o", + "gpt-4o-mini", + "gpt-4gov", + "gpt-4ogov", + "claude-3.5-sonnet", + "claude-3-opus", + "mistral-large", + "llama-3-chat", + "gemini-pro", + "AUTODETECT" + ] + }, + { + "type": "string" + } + ] + } + } + } } ] }, diff --git a/gui/public/logos/ask-sage.png b/gui/public/logos/ask-sage.png new file mode 100644 index 000000000..6700221ba Binary files /dev/null and b/gui/public/logos/ask-sage.png differ diff --git a/gui/src/pages/AddNewModel/configs/models.ts b/gui/src/pages/AddNewModel/configs/models.ts index 1540d8007..64d489d2b 100644 --- a/gui/src/pages/AddNewModel/configs/models.ts +++ b/gui/src/pages/AddNewModel/configs/models.ts @@ -311,7 +311,7 @@ export const models: { [key: string]: ModelPackage } = { contextLength: 8192, }, icon: "meta.png", - providerOptions: ["groq"], + providerOptions: ["groq", "askSage"], isOpenSource: false, }, llama318bChat: { @@ -618,7 +618,7 @@ export const models: { [key: string]: ModelPackage } = { contextLength: 32000, }, icon: "mistral.png", - providerOptions: ["mistral"], + providerOptions: ["mistral", "askSage"], isOpenSource: false, }, geminiPro: { @@ -644,7 +644,7 @@ export const models: { [key: string]: ModelPackage } = { apiKey: "", }, icon: "gemini.png", - providerOptions: ["gemini", "free-trial"], + providerOptions: ["gemini", "free-trial", "askSage"], isOpenSource: false, }, gemini15Flash: { @@ -713,7 +713,7 @@ export const models: { [key: string]: ModelPackage } = { systemMessage: "You are an expert software developer. You give helpful and concise responses.", }, - providerOptions: ["openai", "free-trial"], + providerOptions: ["openai", "free-trial", "askSage"], icon: "openai.png", isOpenSource: false, }, @@ -728,7 +728,7 @@ export const models: { [key: string]: ModelPackage } = { systemMessage: "You are an expert software developer. You give helpful and concise responses.", }, - providerOptions: ["openai"], + providerOptions: ["openai", "askSage"], icon: "openai.png", isOpenSource: false, }, @@ -741,7 +741,7 @@ export const models: { [key: string]: ModelPackage } = { contextLength: 8096, title: "GPT-3.5-Turbo", }, - providerOptions: ["openai", "free-trial"], + providerOptions: ["openai", "free-trial", "askSage"], icon: "openai.png", isOpenSource: false, }, @@ -755,7 +755,7 @@ export const models: { [key: string]: ModelPackage } = { title: "Claude 3.5 Sonnet", apiKey: "", }, - providerOptions: ["anthropic", "free-trial"], + providerOptions: ["anthropic", "free-trial", "askSage"], icon: "anthropic.png", isOpenSource: false, }, @@ -769,7 +769,7 @@ export const models: { [key: string]: ModelPackage } = { title: "Claude 3 Opus", apiKey: "", }, - providerOptions: ["anthropic"], + providerOptions: ["anthropic", "askSage"], icon: "anthropic.png", isOpenSource: false, }, @@ -783,7 +783,7 @@ export const models: { [key: string]: ModelPackage } = { title: "Claude 3 Sonnet", apiKey: "", }, - providerOptions: ["anthropic", "free-trial"], + providerOptions: ["anthropic", "free-trial", "askSage"], icon: "anthropic.png", isOpenSource: false, }, @@ -908,6 +908,36 @@ export const models: { [key: string]: ModelPackage } = { providerOptions: ["watsonx"], isOpenSource: false, }, + gpt4gov: { + title: "GPT-4 gov", + description: + "U.S. Government. Most capable model today - which is similar to GPT-4o but approved for use by the U.S. Government.", + params: { + model: "gpt4-gov", + contextLength: 128_000, + title: "GPT-4 gov", + systemMessage: + "You are an expert software developer. You give helpful and concise responses.", // Need to set this on the Ask Sage side or just configure it in here to be discussed + }, + providerOptions: ["askSage"], + icon: "openai.png", + isOpenSource: false, + }, + gpt4ogov: { + title: "GPT-4o gov", + description: + "U.S. Government. Most capable model today - which is similar to GPT-4o but approved for use by the U.S. Government.", + params: { + model: "gpt-4o-gov", + contextLength: 128_000, + title: "GPT-4o", + systemMessage: + "You are an expert software developer. You give helpful and concise responses.", // Need to set this on the Ask Sage side or just configure it in here to be discussed + }, + providerOptions: ["askSage"], + icon: "openai.png", + isOpenSource: false, + }, AUTODETECT: { title: "Autodetect", description: diff --git a/gui/src/pages/AddNewModel/configs/providers.ts b/gui/src/pages/AddNewModel/configs/providers.ts index eef820edf..11f27395e 100644 --- a/gui/src/pages/AddNewModel/configs/providers.ts +++ b/gui/src/pages/AddNewModel/configs/providers.ts @@ -622,4 +622,48 @@ To get started, [register](https://dataplatform.cloud.ibm.com/registration/stepo ], apiKeyUrl: "https://cloud.cerebras.ai/", }, + askSage: { + title: "Ask Sage", + provider: "askSage", + icon: "ask-Sage.png", + description: + "The Ask Sage API provides seamless access to LLMs including OpenAI, Anthropic, Meta, Mistral, and more.", + longDescription: `To get access to the Ask Sage API, obtain your API key from the [Ask Sage platform](https://chat.asksage.ai/) for all other models.`, + tags: [ModelProviderTags.RequiresApiKey], + params: { + apiKey: "", + apiBase: "https://api.asksage.ai/server/", // Default base URL + }, + collectInputFor: [ + { + inputType: "text", + key: "apiKey", + label: "API Key", + placeholder: "Enter your Ask Sage API key", + required: true, + }, + { + inputType: "text", + key: "apiBase", + label: "API Base URL", + placeholder: "Enter the API Base URL", + required: true, + }, + ...completionParamsInputsConfigs, + ], + packages: [ + models.gpt4gov, + models.gpt4ogov, + models.gpt4o, + models.gpt4omini, + models.gpt35turbo, + models.claude35Sonnet, + models.claude3Opus, + models.claude3Sonnet, + models.mistralLarge, + models.llama370bChat, + models.gemini15Pro, + ], + apiKeyUrl: "https://chat.asksage.ai/", + }, };