How to Build a Local AI Chatbot in Python (Ollama, Free & Offline) | Tamil
Tamil Tech Lab
0:00 / 0:00
How to Build a Local AI Chatbot in Python (Ollama, Free & Offline) | Tamil
81 просмотр · 13 дн. назад
Tamil Tech Lab
5 подписчиков
81 просмотр · 13 дн. назад
Ollama Python Tutorial: In this video, you'll build a free AI chatbot in Python using Ollama and Llama. It runs locally on your own computer, works offline, and needs no API key. You'll also learn how AI chatbot memory really works, and why the AI forgets everything unless your code sends the chat history back.
Ollama Setup Local - • Build ChatGPT's Typing Effect in Python (F...
🔧 WHAT YOU'LL LEARN
How to run an LLM locally with Ollama
How to build an AI chatbot in Python in about 10 lines
How chatbot memory works (the "history" list)
How to prove the AI forgets when the history is cleared
import json
import ollama
MODEL = "llama3.2" # use your exact model name from `ollama list`
history = []
print("Commands: /history = show memory | /forget = clear memory | quit = exit")
while True:
user = input("\nYou: ")
if user.lower() in ("quit", "exit"):
break
if user == "/history":
print(json.dumps(history, indent=2))
continue
if user == "/forget":
history.clear()
print("Memory cleared.")
continue
history.append({"role": "user", "content": user})
print(f"[Sending {len(history)} message(s) to the model]")
response = ollama.chat(model=MODEL, messages=history)
reply = response["message"]["content"]
history.append({"role": "assistant", "content": reply})
print("AI:", reply)