feat: ✨ /cmd slash command

This commit is contained in:
Nate Sesti 2023-09-05 12:11:47 -07:00
parent 7b6eac3ae8
commit 011877c09e
5 changed files with 41 additions and 5 deletions

View file

@ -16,6 +16,7 @@ from continuedev.src.continuedev.plugins.steps.feedback import FeedbackStep
from continuedev.src.continuedev.plugins.steps.comment_code import CommentCodeStep
from continuedev.src.continuedev.plugins.steps.share_session import ShareSessionStep
from continuedev.src.continuedev.plugins.steps.main import EditHighlightedCodeStep
from continuedev.src.continuedev.plugins.steps.cmd import GenerateShellCommandStep
from continuedev.src.continuedev.plugins.context_providers.search import SearchContextProvider
from continuedev.src.continuedev.plugins.context_providers.diff import DiffContextProvider
from continuedev.src.continuedev.plugins.context_providers.url import URLContextProvider
@ -66,7 +67,12 @@ config = ContinueConfig(
name="share",
description="Download and share the session transcript",
step=ShareSessionStep,
)
),
SlashCommand(
name="cmd",
description="Generate a shell command",
step=GenerateShellCommandStep,
),
],
context_providers=[
# GitHubIssuesContextProvider(

View file

@ -185,7 +185,7 @@ class LLM(ContinueBaseModel):
stop: Optional[List[str]] = None,
max_tokens: Optional[int] = None,
functions: Optional[List[Any]] = None,
) -> Coroutine[Any, Any, str]:
) -> str:
"""Yield completion response, either streamed or not."""
options = CompletionOptions(
model=model or self.model,

View file

@ -8,7 +8,7 @@ from ...core.sdk import ContinueSDK
from ...libs.util.filter_files import DEFAULT_IGNORE_PATTERNS
from .util import remove_meilisearch_disallowed_chars
MAX_SIZE_IN_CHARS = 25_000
MAX_SIZE_IN_CHARS = 50_000
async def get_file_contents(filepath: str, sdk: ContinueSDK) -> str:

View file

@ -0,0 +1,30 @@
from textwrap import dedent
from typing import Coroutine
from ...core.main import Step
from ...core.observation import Observation
from ...core.sdk import ContinueSDK
from ...libs.util.strings import remove_quotes_and_escapes
class GenerateShellCommandStep(Step):
user_input: str
async def run(self, sdk: ContinueSDK) -> Coroutine[Observation, None, None]:
cmd = await sdk.models.default.complete(
dedent(
f"""\
The user has made a request to run a shell command. Their description of what it should do is:
"{self.user_input}"
Please write a shell command that will do what the user requested. Your output should consist of only the command itself, without any explanation or example output. Do not use any newlines. Only output the command that when inserted into the terminal will do precisely what was requested.
"""
)
)
cmd = remove_quotes_and_escapes(cmd.strip()).replace("\n", "").replace("\r", "")
await sdk.ide.runCommand(cmd)
self.description = f"Generated shell command: {cmd}"

View file

@ -700,11 +700,11 @@ class IdeProtocolClient {
async runCommand(command: string) {
if (vscode.window.terminals.length) {
vscode.window.terminals[0].sendText(command);
vscode.window.terminals[0].sendText(command, false);
} else {
const terminal = vscode.window.createTerminal();
terminal.show();
terminal.sendText(command);
terminal.sendText(command, false);
}
}