From f280eca8ae85558ecd995dc5b679a100ea5bd04f Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Mon, 21 Oct 2024 22:20:02 +0200 Subject: [PATCH] remove stack overflow context provider --- core/commands/slash/index.ts | 2 - core/commands/slash/stackOverflow.ts | 126 --------------------- docs/docs/customize/slash-commands.md | 15 --- gui/src/redux/slices/serverStateReducer.ts | 1 - 4 files changed, 144 deletions(-) delete mode 100644 core/commands/slash/stackOverflow.ts diff --git a/core/commands/slash/index.ts b/core/commands/slash/index.ts index 0a6fc327d..f94c6ee05 100644 --- a/core/commands/slash/index.ts +++ b/core/commands/slash/index.ts @@ -6,13 +6,11 @@ import EditSlashCommand from "./edit"; import HttpSlashCommand from "./http"; import ReviewMessageCommand from "./review"; import ShareSlashCommand from "./share"; -import StackOverflowSlashCommand from "./stackOverflow"; import OnboardSlashCommand from "./onboard"; export default [ DraftIssueCommand, ShareSlashCommand, - StackOverflowSlashCommand, GenerateTerminalCommand, EditSlashCommand, CommentSlashCommand, diff --git a/core/commands/slash/stackOverflow.ts b/core/commands/slash/stackOverflow.ts deleted file mode 100644 index 3e967990d..000000000 --- a/core/commands/slash/stackOverflow.ts +++ /dev/null @@ -1,126 +0,0 @@ -import { TRIAL_PROXY_URL } from "../../control-plane/client.js"; -import { ChatMessageRole, FetchFunction, SlashCommand } from "../../index.js"; -import { pruneStringFromBottom } from "../../llm/countTokens.js"; -import { stripImages } from "../../llm/images.js"; - -const PROMPT = ( - input: string, -) => `The above sources are excerpts from related StackOverflow questions. Use them to help answer the below question from our user. Provide links to the sources in markdown whenever possible: - -${input} -`; - -async function getResults(q: string, fetch: FetchFunction): Promise { - const payload = JSON.stringify({ - q: `${q} site:stackoverflow.com`, - }); - - const resp = await fetch(new URL("/search", TRIAL_PROXY_URL), { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: payload, - }); - return await resp.json(); -} - -async function fetchData( - url: string, - fetch: FetchFunction, -): Promise { - const response = await fetch(url, { - headers: { - Accept: "text/html", - }, - }); - const htmlString = await response.text(); - - const parser = new DOMParser(); - const doc = parser.parseFromString(htmlString, "text/html"); - - const h1 = doc.querySelector("h1.fs-headline1"); - const title = h1?.textContent?.trim() ?? "No Title"; - - const bodies = doc.querySelectorAll("div.js-post-body"); - if (bodies.length < 2) { - return undefined; - } - - const question = bodies[0].textContent ?? ""; - const answer = bodies[1].textContent ?? ""; - - return ` - # Question: [${title}](${url}) - -${question} - -# Best Answer - -${answer} - `; -} - -const StackOverflowSlashCommand: SlashCommand = { - name: "so", - description: "Search Stack Overflow", - run: async function* ({ llm, input, addContextItem, history, fetch }) { - const contextLength = llm.contextLength; - - const sources: string[] = []; - const results = await getResults(input, fetch); - const links = results.organic.map((result: any) => result.link); - let totalTokens = llm.countTokens(input) + 200; - - for (const link of links) { - const contents = await fetchData(link, fetch); - if (!contents) { - continue; - } - sources.push(contents); - const newTokens = llm.countTokens(contents); - totalTokens += newTokens; - - let shouldBreak = false; - if (totalTokens > contextLength) { - sources[sources.length - 1] = pruneStringFromBottom( - llm.model, - contextLength - (totalTokens - newTokens), - sources[sources.length - 1], - ); - shouldBreak = true; - } - - if (sources.length >= 3) { - shouldBreak = true; - } - - addContextItem({ - content: sources[sources.length - 1], - description: "StackOverflow Answer", - name: `StackOverflow ${sources.length}`, - id: { - providerTitle: "so", - itemId: links[sources.length - 1], - }, - }); - - if (shouldBreak) { - break; - } - } - - for await (const chunk of llm.streamChat([ - ...history, - ...sources.map((source) => ({ - role: "user" as ChatMessageRole, - content: source, - })), - { role: "user", content: PROMPT(input) }, - ])) { - yield stripImages(chunk.content); - } - }, -}; - -export default StackOverflowSlashCommand; diff --git a/docs/docs/customize/slash-commands.md b/docs/docs/customize/slash-commands.md index 702d00c7c..7c1d05ed9 100644 --- a/docs/docs/customize/slash-commands.md +++ b/docs/docs/customize/slash-commands.md @@ -122,21 +122,6 @@ Describe the issue you'd like to generate, and Continue will turn into a well-fo } ``` -### `/So` - -The StackOverflow slash command will automatically pull results from StackOverflow to answer your question, quoting links along with its answer. - -```json title="config.json" -{ - "slashCommands": [ - { - "name": "so", - "description": "Reference StackOverflow to answer the question" - } - ] -} -``` - ### `/Onboard` The Onboard slash command helps to familiarize yourself with a new project by analyzing the project structure, READMEs, and dependency files. It identifies key folders, explains their purpose, and highlights popular packages used. Additionally, it offers insights into the project's architecture. diff --git a/gui/src/redux/slices/serverStateReducer.ts b/gui/src/redux/slices/serverStateReducer.ts index b3e17a096..16b2c0d78 100644 --- a/gui/src/redux/slices/serverStateReducer.ts +++ b/gui/src/redux/slices/serverStateReducer.ts @@ -53,7 +53,6 @@ export const serverStateSlice = createSlice({ state.slashCommands = [ ...action.payload, { name: "codebase", description: "Retrieve codebase context" }, - { name: "so", description: "Search StackOverflow" }, ]; }, setContextProviders: (