Initial Commit
This commit is contained in:
parent
78f950cd9b
commit
ffcdc2a329
8 changed files with 354 additions and 11 deletions
3
core/index.d.ts
vendored
3
core/index.d.ts
vendored
|
|
@ -648,7 +648,8 @@ type ModelProvider =
|
|||
| "nvidia"
|
||||
| "vllm"
|
||||
| "mock"
|
||||
| "cerebras";
|
||||
| "cerebras"
|
||||
| "ask-sage";
|
||||
|
||||
|
||||
export type ModelName =
|
||||
|
|
|
|||
223
core/llm/llms/Asksage.ts
Normal file
223
core/llm/llms/Asksage.ts
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
import {
|
||||
ChatMessage,
|
||||
CompletionOptions,
|
||||
LLMOptions,
|
||||
ModelProvider,
|
||||
} from "../../index.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { streamSse } from "../stream.js";
|
||||
|
||||
/**
|
||||
* Asksage is a class that interfaces with the Ask Sage API.
|
||||
*/
|
||||
class Asksage extends BaseLLM {
|
||||
static providerName: ModelProvider = "ask-sage"; // Provider Name
|
||||
static defaultOptions: Partial<LLMOptions> = {
|
||||
apiBase: "https://api.asksage.ai/server/", // Base URL for Ask Sage API
|
||||
model: "gpt-4o", // Default model
|
||||
};
|
||||
|
||||
// Supported models and their corresponding API identifiers
|
||||
private static modelConversion: { [key: string]: string } = {
|
||||
"gpt-4o": "gpt-4o",
|
||||
"gpt-4o-mini": "gpt-4o-mini",
|
||||
// Add other models as needed
|
||||
};
|
||||
|
||||
constructor(options: LLMOptions) {
|
||||
super(options);
|
||||
this.apiVersion = options.apiVersion ?? "v1";
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given model name to the corresponding model identifier used by the API.
|
||||
* @param model - The model name.
|
||||
* @returns The API-specific model identifier.
|
||||
*/
|
||||
protected _convertModelName(model: string): string {
|
||||
return Asksage.modelConversion[model] ?? model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a ChatMessage into the format required by the Ask Sage API.
|
||||
* @param message - The ChatMessage to convert.
|
||||
* @returns The converted message.
|
||||
*/
|
||||
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(""),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the arguments for the API request.
|
||||
* @param options - The completion options.
|
||||
* @param messages - An array of ChatMessage objects.
|
||||
* @returns The arguments for the API request.
|
||||
*/
|
||||
protected _convertArgs(options: any, messages: ChatMessage[]) {
|
||||
// Format message as per API requirement
|
||||
let formattedMessage: any;
|
||||
if (messages.length === 1) {
|
||||
// Single message
|
||||
formattedMessage = messages[0].content;
|
||||
} else {
|
||||
// Array of messages
|
||||
formattedMessage = messages.map(this._convertMessage);
|
||||
}
|
||||
|
||||
const args: any = {
|
||||
message: formattedMessage,
|
||||
persona: options.persona ?? "default",
|
||||
dataset: options.dataset ?? "all",
|
||||
limit_references: options.limitReferences ?? 0,
|
||||
temperature: options.temperature ?? 0.0,
|
||||
live: options.live ?? 0,
|
||||
model: this._convertModelName(options.model),
|
||||
system_prompt: options.systemPrompt,
|
||||
tools: options.tools,
|
||||
tool_choice: options.toolChoice,
|
||||
// Add other parameters as required by your API
|
||||
};
|
||||
|
||||
// Remove undefined properties
|
||||
Object.keys(args).forEach(
|
||||
(key) => args[key] === undefined && delete args[key]
|
||||
);
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the headers required for the API requests.
|
||||
* @returns An object containing header key-value pairs.
|
||||
*/
|
||||
protected _getHeaders() {
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
|
||||
if (this.apiKey) {
|
||||
headers["x-access-tokens"] = this.apiKey; // Use x-access-tokens as per API requirement
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the full URL for a given API endpoint.
|
||||
* @param endpoint - The endpoint path.
|
||||
* @returns A URL object representing the full API endpoint URL.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a completion request to the API and returns the response.
|
||||
* @param prompt - The input prompt for the language model.
|
||||
* @param options - Additional completion options.
|
||||
* @returns The generated completion text.
|
||||
*/
|
||||
protected async _complete(
|
||||
prompt: string,
|
||||
options: CompletionOptions
|
||||
): Promise<string> {
|
||||
// Input validation to prevent injections
|
||||
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.response; // Adjust based on your API's response structure
|
||||
}
|
||||
|
||||
/**
|
||||
* Streams completion data from the API.
|
||||
* Note: If streaming is not supported, you can remove this method or adjust accordingly.
|
||||
* @param prompt - The input prompt for the language model.
|
||||
* @param options - Additional completion options.
|
||||
* @returns An async generator yielding completion text chunks.
|
||||
*/
|
||||
protected async *_streamComplete(
|
||||
prompt: string,
|
||||
options: CompletionOptions
|
||||
): AsyncGenerator<string> {
|
||||
// Since streaming is not indicated, yield the full completion
|
||||
const completion = await this._complete(prompt, options);
|
||||
yield completion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Streams chat messages from the API.
|
||||
* @param messages - An array of ChatMessage objects.
|
||||
* @param options - Additional completion options.
|
||||
* @returns An async generator yielding ChatMessage chunks.
|
||||
*/
|
||||
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();
|
||||
|
||||
// Construct a ChatMessage from the response
|
||||
const assistantMessage: ChatMessage = {
|
||||
role: "assistant",
|
||||
content: data.response, // Adjust based on your API's response structure
|
||||
};
|
||||
|
||||
yield assistantMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of available models from the API.
|
||||
* @returns A promise that resolves to an array of model names.
|
||||
*/
|
||||
async listModels(): Promise<string[]> {
|
||||
// If your API provides an endpoint to list models, implement it here
|
||||
// For now, return the keys from modelConversion
|
||||
return Object.keys(Asksage.modelConversion);
|
||||
}
|
||||
}
|
||||
|
||||
export default Asksage;
|
||||
57
docs/docs/customize/model-providers/more/asksage.md
Normal file
57
docs/docs/customize/model-providers/more/asksage.md
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
---
|
||||
title: Ask Sage
|
||||
slug: ../ask-sage
|
||||
---
|
||||
|
||||
## Chat model
|
||||
|
||||
We recommend configuring **GPT-4o** as your chat model.
|
||||
|
||||
```json title="config.json"
|
||||
"models": [{
|
||||
"title": "GPT-4o",
|
||||
"provider": "azure",
|
||||
"model": "gpt-4o",
|
||||
"apiBase": "<YOUR_DEPLOYMENT_BASE>",
|
||||
"engine": "<YOUR_ENGINE>",
|
||||
"apiVersion": "<YOUR_API_VERSION>",
|
||||
"apiType": "azure",
|
||||
"apiKey": "<MY_API_KEY>"
|
||||
}]
|
||||
```
|
||||
|
||||
## Privacy
|
||||
|
||||
If you'd like to use OpenAI models but are concerned about privacy, you can use the Azure OpenAI service, which is GDPR and HIPAA compliant.
|
||||
|
||||
:::info[Getting access]
|
||||
You need to apply for access to the Azure OpenAI service. Response times are typically within a few days.
|
||||
|
||||
**[Click here to apply for access to the Azure OpenAI service](https://azure.microsoft.com/en-us/products/ai-services/openai-service)**
|
||||
:::
|
||||
|
||||
## General model configuration
|
||||
|
||||
Azure OpenAI requires a handful of additional parameters to be configured, such as a model engine and API version.
|
||||
|
||||
To find this information in _Azure AI Studio_, first select the model that you would like to connect. Then visit _Endpoint_ > _Target URI_.
|
||||
|
||||
For example, a Target URI of `<https://just-an-example.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2023-03-15-preview>` would map to the following:
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "GPT-4o Azure",
|
||||
"model": "gpt-4o",
|
||||
"provider": "azure",
|
||||
"apiBase": "https://just-an-example.openai.azure.com",
|
||||
"apiType": "azure",
|
||||
"engine": "gpt-4o",
|
||||
"apiVersion": "2023-03-15-preview",
|
||||
"apiKey": "<MY_API_KEY>"
|
||||
}
|
||||
```
|
||||
|
||||
## Future Work
|
||||
|
||||
Ask Sage is working on enabling the utilization of the other functionalities that Continue.Dev offers. Stay tuned for more updates!
|
||||
|
||||
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "0.9.223",
|
||||
"version": "0.9.227",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "0.9.223",
|
||||
"version": "0.9.227",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "continue",
|
||||
"icon": "media/icon.png",
|
||||
"author": "Continue Dev, Inc",
|
||||
"version": "0.9.223",
|
||||
"version": "0.9.227",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/continuedev/continue"
|
||||
|
|
|
|||
BIN
gui/public/logos/ask-sage.png
Normal file
BIN
gui/public/logos/ask-sage.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
|
|
@ -360,6 +360,7 @@ export const models: { [key: string]: ModelPackage } = {
|
|||
"together",
|
||||
"llama.cpp",
|
||||
"replicate",
|
||||
"ask-sage",
|
||||
],
|
||||
isOpenSource: true,
|
||||
},
|
||||
|
|
@ -540,7 +541,7 @@ export const models: { [key: string]: ModelPackage } = {
|
|||
contextLength: 32000,
|
||||
},
|
||||
icon: "mistral.png",
|
||||
providerOptions: ["mistral"],
|
||||
providerOptions: ["mistral", "ask-sage"],
|
||||
isOpenSource: false,
|
||||
},
|
||||
geminiPro: {
|
||||
|
|
@ -553,7 +554,7 @@ export const models: { [key: string]: ModelPackage } = {
|
|||
apiKey: "<API_KEY>",
|
||||
},
|
||||
icon: "gemini.png",
|
||||
providerOptions: ["gemini"],
|
||||
providerOptions: ["gemini", "ask-sage"],
|
||||
isOpenSource: false,
|
||||
},
|
||||
gemini15Pro: {
|
||||
|
|
@ -635,7 +636,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", "ask-sage"],
|
||||
icon: "openai.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
|
|
@ -650,7 +651,7 @@ export const models: { [key: string]: ModelPackage } = {
|
|||
systemMessage:
|
||||
"You are an expert software developer. You give helpful and concise responses.",
|
||||
},
|
||||
providerOptions: ["openai"],
|
||||
providerOptions: ["openai", "ask-sage"],
|
||||
icon: "openai.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
|
|
@ -677,7 +678,7 @@ export const models: { [key: string]: ModelPackage } = {
|
|||
title: "Claude 3.5 Sonnet",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["anthropic", "free-trial"],
|
||||
providerOptions: ["anthropic", "free-trial", "ask-sage"],
|
||||
icon: "anthropic.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
|
|
@ -691,7 +692,7 @@ export const models: { [key: string]: ModelPackage } = {
|
|||
title: "Claude 3 Opus",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["anthropic"],
|
||||
providerOptions: ["anthropic", "ask-sage"],
|
||||
icon: "anthropic.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
|
|
@ -705,7 +706,7 @@ export const models: { [key: string]: ModelPackage } = {
|
|||
title: "Claude 3 Sonnet",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["anthropic", "free-trial"],
|
||||
providerOptions: ["anthropic", "free-trial", "ask-sage"],
|
||||
icon: "anthropic.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
|
|
@ -791,6 +792,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: ["ask-sage", "openai"],
|
||||
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: ["ask-sage", "openai"],
|
||||
icon: "openai.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
AUTODETECT: {
|
||||
title: "Autodetect",
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ export const providers: Partial<Record<ModelProvider, ProviderInfo>> = {
|
|||
models.gpt4omini,
|
||||
models.gpt4turbo,
|
||||
models.gpt35turbo,
|
||||
models.gpt4gov,
|
||||
models.gpt4ogov,
|
||||
{
|
||||
...models.AUTODETECT,
|
||||
params: {
|
||||
|
|
@ -626,4 +628,33 @@ To get started, [register](https://dataplatform.cloud.ibm.com/registration/stepo
|
|||
],
|
||||
apiKeyUrl: "https://cloud.cerebras.ai/",
|
||||
},
|
||||
"ask-sage": {
|
||||
title: "Ask Sage",
|
||||
provider: "ask-sage",
|
||||
description:
|
||||
"The Ask Sage API provides seamless access to their models, including Codestral, Mistral 8x22B, Mistral Large, and more.",
|
||||
icon: "ask-sage.png",
|
||||
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: "",
|
||||
},
|
||||
collectInputFor: [
|
||||
{ ...apiBaseInput, required: true },
|
||||
...completionParamsInputsConfigs,
|
||||
],
|
||||
packages: [
|
||||
models.gpt4gov,
|
||||
models.gpt4ogov,
|
||||
models.gpt4o,
|
||||
models.gpt4omini,
|
||||
models.claude35Sonnet,
|
||||
models.claude3Opus,
|
||||
models.claude3Sonnet,
|
||||
models.mistralLarge,
|
||||
models.llama3Chat,
|
||||
models.geminiPro,
|
||||
],
|
||||
apiKeyUrl: "https://chat.asksage.ai/",
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue