Skip to content

Commit 6d4c895

Browse files
committed
Minor handler improvements
1 parent a18e81b commit 6d4c895

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

sgpt/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ def main(
243243
while shell and interaction:
244244
option = typer.prompt(
245245
text="[E]xecute, [M]odify, [D]escribe, [A]bort",
246-
type=Choice(["e", "m", "d", "a", "y"], case_sensitive=False),
246+
type=Choice(("e", "m", "d", "a", "y"), case_sensitive=False),
247247
default="e" if cfg.get("DEFAULT_EXECUTE_SHELL_CMD") == "true" else "a",
248248
show_choices=False,
249249
show_default=False,
250-
).lower()
250+
)
251251

252252
if option in ("e", "y"):
253253
# "y" option is for keeping compatibility with old version.

sgpt/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import typer
88

9+
from click import UsageError
10+
911
CONFIG_FOLDER = os.path.expanduser("~/.config")
1012
SHELL_GPT_CONFIG_FOLDER = Path(CONFIG_FOLDER) / "shell_gpt"
1113
SHELL_GPT_CONFIG_PATH = SHELL_GPT_CONFIG_FOLDER / ".sgptrc"
@@ -85,7 +87,7 @@ def get(self, key: str) -> str: # type: ignore
8587
# Prioritize environment variables over config file.
8688
value = os.getenv(key) or super().get(key)
8789
if not value:
88-
raise typer.Abort(f"Missing config key: {key}")
90+
raise UsageError(f"Missing config key: {key}")
8991
return value
9092

9193

sgpt/handlers/handler.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,16 @@ def get_completion(
137137
if tool_calls:
138138
for tool_call in tool_calls:
139139
if use_litellm:
140-
if tool_call.get("id"):
141-
tool_call_id = tool_call.get("id")
142-
if tool_call.get("function", {}).get("name"):
143-
name = tool_call["function"]["name"]
144-
if tool_call.get("function", {}).get("arguments"):
145-
arguments += tool_call["function"]["arguments"]
140+
# TODO: test.
141+
tool_call_id = tool_call.get("id") or tool_call_id
142+
name = tool_call.get("function", {}).get("name") or name
143+
arguments += tool_call.get("function", {}).get(
144+
"arguments", ""
145+
)
146146
else:
147-
if tool_call.id:
148-
tool_call_id = tool_call.id
149-
if tool_call.function.name:
150-
name = tool_call.function.name
151-
if tool_call.function.arguments:
152-
arguments += tool_call.function.arguments
147+
tool_call_id = tool_call.id or tool_call_id
148+
name = tool_call.function.name or name
149+
arguments += tool_call.function.arguments or ""
153150
if chunk.choices[0].finish_reason == "tool_calls":
154151
yield from self.handle_function_call(
155152
messages, tool_call_id, name, arguments

sgpt/llm_functions/common/execute_shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Function(BaseModel):
1313
...,
1414
example="ls -la",
1515
description="Shell command to execute.",
16-
) # type: ignore
16+
) # type: ignore
1717

1818
@classmethod
1919
def execute(cls, shell_command: str) -> str:

sgpt/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Any, Callable
66

77
import typer
8-
from click import BadParameter
8+
from click import BadParameter, UsageError
99

1010
from sgpt.__version__ import __version__
1111
from sgpt.integration import bash_integration, zsh_integration
@@ -82,7 +82,7 @@ def install_shell_integration(*_args: Any) -> None:
8282
with open(os.path.expanduser("~/.bashrc"), "a", encoding="utf-8") as file:
8383
file.write(bash_integration)
8484
else:
85-
raise typer.Abort("ShellGPT integrations only available for ZSH and Bash.")
85+
raise UsageError("ShellGPT integrations only available for ZSH and Bash.")
8686

8787
typer.echo("Done! Restart your shell to apply changes.")
8888

0 commit comments

Comments
 (0)