sigoden / aichat

All-in-one LLM CLI tool featuring Shell Assistant, Chat-REPL, RAG, AI tools & agents, with access to OpenAI, Claude, Gemini, Ollama, Groq, and more.
Apache License 2.0
4.33k stars 295 forks source link

Cannot pipe into `aichat -e` #531

Closed denniswebb closed 3 weeks ago

denniswebb commented 5 months ago

Describe the bug

On Mac, piping data to aichat -e always exits non-zero and without allowing you to run with the error

Error: IO error: Failed to initialize input reader

Caused by:
    Failed to initialize input reader

You can tell that it receives the data and a response from the GPT because it actually shows the proposed command, just exits with the error instead of waiting for your response.

This works as expected without -e but of course isn't what I need.

To Reproduce

Pipe any input into aichat -e

Expected behavior

App would present the EREC menu and await my response.

Screenshots/Logs

image

Configuration

model               openai:gpt-4o
max_output_tokens   -
temperature         -
top_p               -
dry_run             false
save                false
save_session        -
highlight           true
light_theme         true
wrap                no
wrap_code           false
auto_copy           false
keybindings         emacs
prelude             -
compress_threshold  2000

Environment (please complete the following information):

Additional context

I know you've had a few patches before related to this.

sigoden commented 5 months ago

The problem is related to inquire which provide interactive prompts (mikaelmello/inquire#200), Inquire uses an outdated version of crossterm that lacks support for reading standard input from a pipe.

I've encountered similar issue #257 before, but I resolved them by enabling the use-dev-tty feature for crossterm (#264).

I have submitted a issue (mikaelmello/inquire#252) to request that Inquire update its crossterm dependency.

Before that, the pipe stdin cannot be used with aichat -e .