Merge pull request #2706 from mark-espinoza/llm-provider-Ask-Sage

Adding LLM Provider Ask Sage
This commit is contained in:
Nate Sesti 2024-10-29 12:00:27 -07:00 • committed by GitHub
commit 600c8359d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 437 additions and 16 deletions

3
core/index.d.ts vendored
View file

@ -646,7 +646,8 @@ type ModelProvider =
| "nvidia"
| "vllm"
| "mock"
| "cerebras";
| "cerebras"
| "askSage";
export type ModelName =

168
core/llm/llms/Asksage.ts Normal file
View file

@ -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<LLMOptions> = {
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<string, string> = {
"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<string> {
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<string> {
const completion = await this._complete(prompt, options);
yield completion;
}
protected async *_streamChat(
messages: ChatMessage[],
options: CompletionOptions
): AsyncGenerator<ChatMessage> {
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<string[]> {
return Object.keys(Asksage.modelConversion);
}
}
export default Asksage;

View file

@ -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(

View file

@ -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 |

View file

@ -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"
}
]
}
}
}
}
]
},

View file

@ -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"
}
]
}
}
}
}
]
},

View file

@ -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"
}
]
}
}
}
}
]
},

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

View file

@ -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: "<API_KEY>",
},
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:

View file

@ -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/",
},
};