Estimated time: 2–3 hours
You have called the OpenAI API, managed conversation history, and extracted structured data. Now you will wire all three together into a real, usable tool.
You are building a command-line AI assistant that supports persistent conversations, a configurable system prompt, API error handling, and a --structured mode that extracts a JSON summary from any text. When you finish, you will have a tool you can actually use day-to-day.
Your CLI tool (assistant.py) must support the following usage:
uv run assistant.py
Starts a REPL loop. Conversation history is saved to history.json and reloaded on the next run. The user types messages; the assistant replies. Typing quit or exit ends the session.
uv run assistant.py "What is the speed of light?"
Sends the question, prints the answer, exits. Does not save to history.
uv run assistant.py --system "You are a Python code reviewer. Be terse."
Overrides the default system prompt for the session. Works in both modes.
uv run assistant.py --structured "Invoice INV-001, total $500 USD, due 2025-03-01"
Extracts a TextSummary object from the input and prints each field. Does not use conversation history.
uv run assistant.py --clear
Deletes history.json and exits with a confirmation message.
argparse for all CLI flags (--system, --structured, --clear)gpt-4o-miniAuthenticationError, RateLimitError, and OpenAIError with clear messages.env via python-dotenv — never hardcoded--structured mode uses a Pydantic model with at least: main_topic (str), key_entities (list[str]), sentiment (str: “positive”, “neutral”, “negative”), one_line_summary (str).env and history.json in .gitignoreBuild in this order — each step is runnable before the next:
argparse and print which mode was selected. Verify flags work.history.json).--structured mode with the Pydantic model.--clear.uv run assistant.py starts an interactive sessionuv run assistant.py "question" answers and exits--system "..." changes the assistant’s persona visibly--structured "some text" prints four structured fields--clear deletes history and confirms.env and history.json are in .gitignoreFinished early? These are not required, but push the project closer to production quality:
--model to switch between gpt-4o-mini and gpt-4ostream=True in the API call.--session <name> to save separate conversation histories (e.g. history-work.json, history-personal.json)Finished this project? Share your GitHub repo link in the discussion below. Browse what others built to get inspiration and give feedback.