✨ finishing touches on /so
This commit is contained in:
parent
a7d637cd9a
commit
e6da0d03fd
4 changed files with 19 additions and 19 deletions
|
|
@ -40,6 +40,7 @@ export const serverStateSlice = createSlice({
|
|||
slashCommands: [
|
||||
...action.payload,
|
||||
{ name: "codebase", description: "Retrieve codebase context" },
|
||||
{ name: "so", description: "Search StackOverflow" },
|
||||
],
|
||||
};
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Reference in a new issue