TheR1D / shell_gpt

A command-line productivity tool powered by AI large language models like GPT-4, will help you accomplish your tasks faster and more efficiently.
MIT License
9.78k stars 770 forks source link

Function Calling: unexpected behavior within ShellGPT's REPL mode when using the --repl --shell options #485

Closed hcal closed 8 months ago

hcal commented 9 months ago

I've encountered a potential issue or unexpected behavior with ShellGPT's REPL mode when using the --repl --shell options. I'm not 100% sure if this is a bug or if I'm not using the feature correctly.

Issue Description

When using the sgpt --repl --shell command and then asking it to list files in the current directory, the command's behavior is inconsistent between executions. Initially, the command executes but does not produce any output. Repeating the same command immediately after results in the expected output being displayed. Steps to Reproduce

Start ShellGPT in REPL mode with the shell option: sgpt --repl --shell
Input the command: list files in this dir
Entering REPL mode, press Ctrl+C to exit.
>>> list files in this dir

> @FunctionCall `execute_shell_command(shell_command="ls -l")`

>>> list files in this dir
Here is the list of files and directories in the current directory:
total 388
drwxr-xr-x. 1 cal cal    554 Feb 15 10:24 bin
drwxr-xr-x. 1 cal cal     28 Jan 13 16:35 blog
drwxr-xr-x. 1 cal cal      0 Feb 15 09:54 Desktop
drwxr-xr-x. 1 cal cal    880 Feb 15 09:15 Documents

Note the command I issued 'list files in this dir' twice and how the first time didn't product output following the "@FunctionCall" notice.

Expected Behavior

I expected the command run a function and list the files and directories upon the first execution without needing to repeat the command for output.

Actual Behavior

The command needs to be executed twice to produce the expected output. The first execution runs the function without any visible output, and the second execution displays the correct information without seemingly running the function again. Additional Information

I observed similar behavior with other commands that produce output, such as interactions with Task Warrior, which worked impressively well without additional configuration.

Is this behavior a bug, or am I missing a step in setting up or using the --repl --shell mode incorrectly?

TheR1D commented 9 months ago

This is actually a bug, --shell should not have access to functions. It is not particularly useful in the context of generating pure shell commands. Functions should only work with the default and custom roles. I tested it with default role sgpt --repl temp, and it works as expected. We will remove function calls from repl --shell/code in upcoming releases.

ghost commented 8 months ago

in powershell, it acts as follows:

>>> what is current folder?
```powershell
Get-Location

e

powershell : The term 'powershell' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1

save196 commented 8 months ago

I attempted to replicate the issue using the command from the initial comment. It appears that --shell used immediately after --repl is just creating a session called "--shell". Instead, the issue seems to be broader and occurs whenever the --chat or --repl flags are used and a function is called. sgpt outputs the function string, but then it doesn't manage to output the expected answer.