ClojureScript and Ollama
This an experiment to reuse the same principles for accessing Ollama via Clojure, this time with ClojureScript.
Basic routing diagram to show the request going from the browser all the way to the ollama model.
There is a quick preparation for this to work, with the need for a nginx proxy setup to get the CORS headers working properly.
The core of the ClojureScript implementation wrapper code works the same as the Clojure original Pyjama implementation, with defaults to access all the different Ollama API endpoints.
To generate a message to ollama you basically would have an async go block like this:
(go
(let [res (pyjama.core/ollama
"http://localhost:8888"
:generate
{:prompt (:prompt @state) :model (:model @state)}
:response)]
(swap! state assoc :response (str (<! res)))))
Obviously you can put the URL in a state as well, and update as needed.
The result of the model generation is then return and read asynchronously and the code updates the app state atom via the atom.
For quick react-like rendering, reagent was used.
This integration supports all the ollama models, and the hyped deepseek runs effortlessly.
The code for this one-page app and the setup for pyjama-cljs is on github