A command-line chatbot powered by the OpenAI Responses API.
It supports conversation history, file analysis, instant saving, and web search.
Uses event streaming and previous_response_id to maintain context efficiently.
- 🗨️ Conversational interface with context-aware replies
- ⌨️ Advanced input options:
- Multi-line prompt input (Enter = new line, Alt+Enter = send)
- Emacs-style shortcuts (e.g., Ctrl+A, Ctrl+E, Ctrl+K, etc.)
- 💾 Conversation history saved to
./history - 📂 File input via lines starting with
~␣(tilde + space):- Text-based files (
.txt,.csv,.py,.md, etc.) - Excel files (
.xlsx, automatically converted to JSON) - PDF files (
.pdf, supports both local files and URLs) - Images (
.jpg,.jpeg,.png, supports both local files and URLs)
- Text-based files (
- 🌐 Web search using the
--searchflag for up-to-date answers - ⚡ Instant save using
!savecommand
- Python 3.10+
- Install dependencies:
pip install -r requirements.txt
Optional (Windows):
Use Windows Terminal for better rendering and fewer artifacts.
-
Set API Key
setx OPENAI_API_KEY "your_api_key_here" # Windows export OPENAI_API_KEY="your_api_key_here" # Linux / macOS
-
Configure Settings
Copy
settings_example.py→settings.pyand edit:PROMPT = "You are a helpful assistant. Respond in well-structured Markdown." MODEL = "gpt-5.1-chat-latest" # gpt-5.1-chat-latest | gpt-5.1 | gpt-5.1-codex | gpt-5.1-codex-mini | gpt-5-chat-latest | gpt-5 | gpt-5-mini | gpt-4.1 | gpt-4.1-mini | o4-mini TEMPERATURE = 0.35 STREAM = False # True | False REASONING_EFFORT = "low" # low | medium | high | minimal COUNTRY = "JP" # A two-letter ISO country code, like US
-
Run
python clichatbot.py
(Windows users can use
script/wt-openai.batto launch in Windows Terminal.)
Type your question.
Enter→ new lineAlt+Enter(orEscthenEnter) → send message
user: Your question
Multiple files supported (each file path on a new line starting with ~␣):
user: Explain these files
~ /path/to/example.py
~ /path/to/document.pdf
~ /path/to/image.png
user: Are these files related?
~ https://example.com/image.jpg
~ https://example.com/document.pdf
Add the --search flag at the end of your question. gpt-5-chat-latest is not supported.
user: What are the latest developments in quantum computing? --search
Press Alt+Enter (or Esc then Enter) on empty input → history is saved to ./history.
user: !save
Ctrl + A→ Move cursor to beginning of lineCtrl + E→ Move cursor to end of lineCtrl + U→ Delete to beginning of lineCtrl + K→ Delete to end of lineCtrl + D→ Delete character under cursorCtrl + H→ Backspace
user: Explain these files
~ clichatbot.py
~ settings_example.py
Completed loading the file: 'clichatbot.py'
Completed loading the file: 'settings_example.py'
gpt-5-medium assistant:
Here’s a clear walkthrough of what each file does, how to use the CLI chatbot, and how the pieces fit together.
Overview
- clichatbot.py: A command-line chatbot that talks to OpenAI’s Responses API. It supports:
- Streaming and non-streaming outputs
...
user: Analyze the letter and provide a summary of the key points.
~ https://www.berkshirehathaway.com/qtrly/2ndqtr25.pdf
Processing the file: 'https://www.berkshirehathaway.com/qtrly/2ndqtr25.pdf'
gpt-5-medium assistant:
Here’s a concise, decision‑oriented summary of Berkshire Hathaway’s Q2 2025 Form 10‑Q.
Headline results
- Net earnings attributable to Berkshire shareholders: $12.37B for Q2 (vs. $30.35B in Q2’24); $16.97B for 1H’25 (vs. $43.05B in 1H’24).
- Revenues: $92.5B in Q2 (−1% YoY); $182.2B in 1H (−1% YoY).
...
- PROMPT → System prompt for the assistant (e.g.,
"You are a helpful assistant.") - MODEL → OpenAI model (
gpt-5.1,gpt-4.1,o4-mini, etc.) - TEMPERATURE → Higher = more creative, Lower = more deterministic
- STREAM → Stream output (
True/False) - REASONING_EFFORT → Controls reasoning depth (
low,medium,high,minimal) - COUNTRY → ISO country code (e.g.,
US,JP) for localized web search
- Reasoning usage:
- Valid only for reasoning models (
gpt-5,o1–o9), excludinggpt-5-chat-latest. minimal→ intended forgpt-5family.- For
o1–o9,minimalfalls back tolow.
- Valid only for reasoning models (
- STREAM=False → single Markdown-rendered reply per turn.
- If an error occurs with an HTTP-linked PDF, try downloading the file first.
- Surrogate pair characters are not supported due to a limitation in prompt_toolkit.
MIT
