Clojure and Ollama
Back to Clojure for a bit with this library to access Ollama via my favourite language. Sheer amount of reliable Java+Clojure open source libraries has just made my life easier in the last few weeks.
Basically, Pyjama has full support for all the Ollama API endpoints, generate, chat, pull etc.. you name it.
Right now it is available as a clojure deps library, you can use it in your project, by adding the git coordinates to the deps.edn file.
{
:deps
{hellonico/pyjama {:git/url "https://github.com/hellonico/pyjama.git"
:sha "ec753eebffd422fd2d02eb1c93957a9f8adb0016"}}}
In very simple cases, there is only one function from pyjama.core to remember, ollama, and the easiest way to use is shown in the snippet below.
(require '[pyjama.core] :refer [ollama])
(ollama
"http://localhost:11434"
:generate
{:prompt "What color is the sky at night and why?"})
In the snippet, second parameter keywords like :generate are all one to one mapping to the api endpoints, and the json map that the ollama server is waiting for is directly generated from the edn, with all the same keywords.
Streaming is off by default; if you need streaming at the REPL or CLI level, you can set streaming with a parameter in the map, as shown below:
(pyjama.core/ollama
"http://localhost:11434"
:generate
{:stream true :prompt "What color is the sky at night and why?"})
The short clip below shows the pyjama basics again in video format.