🐛 truncate stop words only for Jan

This commit is contained in:
Nate Sesti 2024-03-01 16:25:41 -05:00
parent 0017373633
commit 90e76bcd4c
4 changed files with 49 additions and 26 deletions

4
.prettierrc Normal file
View file

@ -0,0 +1,4 @@
{
"tabWidth": 2,
"useTabs": false
}

View file

@ -9,7 +9,7 @@ import { getBasename } from "../util";
const RERANK_PROMPT = (
query: string,
documentId: string,
document: string
document: string,
) => `You are an expert software developer responsible for helping detect whether the retrieved snippet of code is relevant to the query. For a given input, you need to output a single word: "Yes" or "No" indicating the retrieved snippet is relevant to the query.
Query: Where is the FastAPI server?
@ -49,7 +49,7 @@ Relevant:
async function scoreChunk(
chunk: Chunk,
llm: ILLM,
query: string
query: string,
): Promise<number> {
const completion = await llm.complete(
RERANK_PROMPT(query, getBasename(chunk.filepath), chunk.content),
@ -59,7 +59,7 @@ async function scoreChunk(
llm.providerName.startsWith("openai") && llm.model.startsWith("gpt-4")
? "gpt-3.5-turbo"
: llm.model,
}
},
);
if (!completion) {
@ -79,7 +79,7 @@ async function scoreChunk(
return 0.0;
} else {
console.warn(
`Unexpected response from single token reranker: "${answer}". Expected "yes" or "no".`
`Unexpected response from single token reranker: "${answer}". Expected "yes" or "no".`,
);
return 0.0;
}
@ -89,10 +89,10 @@ async function rerank(
chunks: Chunk[],
llm: ILLM,
query: string,
nFinal: number
nFinal: number,
): Promise<Chunk[]> {
const scores = await Promise.all(
chunks.map((chunk) => scoreChunk(chunk, llm, query))
chunks.map((chunk) => scoreChunk(chunk, llm, query)),
);
const sorted = chunks
.map((chunk, i) => ({ chunk, score: scores[i] }))
@ -104,7 +104,7 @@ async function rerank(
export async function retrieveContextItemsFromEmbeddings(
extras: ContextProviderExtras,
options: any | undefined,
filterDirectory: string | undefined
filterDirectory: string | undefined,
): Promise<ContextItem[]> {
if (!extras.embeddingsProvider) {
return [];
@ -123,9 +123,14 @@ export async function retrieveContextItemsFromEmbeddings(
throw new Error("No workspace directories found");
}
const branches = await Promise.all(
workspaceDirs.map((dir) => extras.ide.getBranch(dir))
);
const branches = (await Promise.race([
workspaceDirs.map((dir) => extras.ide.getBranch(dir)),
new Promise((resolve) => {
setTimeout(() => {
resolve(["NONE"]);
}, 500);
}),
])) as string[];
const tags: IndexTag[] = workspaceDirs.map((directory, i) => ({
directory,
branch: branches[i],
@ -138,10 +143,14 @@ export async function retrieveContextItemsFromEmbeddings(
if (extras.fullInput.trim() !== "") {
ftsResults = await ftsIndex.retrieve(
tags,
extras.fullInput.trim().split(" ").map(element => `"${element}"`).join(" OR "),
extras.fullInput
.trim()
.split(" ")
.map((element) => `"${element}"`)
.join(" OR "),
nRetrieve / 2,
filterDirectory,
undefined
undefined,
);
}
} catch (e) {
@ -149,13 +158,13 @@ export async function retrieveContextItemsFromEmbeddings(
}
const lanceDbIndex = new LanceDbIndex(extras.embeddingsProvider, (path) =>
extras.ide.readFile(path)
extras.ide.readFile(path),
);
let vecResults = await lanceDbIndex.retrieve(
tags,
extras.fullInput,
nRetrieve,
filterDirectory
filterDirectory,
);
// Now combine these (de-duplicate) and re-rank
@ -169,7 +178,7 @@ export async function retrieveContextItemsFromEmbeddings(
(r) =>
r.filepath === vecResult.filepath &&
r.startLine === vecResult.startLine &&
r.endLine === vecResult.endLine
r.endLine === vecResult.endLine,
)
) {
results.push(vecResult);
@ -183,7 +192,7 @@ export async function retrieveContextItemsFromEmbeddings(
if (results.length === 0) {
throw new Error(
"Warning: No results found for @codebase context provider."
"Warning: No results found for @codebase context provider.",
);
}

View file

@ -71,7 +71,9 @@ class OpenAI extends BaseLLM {
top_p: options.topP,
frequency_penalty: options.frequencyPenalty,
presence_penalty: options.presencePenalty,
stop: options.stop?.slice(0, 4),
stop: this.apiBase?.includes(":1337")
? options.stop?.slice(0, 4)
: options.stop,
};
return finalOptions;
@ -79,12 +81,12 @@ class OpenAI extends BaseLLM {
protected async _complete(
prompt: string,
options: CompletionOptions
options: CompletionOptions,
): Promise<string> {
let completion = "";
for await (const chunk of this._streamChat(
[{ role: "user", content: prompt }],
options
options,
)) {
completion += chunk.content;
}
@ -93,7 +95,7 @@ class OpenAI extends BaseLLM {
}
private _getEndpoint(
endpoint: "/chat/completions" | "/completions" | "/models"
endpoint: "/chat/completions" | "/completions" | "/models",
) {
if (this.apiType === "azure") {
return `${this.apiBase}/openai/deployments/${this.engine}${endpoint}?api-version=${this.apiVersion}`;
@ -101,7 +103,7 @@ class OpenAI extends BaseLLM {
let url = this.apiBase;
if (!url) {
throw new Error(
"No API base URL provided. Please set the 'apiBase' option in config.json"
"No API base URL provided. Please set the 'apiBase' option in config.json",
);
}
if (url.endsWith("/")) {
@ -114,11 +116,11 @@ class OpenAI extends BaseLLM {
protected async *_streamComplete(
prompt: string,
options: CompletionOptions
options: CompletionOptions,
): AsyncGenerator<string> {
for await (const chunk of this._streamChat(
[{ role: "user", content: prompt }],
options
options,
)) {
yield stripImages(chunk.content);
}
@ -126,7 +128,7 @@ class OpenAI extends BaseLLM {
protected async *_legacystreamComplete(
prompt: string,
options: CompletionOptions
options: CompletionOptions,
): AsyncGenerator<string> {
const args: any = this._convertArgs(options, []);
args.prompt = prompt;
@ -154,7 +156,7 @@ class OpenAI extends BaseLLM {
protected async *_streamChat(
messages: ChatMessage[],
options: CompletionOptions
options: CompletionOptions,
): AsyncGenerator<ChatMessage> {
if (
!CHAT_ONLY_MODELS.includes(options.model) &&
@ -163,7 +165,7 @@ class OpenAI extends BaseLLM {
) {
for await (const content of this._legacystreamComplete(
stripImages(messages[messages.length - 1]?.content || ""),
options
options,
)) {
yield {
role: "assistant",

View file

@ -6,6 +6,7 @@ import * as vscode from "vscode";
import { IDE } from "core";
import { ConfigHandler } from "core/config/handler";
import { logDevData } from "core/util/devdata";
import { Telemetry } from "core/util/posthog";
import { AutocompleteOutcome } from "./autocomplete/getTabCompletion";
import { ContinueGUIWebviewViewProvider } from "./debugPanel";
import { DiffManager } from "./diff/horizontal";
@ -409,6 +410,13 @@ const commandsMap: (
clearTimeout(logRejectionTimeout);
outcome.accepted = true;
logDevData("autocomplete", outcome);
Telemetry.capture("autocomplete", {
accepted: outcome.accepted,
modelName: outcome.modelName,
modelProvider: outcome.modelProvider,
time: outcome.time,
cacheHit: outcome.cacheHit
})
},
"continue.toggleTabAutocompleteEnabled": () => {
const config = vscode.workspace.getConfiguration("continue");