diff --git a/gui/src/redux/slices/serverStateReducer.ts b/gui/src/redux/slices/serverStateReducer.ts index cb956f8f4..f05b13a7a 100644 --- a/gui/src/redux/slices/serverStateReducer.ts +++ b/gui/src/redux/slices/serverStateReducer.ts @@ -40,6 +40,7 @@ export const serverStateSlice = createSlice({ slashCommands: [ ...action.payload, { name: "codebase", description: "Retrieve codebase context" }, + { name: "so", description: "Search StackOverflow" }, ], }; }, diff --git a/server/continuedev/core/config.py b/server/continuedev/core/config.py index 1257fc15d..2267b6a6d 100644 --- a/server/continuedev/core/config.py +++ b/server/continuedev/core/config.py @@ -15,7 +15,6 @@ from .context import ContextProvider from .main import ContextProviderDescription, Policy, SlashCommandDescription, Step from .models import Models from ..libs.util.telemetry import posthog_logger -from ..libs.util.logging import logger class SlashCommand(BaseModel): diff --git a/server/continuedev/plugins/policies/default.py b/server/continuedev/plugins/policies/default.py index 42f5e8ead..e1b06d29e 100644 --- a/server/continuedev/plugins/policies/default.py +++ b/server/continuedev/plugins/policies/default.py @@ -1,9 +1,8 @@ from typing import Type, Union +from ..steps.stack_overflow import StackOverflowStep from ...models.main import Position, PositionInFile - from ..steps.refactor import RefactorReferencesStep - from ..steps.clear_history import ClearHistoryStep from ..steps.comment_code import CommentCodeStep from ..steps.share_session import ShareSessionStep @@ -27,6 +26,7 @@ REPLACEMENT_SLASH_COMMAND_STEPS = [ ShareSessionStep, CommentCodeStep, ClearHistoryStep, + StackOverflowStep, ] @@ -107,6 +107,9 @@ class DefaultPolicy(Policy): if user_input.startswith("/codebase "): return AnswerQuestionChroma(user_input=user_input[len("/codebase ") :]) + if user_input.startswith("/so "): + return StackOverflowStep(user_input=user_input[len("/so ") :]) + if user_input.startswith("/references "): args = user_input.split() return RefactorReferencesStep( diff --git a/server/continuedev/plugins/steps/web.py b/server/continuedev/plugins/steps/stack_overflow.py similarity index 86% rename from server/continuedev/plugins/steps/web.py rename to server/continuedev/plugins/steps/stack_overflow.py index 3dbf0f319..ed1c1c454 100644 --- a/server/continuedev/plugins/steps/web.py +++ b/server/continuedev/plugins/steps/stack_overflow.py @@ -11,12 +11,10 @@ from ...libs.llm.base import CompletionOptions from .chat import SimpleChatStep from ...core.main import ContextItem, ContextItemDescription, ContextItemId, Step from ...core.sdk import ContinueSDK -from dotenv import load_dotenv -import os - -load_dotenv() -SERPER_API_KEY = os.getenv("SERPER_API_KEY") +from ...libs.util.logging import logger +# SERVER_URL = "http://127.0.0.1:8080" +SERVER_URL = "https://proxy-server-l6vsfbzhba-uw.a.run.app" PROMPT = """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: {user_input} @@ -24,17 +22,16 @@ PROMPT = """The above sources are excerpts from related StackOverflow questions. async def get_results(q: str): - url = "https://google.serper.dev/search" - payload = json.dumps({"q": f"{q} site:stackoverflow.com"}) - headers = { - "X-API-KEY": SERPER_API_KEY, - "Content-Type": "application/json", - } - response = requests.request("POST", url, headers=headers, data=payload) - - return response.json() + try: + response = requests.request("POST", f"{SERVER_URL}/search", data=payload) + return response.json() + except Exception: + logger.warning( + "You have been rate limited. Try the search endpoint again in a few minutes." + ) + return {"organic": []} async def get_link_contents(url: str) -> Optional[str]: @@ -62,9 +59,9 @@ async def get_link_contents(url: str) -> Optional[str]: return content -class WebSearchChatStep(Step): +class StackOverflowStep(Step): user_input: str - name: str = "Chat using Web Search for reference" + name: str = "Chat using StackOverflow for reference" max_sources: int = 3 hide: bool = True