diff --git a/core/context/providers/HttpContextProvider.ts b/core/context/providers/HttpContextProvider.ts index c9ff0b2ea..05a50e15d 100644 --- a/core/context/providers/HttpContextProvider.ts +++ b/core/context/providers/HttpContextProvider.ts @@ -37,20 +37,29 @@ class HttpContextProvider extends BaseContextProvider { body: JSON.stringify({ query: query || "", fullInput: extras.fullInput, + options: this.options.options, }), }); const json = await response.json(); - const createContextItem = (item: any) => ({ - description: item.description ?? "HTTP Context Item", - content: item.content ?? "", - name: item.name ?? this.options.title ?? "HTTP", - }); + try { + const createContextItem = (item: any) => ({ + description: item.description ?? "HTTP Context Item", + content: item.content ?? "", + name: item.name ?? this.options.title ?? "HTTP", + }); - return Array.isArray(json) - ? json.map(createContextItem) - : [createContextItem(json)]; + return Array.isArray(json) + ? json.map(createContextItem) + : [createContextItem(json)]; + } catch (e) { + console.warn( + `Failed to parse response from custom HTTP context provider.\nError:\n${e}\nResponse from server:\n`, + json, + ); + return []; + } } } diff --git a/core/index.d.ts b/core/index.d.ts index 7c47ff5e5..be55efaa6 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -801,6 +801,7 @@ export interface ModelDescription { } export type EmbeddingsProviderName = + | "sagemaker" | "bedrock" | "huggingface-tei" | "transformers.js" diff --git a/core/indexing/embeddings/SageMakerEmbeddingsProvider.ts b/core/indexing/embeddings/SageMakerEmbeddingsProvider.ts new file mode 100644 index 000000000..9b860f1ae --- /dev/null +++ b/core/indexing/embeddings/SageMakerEmbeddingsProvider.ts @@ -0,0 +1,114 @@ +import { + InvokeEndpointCommand, + SageMakerRuntimeClient, + } from "@aws-sdk/client-sagemaker-runtime"; + import { fromIni } from "@aws-sdk/credential-providers"; + + import { + EmbeddingsProviderName, + EmbedOptions, + FetchFunction, + } from "../../index.js"; + import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider.js"; + + + class SageMakerEmbeddingsProvider extends BaseEmbeddingsProvider { + static providerName: EmbeddingsProviderName = "sagemaker"; + + static defaultOptions: Partial | undefined = { + region: "us-west-2", + maxBatchSize: 1, + }; + profile?: string | undefined; + + constructor(options: EmbedOptions, fetch: FetchFunction) { + super(options, fetch); + if (!options.apiBase) { + options.apiBase = `https://runtime.sagemaker.${options.region}.amazonaws.com`; + } + + if (options.profile) { + this.profile = options.profile; + } else { + this.profile = "sagemaker"; + } + } + + async embed(chunks: string[]) { + const credentials = await this._getCredentials(); + const client = new SageMakerRuntimeClient({ + region: this.options.region, + credentials: { + accessKeyId: credentials.accessKeyId, + secretAccessKey: credentials.secretAccessKey, + sessionToken: credentials.sessionToken || "", + }, + }); + + const batchedChunks = this.getBatchedChunks(chunks); + return ( + await Promise.all( + batchedChunks.map(async (batch) => { + const input = this._generateInvokeModelCommandInput( + batch, + this.options, + ); + const command = new InvokeEndpointCommand(input); + const response = await client.send(command); + + if (response.Body) { + const responseBody = JSON.parse( + new TextDecoder().decode(response.Body), + ); + // If the body contains a key called "embedding" or "embeddings", return the value, otherwise return the whole body + if (responseBody.embedding) { + return responseBody.embedding; + } else if (responseBody.embeddings) { + return responseBody.embeddings; + } else { + return responseBody; + } + } + }), + ) + ).flat(); + } + private _generateInvokeModelCommandInput( + prompts: string | string[], + options: EmbedOptions, + ): any { + const payload = { + inputs: prompts, + normalize: true, + // ...(options.requestOptions?.extraBodyProperties || {}), + }; + + if (options.requestOptions?.extraBodyProperties) { + Object.assign(payload, options.requestOptions.extraBodyProperties); + } + + return { + EndpointName: this.options.model, + Body: JSON.stringify(payload), + ContentType: "application/json", + CustomAttributes: "accept_eula=false", + }; + } + + private async _getCredentials() { + try { + return await fromIni({ + profile: this.profile, + ignoreCache: true, + })(); + } catch (e) { + console.warn( + `AWS profile with name ${this.profile} not found in ~/.aws/credentials, using default profile`, + ); + return await fromIni()(); + } + } + } + + export default SageMakerEmbeddingsProvider; + \ No newline at end of file diff --git a/core/indexing/embeddings/index.ts b/core/indexing/embeddings/index.ts index f22c8af42..0eb2ae11f 100644 --- a/core/indexing/embeddings/index.ts +++ b/core/indexing/embeddings/index.ts @@ -1,5 +1,6 @@ import { EmbeddingsProviderName } from "../../index.js"; import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider.js"; +import SageMakerEmbeddingsProvider from "./SageMakerEmbeddingsProvider.js"; import BedrockEmbeddingsProvider from "./BedrockEmbeddingsProvider.js"; import CohereEmbeddingsProvider from "./CohereEmbeddingsProvider.js"; import ContinueProxyEmbeddingsProvider from "./ContinueProxyEmbeddingsProvider.js"; @@ -22,6 +23,7 @@ export const allEmbeddingsProviders: Record< EmbeddingsProviderName, EmbeddingsProviderConstructor > = { + sagemaker: SageMakerEmbeddingsProvider, bedrock: BedrockEmbeddingsProvider, ollama: OllamaEmbeddingsProvider, "transformers.js": TransformersJsEmbeddingsProvider, diff --git a/docs/docs/customize/model-providers/more/sagemaker.md b/docs/docs/customize/model-providers/more/sagemaker.md index fc3bb9b4a..0c9eba812 100644 --- a/docs/docs/customize/model-providers/more/sagemaker.md +++ b/docs/docs/customize/model-providers/more/sagemaker.md @@ -1,8 +1,8 @@ # AWS SageMaker -SageMaker provider support SageMaker endpoint deployed with [LMI](https://docs.djl.ai/docs/serving/serving/docs/lmi/index.html) +SageMaker can be used for both chat and embedding models. Chat models are supported for endpoints deployed with [LMI](https://docs.djl.ai/docs/serving/serving/docs/lmi/index.html), and embedding models are supported for endpoints deployed with [HuggingFace TEI](https://huggingface.co/blog/sagemaker-huggingface-embedding) -To setup SageMaker, add the following to your `config.json` file: +To setup SageMaker as a chat model provider, add the following to your `config.json` file: ```json title="config.json" { @@ -13,7 +13,11 @@ To setup SageMaker, add the following to your `config.json` file: "model": "lmi-model-deepseek-coder-xxxxxxx", "region": "us-west-2" } - ] + ], + "embeddingsProvider": { + "provider": "sagemaker", + "model": "mxbai-embed-large-v1-endpoint" + }, } ``` diff --git a/docs/docs/customize/model-providers/top-level/azure.md b/docs/docs/customize/model-providers/top-level/azure.md index f6e54137f..338a3772b 100644 --- a/docs/docs/customize/model-providers/top-level/azure.md +++ b/docs/docs/customize/model-providers/top-level/azure.md @@ -22,7 +22,7 @@ We recommend configuring **GPT-4o** as your chat model. ## Autocomplete model -We recommend configuring **Codestral** as your autocomplete model. +We recommend configuring **Codestral** as your autocomplete model. There are not currently any other models in Azure that are capable of autocomplete. ```json title="config.json" "tabAutocompleteModel": [{ diff --git a/docs/docs/customize/tutorials/build-your-own-context-provider.md b/docs/docs/customize/tutorials/build-your-own-context-provider.md index 3ff7a3246..f730d22a4 100644 --- a/docs/docs/customize/tutorials/build-your-own-context-provider.md +++ b/docs/docs/customize/tutorials/build-your-own-context-provider.md @@ -180,12 +180,15 @@ If you'd like to write a context provider in a language other than TypeScript, y "url": "https://myserver.com/context-provider", "title": "http", "description": "Custom HTTP Context Provider", - "displayTitle": "My Custom Context" + "displayTitle": "My Custom Context", + "options": {} } } ``` - +Then, create a server that responds to requests as are made from [HttpContextProvider.ts](../../../../core/context/providers/HttpContextProvider.ts). See the `hello` endpoint in [context_provider_server.py](../../../../core/context/providers/context_provider_server.py) for an example that uses FastAPI. + +The `"options"` property can be used to send additional parameters to your endpoint, which will be included in the request body. ## Extension API for VSCode diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index 77de3cf8a..c1458bfc9 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -246,7 +246,25 @@ "region": { "title": "Region", "description": "The region where the model is hosted", - "type": "string" + "anyOf": [ + { + "enum": [ + "us-east-1", + "us-east-2", + "us-west-1", + "us-west-2", + "eu-west-1", + "eu-central-1", + "ap-southeast-1", + "ap-northeast-1", + "ap-south-1" + ], + "type": "string" + }, + { + "type": "string" + } + ] }, "profile": { "title": "Profile", @@ -1389,7 +1407,6 @@ "enum": [ "issue", "share", - "so", "cmd", "edit", "comment", @@ -1401,7 +1418,6 @@ "markdownEnumDescriptions": [ "Generate a link to a drafted GitHub issue", "Export the current chat session to markdown", - "Reference StackOverflow to answer the question", "Generate a terminal command and paste it into the terminal", "Edit the highlighted code with given instructions", "Add comments to the highlighted code", @@ -1855,6 +1871,11 @@ "url": { "type": "string", "description": "The HTTP endpoint of your context provider server." + }, + "options": { + "title": "Custom Options", + "description": "Additional options to pass to your custom HTTP server.", + "type": "object" } }, "required": ["url"] @@ -2145,7 +2166,8 @@ "gemini", "voyage", "nvidia", - "bedrock" + "bedrock", + "sagemaker" ] }, "model": { @@ -2179,7 +2201,7 @@ "region": { "title": "Region", "description": "The region where the model is hosted", - "type": "string" + "$ref": "#/definitions/ModelDescription/properties/region" }, "profile": { "title": "Profile", @@ -2201,6 +2223,24 @@ "then": { "required": ["apiKey"] } + }, + { + "if": { + "properties": { + "provider": { + "enum": ["sagemaker"] + } + }, + "required": ["provider"] + }, + "then": { + "properties": { + "model": { + "markdownDescription": "SageMaker endpoint name" + } + }, + "required": ["model"] + } } ] }, diff --git a/extensions/intellij/gradle.properties b/extensions/intellij/gradle.properties index dd4a1c1a0..37e02f543 100644 --- a/extensions/intellij/gradle.properties +++ b/extensions/intellij/gradle.properties @@ -3,13 +3,13 @@ pluginGroup=com.github.continuedev.continueintellijextension pluginName=continue-intellij-extension pluginRepositoryUrl=https://github.com/continuedev/continue # SemVer format -> https://semver.org -pluginVersion=0.0.74 +pluginVersion=0.0.75 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild=223 #pluginUntilBuild = 232.* # IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension platformType=IC -platformVersion=2022.3.3 +platformVersion=2023.2 #platformVersion = LATEST-EAP-SNAPSHOT # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt index f3a8f7d2e..0634fe844 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt @@ -126,7 +126,12 @@ class ContinuePluginStartupActivity : StartupActivity, Disposable, DumbAware { continuePluginService.coreMessenger?.request("config/ideSettingsUpdate", settings, null) { _ -> } continuePluginService.sendToWebview( "didChangeIdeSettings", mapOf( - "settings" to settings + "settings" to mapOf( + "remoteConfigServerUrl" to settings.remoteConfigServerUrl, + "remoteConfigSyncPeriod" to settings.remoteConfigSyncPeriod, + "userToken" to settings.userToken, + "enableControlServerBeta" to settings.enableContinueTeamsBeta + ) ) ) } diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/auth/ContinueAuthService.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/auth/ContinueAuthService.kt index 9c83e67fc..da6d74b43 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/auth/ContinueAuthService.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/auth/ContinueAuthService.kt @@ -100,7 +100,7 @@ class ContinueAuthService { updateRefreshToken(refreshToken) } - kotlinx.coroutines.delay(30 * 60 * 1000) + kotlinx.coroutines.delay(15 * 60 * 1000) // 15 minutes in milliseconds } } } @@ -140,19 +140,30 @@ class ContinueAuthService { } private fun retrieveSecret(key: String): String? { - val attributes = createCredentialAttributes(key, CREDENTIALS_USER) - val passwordSafe: PasswordSafe = PasswordSafe.instance + return try { + val attributes = createCredentialAttributes(key, CREDENTIALS_USER) + val passwordSafe: PasswordSafe = PasswordSafe.instance - val credentials: Credentials? = passwordSafe[attributes!!] - return credentials?.getPasswordAsString() + val credentials: Credentials? = passwordSafe[attributes!!] + credentials?.getPasswordAsString() + } catch (e: Exception) { + // Log the exception or handle it as needed + println("Error retrieving secret for key $key: ${e.message}") + null + } } private fun storeSecret(key: String, secret: String) { - val attributes = createCredentialAttributes(key, CREDENTIALS_USER) - val passwordSafe: PasswordSafe = PasswordSafe.instance + try { + val attributes = createCredentialAttributes(key, CREDENTIALS_USER) + val passwordSafe: PasswordSafe = PasswordSafe.instance - val credentials = Credentials(CREDENTIALS_USER, secret) - passwordSafe.set(attributes!!, credentials) + val credentials = Credentials(CREDENTIALS_USER, secret) + passwordSafe.set(attributes!!, credentials) + } catch (e: Exception) { + // Log the exception or handle it as needed + println("Error storing secret for key $key: ${e.message}") + } } private fun getAccessToken(): String? { diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt index 7f0697772..350a96bdd 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt @@ -730,9 +730,7 @@ class IdeProtocolClient( respond(File.separator) } - else -> { - println("Unknown messageType: $messageType") - } + else -> {} } } catch (error: Exception) { showToast("error", "Error handling message of type $messageType: $error") diff --git a/extensions/intellij/src/main/resources/config_schema.json b/extensions/intellij/src/main/resources/config_schema.json index 77de3cf8a..c1458bfc9 100644 --- a/extensions/intellij/src/main/resources/config_schema.json +++ b/extensions/intellij/src/main/resources/config_schema.json @@ -246,7 +246,25 @@ "region": { "title": "Region", "description": "The region where the model is hosted", - "type": "string" + "anyOf": [ + { + "enum": [ + "us-east-1", + "us-east-2", + "us-west-1", + "us-west-2", + "eu-west-1", + "eu-central-1", + "ap-southeast-1", + "ap-northeast-1", + "ap-south-1" + ], + "type": "string" + }, + { + "type": "string" + } + ] }, "profile": { "title": "Profile", @@ -1389,7 +1407,6 @@ "enum": [ "issue", "share", - "so", "cmd", "edit", "comment", @@ -1401,7 +1418,6 @@ "markdownEnumDescriptions": [ "Generate a link to a drafted GitHub issue", "Export the current chat session to markdown", - "Reference StackOverflow to answer the question", "Generate a terminal command and paste it into the terminal", "Edit the highlighted code with given instructions", "Add comments to the highlighted code", @@ -1855,6 +1871,11 @@ "url": { "type": "string", "description": "The HTTP endpoint of your context provider server." + }, + "options": { + "title": "Custom Options", + "description": "Additional options to pass to your custom HTTP server.", + "type": "object" } }, "required": ["url"] @@ -2145,7 +2166,8 @@ "gemini", "voyage", "nvidia", - "bedrock" + "bedrock", + "sagemaker" ] }, "model": { @@ -2179,7 +2201,7 @@ "region": { "title": "Region", "description": "The region where the model is hosted", - "type": "string" + "$ref": "#/definitions/ModelDescription/properties/region" }, "profile": { "title": "Profile", @@ -2201,6 +2223,24 @@ "then": { "required": ["apiKey"] } + }, + { + "if": { + "properties": { + "provider": { + "enum": ["sagemaker"] + } + }, + "required": ["provider"] + }, + "then": { + "properties": { + "model": { + "markdownDescription": "SageMaker endpoint name" + } + }, + "required": ["model"] + } } ] }, diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 77de3cf8a..c1458bfc9 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -246,7 +246,25 @@ "region": { "title": "Region", "description": "The region where the model is hosted", - "type": "string" + "anyOf": [ + { + "enum": [ + "us-east-1", + "us-east-2", + "us-west-1", + "us-west-2", + "eu-west-1", + "eu-central-1", + "ap-southeast-1", + "ap-northeast-1", + "ap-south-1" + ], + "type": "string" + }, + { + "type": "string" + } + ] }, "profile": { "title": "Profile", @@ -1389,7 +1407,6 @@ "enum": [ "issue", "share", - "so", "cmd", "edit", "comment", @@ -1401,7 +1418,6 @@ "markdownEnumDescriptions": [ "Generate a link to a drafted GitHub issue", "Export the current chat session to markdown", - "Reference StackOverflow to answer the question", "Generate a terminal command and paste it into the terminal", "Edit the highlighted code with given instructions", "Add comments to the highlighted code", @@ -1855,6 +1871,11 @@ "url": { "type": "string", "description": "The HTTP endpoint of your context provider server." + }, + "options": { + "title": "Custom Options", + "description": "Additional options to pass to your custom HTTP server.", + "type": "object" } }, "required": ["url"] @@ -2145,7 +2166,8 @@ "gemini", "voyage", "nvidia", - "bedrock" + "bedrock", + "sagemaker" ] }, "model": { @@ -2179,7 +2201,7 @@ "region": { "title": "Region", "description": "The region where the model is hosted", - "type": "string" + "$ref": "#/definitions/ModelDescription/properties/region" }, "profile": { "title": "Profile", @@ -2201,6 +2223,24 @@ "then": { "required": ["apiKey"] } + }, + { + "if": { + "properties": { + "provider": { + "enum": ["sagemaker"] + } + }, + "required": ["provider"] + }, + "then": { + "properties": { + "model": { + "markdownDescription": "SageMaker endpoint name" + } + }, + "required": ["model"] + } } ] }, diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index 21f27ca4a..7acf7d709 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -249,7 +249,25 @@ "region": { "title": "Region", "description": "The region where the model is hosted", - "type": "string" + "anyOf": [ + { + "enum": [ + "us-east-1", + "us-east-2", + "us-west-1", + "us-west-2", + "eu-west-1", + "eu-central-1", + "ap-southeast-1", + "ap-northeast-1", + "ap-south-1" + ], + "type": "string" + }, + { + "type": "string" + } + ] }, "profile": { "title": "Profile", @@ -1543,7 +1561,6 @@ "enum": [ "issue", "share", - "so", "cmd", "edit", "comment", @@ -1555,7 +1572,6 @@ "markdownEnumDescriptions": [ "Generate a link to a drafted GitHub issue", "Export the current chat session to markdown", - "Reference StackOverflow to answer the question", "Generate a terminal command and paste it into the terminal", "Edit the highlighted code with given instructions", "Add comments to the highlighted code", @@ -2076,6 +2092,11 @@ "url": { "type": "string", "description": "The HTTP endpoint of your context provider server." + }, + "options": { + "title": "Custom Options", + "description": "Additional options to pass to your custom HTTP server.", + "type": "object" } }, "required": [ @@ -2391,7 +2412,8 @@ "gemini", "voyage", "nvidia", - "bedrock" + "bedrock", + "sagemaker" ] }, "model": { @@ -2425,7 +2447,7 @@ "region": { "title": "Region", "description": "The region where the model is hosted", - "type": "string" + "$ref": "#/definitions/ModelDescription/properties/region" }, "profile": { "title": "Profile", @@ -2458,6 +2480,30 @@ "apiKey" ] } + }, + { + "if": { + "properties": { + "provider": { + "enum": [ + "sagemaker" + ] + } + }, + "required": [ + "provider" + ] + }, + "then": { + "properties": { + "model": { + "markdownDescription": "SageMaker endpoint name" + } + }, + "required": [ + "model" + ] + } } ] },