Menu

I built a private ChatGPT with Flask and Ollama. Here's what tripped me up.
📰

I built a private ChatGPT with Flask and Ollama. Here's what tripped me up.

DEV Community: flask·gvelrajan·8 days ago
#H0gVTany
#devtoflask#devto#dev#ollama#flask
Reading 0:00
15s threshold

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 .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.