From 69811f82af27ff6245b025248ef1ec55a75dd8e8 Mon Sep 17 00:00:00 2001 From: null Date: Mon, 24 Jun 2024 04:24:55 +0000 Subject: [PATCH 1/4] fixed source retrial when only a line instead of a scope is given (#1545) --- extensions/vscode/src/util/ideUtils.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extensions/vscode/src/util/ideUtils.ts b/extensions/vscode/src/util/ideUtils.ts index cf9290a1c..14e70921c 100644 --- a/extensions/vscode/src/util/ideUtils.ts +++ b/extensions/vscode/src/util/ideUtils.ts @@ -19,6 +19,8 @@ import { uriFromFilePath, } from "./vscode"; +import _ from "lodash"; + const util = require("node:util"); const asyncExec = util.promisify(require("node:child_process").exec); @@ -495,7 +497,9 @@ export class VsCodeIdeUtils { const scope = scopeResponse.scopes[0]; - return await this.retrieveSource(scope.source ? scope : stackFrame); + return await this.retrieveSource( + scope.source && !_.isEmpty(scope.source) ? scope : stackFrame, + ); }), ); @@ -530,7 +534,7 @@ export class VsCodeIdeUtils { return await this.readRangeInFile( sourceContainer.source.path, new vscode.Range( - sourceContainer.line - 3, + Math.max(0, sourceContainer.line - 3), 0, sourceContainer.line + 2, 0, From 574a3923a6f97d8995561da3654aae3aca9ae439 Mon Sep 17 00:00:00 2001 From: Jonah Wagner Date: Sun, 23 Jun 2024 22:55:08 -0700 Subject: [PATCH 2/4] fix: preserve indentation in code blocks (#1554) --- extensions/vscode/src/commands.ts | 4 +++- gui/src/components/markdown/CodeSnippetPreview.tsx | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 5c3ae6fcf..1d2b4ce6c 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -70,7 +70,9 @@ async function addHighlightedCodeToContext( // } return; } - const range = new vscode.Range(selection.start, selection.end); + // adjust starting position to include indentation + const start = new vscode.Position(selection.start.line, 0); + const range = new vscode.Range(start, selection.end); const contents = editor.document.getText(range); const rangeInFileWithContents = { filepath: editor.document.uri.fsPath, diff --git a/gui/src/components/markdown/CodeSnippetPreview.tsx b/gui/src/components/markdown/CodeSnippetPreview.tsx index 770a7a588..63bff4257 100644 --- a/gui/src/components/markdown/CodeSnippetPreview.tsx +++ b/gui/src/components/markdown/CodeSnippetPreview.tsx @@ -156,7 +156,7 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) { From 6407458d7626d52558ea760b79a03129caba14ff Mon Sep 17 00:00:00 2001 From: Jonah Wagner Date: Tue, 25 Jun 2024 12:20:44 -0700 Subject: [PATCH 3/4] fix: autocomplete label after selecting a query type context provider (#1562) * fix: autocomplete label after selecting a query type context * fix: resolved issue causing unintentional changes to editor --- gui/src/components/mainInput/MentionList.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gui/src/components/mainInput/MentionList.tsx b/gui/src/components/mainInput/MentionList.tsx index 01a64a971..66efddcc6 100644 --- a/gui/src/components/mainInput/MentionList.tsx +++ b/gui/src/components/mainInput/MentionList.tsx @@ -83,8 +83,8 @@ function DropdownIcon(props: { className?: string; item: ComboBoxItem }) { props.item.type === "contextProvider" ? props.item.id : props.item.type === "slashCommand" - ? props.item.id - : props.item.type; + ? props.item.id + : props.item.type; const iconClass = `${props.className} flex-shrink-0`; @@ -120,9 +120,7 @@ function DropdownIcon(props: { className?: string; item: ComboBoxItem }) { const ItemsDiv = styled.div` border-radius: ${defaultBorderRadius}; - box-shadow: - 0 0 0 1px rgba(0, 0, 0, 0.05), - 0px 10px 20px rgba(0, 0, 0, 0.1); + box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05), 0px 10px 20px rgba(0, 0, 0, 0.1); font-size: 0.9rem; overflow-x: hidden; overflow-y: auto; @@ -242,6 +240,15 @@ const MentionList = forwardRef((props: MentionListProps, ref) => { } if (item.contextProvider?.type === "query") { + // update editor to complete context provider title + const { tr } = props.editor.view.state; + const text = tr.doc.textBetween(0, tr.selection.from); + const partialText = text.slice(text.lastIndexOf("@") + 1); + const remainingText = item.title.slice(partialText.length); + props.editor.view.dispatch( + tr.insertText(remainingText, tr.selection.from), + ); + setSubMenuTitle(item.description); setQuerySubmenuItem(item); return; From 02784804ab6b024fdef314ccba913909d849dc5c Mon Sep 17 00:00:00 2001 From: Andrij David Date: Thu, 27 Jun 2024 17:24:06 +0200 Subject: [PATCH 4/4] Add support for Azure OpenAI Endpoint in OpenAIEmbeddingProvider (#1517) --- core/index.d.ts | 3 +++ .../embeddings/OpenAIEmbeddingsProvider.ts | 23 +++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index 4f53b3c42..f3c8b03af 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -720,6 +720,9 @@ export interface EmbedOptions { apiBase?: string; apiKey?: string; model?: string; + engine?: string; + apiType?: string; + apiVersion?: string; requestOptions?: RequestOptions; } diff --git a/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts b/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts index 29e24ceeb..83d79a42a 100644 --- a/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts +++ b/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts @@ -13,11 +13,25 @@ class OpenAIEmbeddingsProvider extends BaseEmbeddingsProvider { model: "text-embedding-3-small", }; - async embed(chunks: string[]) { - if (!this.options.apiBase?.endsWith("/")) { - this.options.apiBase += "/"; + private _getEndpoint() { + if (!this.options.apiBase) { + throw new Error("No API base URL provided. Please set the 'apiBase' option in config.json"); } + this.options.apiBase = this.options.apiBase.endsWith("/") + ? this.options.apiBase + : `${this.options.apiBase}/`; + + if (this.options.apiType === "azure") { + return new URL( + `openai/deployments/${this.options.engine}/embeddings?api-version=${this.options.apiVersion}`, + this.options.apiBase, + ); + } + return new URL("embedding", this.options.apiBase); + } + + async embed(chunks: string[]) { const batchedChunks = []; for ( let i = 0; @@ -33,7 +47,7 @@ class OpenAIEmbeddingsProvider extends BaseEmbeddingsProvider { batchedChunks.map(async (batch) => { const fetchWithBackoff = () => withExponentialBackoff(() => - this.fetch(new URL("embeddings", this.options.apiBase), { + this.fetch(this._getEndpoint(), { method: "POST", body: JSON.stringify({ input: batch, @@ -42,6 +56,7 @@ class OpenAIEmbeddingsProvider extends BaseEmbeddingsProvider { headers: { Authorization: `Bearer ${this.options.apiKey}`, "Content-Type": "application/json", + "api-key": this.options.apiKey ?? "", // For Azure }, }), );