I wanted a chatbot that runs entirely on my laptop and access it from anywhere from my mobile phone. No API key, no per-token bill, and no prompts leaving the machine. Ollama runs the model, and Flask is the thinnest web layer I know, so the plan looked like an afternoon's work.
It mostly was. But a few things cost me more time than they should have, so here they are, along with the numbers I got when I benchmarked it.
The whole thing is about 100 lines of Python and HTML: ampaslabs/python-flask-ollama-chatbot (MIT).
1. Ollama speaks OpenAI, but only under /v1
Ollama has an OpenAI-compatible API, so you can use the regular openai Python package and switch to a hosted model later by changing one line. My first attempt looked like this:
client = OpenAI ( base_url = " http://localhost:11434 " , api_key = " ollama " )
Enter fullscreen mode
Exit fullscreen mode
All it gave me was:
NotFoundError: Error code: 404
Enter fullscreen mode
Exit fullscreen mode
The OpenAI-compatible routes live under /v1 .…