Merge branch 'preview' of https://github.com/continuedev/continue into preview

This commit is contained in:
Nate Sesti 2024-06-27 08:25:07 -07:00
commit 71ae746d53
6 changed files with 44 additions and 13 deletions

3
core/index.d.ts vendored
View file

@ -720,6 +720,9 @@ export interface EmbedOptions {
apiBase?: string;
apiKey?: string;
model?: string;
engine?: string;
apiType?: string;
apiVersion?: string;
requestOptions?: RequestOptions;
}

View file

@ -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<Response>(() =>
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
},
}),
);

View file

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

View file

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

View file

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

View file

@ -156,7 +156,7 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) {
<StyledMarkdownPreview
source={`${fence}${getMarkdownLanguageTagForFile(
props.item.description,
)}\n${props.item.content.trim()}\n${fence}`}
)}\n${props.item.content.trimEnd()}\n${fence}`}
showCodeBorder={false}
/>
</div>