What you need
- Python 3.8+
- An OpenAI API key (get one here)
- 5 minutes
Step 1 — Install
pip install openai python-dotenvStep 2 — The simplest possible bot
Create a .env file in your project folder:
OPENAI_API_KEY=sk-...your-key-here...Then create bot.py:
import os
import openai
from dotenv import load_dotenv
load_dotenv()
client = openai.OpenAI(api_key=os.environ["OPENAI_API_KEY"])
SYSTEM_PROMPT = """You are a helpful assistant. Be concise and direct.
Answer the user's question, then stop."""
conversation = [{"role": "system", "content": SYSTEM_PROMPT}]
print("Bot ready. Type 'quit' to exit.\n")
while True:
user_input = input("You: ").strip()
if user_input.lower() in ("quit", "exit"):
break
if not user_input:
continue
conversation.append({"role": "user", "content": user_input})
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=conversation,
)
reply = response.choices[0].message.content
conversation.append({"role": "assistant", "content": reply})
print(f"\nBot: {reply}\n")That’s the entire pattern. The conversation list grows with each turn, so the bot remembers context. gpt-4o-mini costs roughly $0.15 per million input tokens — cheap enough to leave running while you build.
Step 3 — Run it
python bot.pyExpected output:
Bot ready. Type 'quit' to exit.
You: What's the difference between a list and a tuple in Python?
Bot: Lists are mutable (you can change them after creation), tuples are not.
Use lists when the contents will change, tuples when they're fixed — like
coordinates or function return values. Tuples are also slightly faster.
You:What to do next
This is the core pattern. If you want a customer support bot, a sales bot, or a social media content bot — those just need a more specific system prompt and a few extra behaviors. The pre-built packs at RoboSmith skip the iteration so you go straight to something production-ready.
Right now: buy any bot pack, get a second one free instantly.