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.28k stars 724 forks source link

Piping into `sgpt -s` doesn't seem to provide the option to execute. #278

Closed startakovsky closed 7 months ago

startakovsky commented 1 year ago

I am doing the pipe using the -s flag but I do not see anything asking me to \[E\]xecute, etc. What am I doing wrong? This is with the latest release 0.92. When I do the cat data.json | sgpt -s "curl localhost with this json" it works just fine. So what is the difference between piping a bunch of files and a json?

>>> ls ~/.config/shell_gpt/roles/*.json | sgpt -s "what is the jq command to create a json from all these jsons with the key as the file name for each file"

jq -n '{code: (input("./Users/steven/.config/shell_gpt/roles/code.json") | fromjson), default: (input("./Users/steven/.config/shell_gpt/roles/default.json") | fromjson), describe_shell: (input("./Users/steven/.config/shell_gpt/roles/describe_shell.json") | fromjson), shell: (input("./Users/steven/.config/shell_gpt/roles/shell.json") | fromjson)}'
maelp commented 10 months ago

I have the same issue when doing a pipe, for instance

git diff | sgpt -s "Do a git commit with the changes"

prints the command, but does not go in an "interact mode", I guess it's because stdin is already used by the pipe so we cannot interact?

I've asked the question to ChatGPT which told me this 😅

import sys
import select

def main():
    query = sys.argv[1]  # get the query from command-line arguments

    # Check if there's data piped into stdin
    rlist, _, _ = select.select([sys.stdin], [], [], 0)
    if rlist:
        piped_text = sys.stdin.read()
        query += ' ' + piped_text.strip()  # append piped text to query

    while True:
        user_input = input(f"Query: {query}\nExecute or Cancel? (e/c): ").strip().lower()
        if user_input == 'e':
            execute_query(query)
            break
        elif user_input == 'c':
            print("Cancelled.")
            break
        else:
            print("Invalid input. Please enter 'e' to execute or 'c' to cancel.")

def execute_query(query):
    # Your query execution code here
    print(f"Executing: {query}")

if __name__ == "__main__":
    main()
maelp commented 10 months ago

Added a PR here which seems to work https://github.com/TheR1D/shell_gpt/pull/356

TheR1D commented 7 months ago

Hi @startakovsky, thank you for reporting this issue, it should be fixed in https://github.com/TheR1D/shell_gpt/pull/439