A fully local AI chatbot with conversation memory and a custom personality — powered by Llama 3 running on your own machine, completely free and private.
Download and install Ollama, then pull the Llama 3 model.
# In your terminal — after installing Ollama from ollama.com
ollama pull llama3
# Verify it works
ollama run llama3 "Say hello in one sentence"
Hello! I'm Llama 3, a large language model assistant, here to help you with any questions or tasks you may have.
Call Ollama from Python using the official library.
import ollama
response = ollama.chat(
model='llama3',
messages=[{'role': 'user', 'content': 'What is machine learning in one paragraph?'}]
)
print(response['message']['content'])
Machine learning is a subset of artificial intelligence where systems learn patterns from data...
Keep the conversation history so the AI remembers what was said earlier.
import ollama
SYSTEM = "You are a helpful coding tutor. Explain things clearly with examples."
history = [{"role": "system", "content": SYSTEM}]
print("Local AI Chatbot (type 'quit' to exit)\n")
while True:
user_input = input("You: ").strip()
if user_input.lower() in ("quit", "exit"):
break
history.append({"role": "user", "content": user_input})
response = ollama.chat(model="llama3", messages=history)
reply = response["message"]["content"]
history.append({"role": "assistant", "content": reply})
print(f"\nBot: {reply}\n")
Local AI Chatbot (type 'quit' to exit) You: What is a Python list? Bot: A Python list is an ordered, mutable collection... You: Can you give me an example? Bot: Sure! Here's a simple example: list = [1, 2, 3]...
Your chatbot runs 100% locally — no data leaves your machine. Swap in any model from the Ollama library at ollama.com/library.
Spotted a bug, broken code, or something that doesn't look right? Tell us what's off and we'll fix it.