Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sgpt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"OPENAI_FUNCTIONS_PATH": os.getenv("OPENAI_FUNCTIONS_PATH", str(FUNCTIONS_PATH)),
"OPENAI_USE_FUNCTIONS": os.getenv("OPENAI_USE_FUNCTIONS", "true"),
"SHOW_FUNCTIONS_OUTPUT": os.getenv("SHOW_FUNCTIONS_OUTPUT", "false"),
# Require an explicit user confirmation before running a function call
# proposed by the model, mirroring the confirmation already required
# before running a --shell-proposed command.
"FUNCTION_CALL_CONFIRM": os.getenv("FUNCTION_CALL_CONFIRM", "true"),
"API_BASE_URL": os.getenv("API_BASE_URL", "default"),
"PRETTIFY_MARKDOWN": os.getenv("PRETTIFY_MARKDOWN", "true"),
"USE_LITELLM": os.getenv("USE_LITELLM", "false"),
Expand Down
14 changes: 11 additions & 3 deletions sgpt/handlers/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from rich.live_render import VerticalOverflowMethod

import typer

from ..cache import Cache
from ..config import cfg
from ..function import get_function
Expand Down Expand Up @@ -90,9 +92,15 @@ def handle_function_call(
joined_args = ", ".join(f'{k}="{v}"' for k, v in dict_args.items())
yield f"> @FunctionCall `{name}({joined_args})` \n\n"

result = get_function(name)(**dict_args)
if cfg.get("SHOW_FUNCTIONS_OUTPUT") == "true":
yield f"```text\n{result}\n```\n"
if cfg.get("FUNCTION_CALL_CONFIRM") == "true" and not typer.confirm(
f"Run function {name}({joined_args})?", default=False, err=True
):
result = "Function call was not confirmed, the user declined to run it."
yield "> Function call aborted.\n\n"
else:
result = get_function(name)(**dict_args)
if cfg.get("SHOW_FUNCTIONS_OUTPUT") == "true":
yield f"```text\n{result}\n```\n"

# Add tool response message
messages.append(
Expand Down