Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vollcheck/ollama-clj
Ollama Clojure library
https://github.com/vollcheck/ollama-clj
clojure gpt ollama
Last synced: 4 months ago
JSON representation
Ollama Clojure library
- Host: GitHub
- URL: https://github.com/vollcheck/ollama-clj
- Owner: vollcheck
- License: mit
- Created: 2024-02-10T09:40:22.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-07-04T20:35:16.000Z (7 months ago)
- Last Synced: 2024-09-29T17:22:30.956Z (5 months ago)
- Topics: clojure, gpt, ollama
- Language: Clojure
- Homepage:
- Size: 37.1 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ollama-clj
## NOTE: Work in progress!
Use [`ollama`](https://ollama.com) within Clojure project.
## Usage
```clojure
(require '[ollama-clj.core :as o])(def client (o/->Client "http://localhost:11434"))
(def messages
[{:role "user"
:content "Why is the sky blue?"}])(-> (o/chat client "mistral" messages)
:message
:content)
```or with streaming option:
```clojure
(require '[ollama-clj.core :as o])(def client (o/->Client "http://localhost:11434"))
(def messages
[{:role "user"
:content "Why is the sky blue?"}]);; note the streaming flag!
(doseq [part (o/chat client "mistral" messages {:stream true})]
(print (-> part :message :content)))
```For more usages reach out to `examples/` directory.
### Internals
### Implement your own client
If you want to gain control over the way of executing `ollama` calls, you can implement your own client simply by using record and protocol like so:
```clojure
(defrecord MyClient [url]
o/BaseClient
(request [_this method endpoint opts]
:perform-request)(stream [_this method endpoint opts]
:perform-streaming)(request-stream [this method endpoint {:keys [stream?] :as opts}]
(if stream?
(.stream this method endpoint opts)
(.request this method endpoint opts))))
```## References
- https://ollama.com
- https://github.com/ollama/ollama-python - Python library for ollama (big inspiration for this project)
- https://github.com/clj-commons/manifold/blob/master/doc/stream.md - aleph/manifold streaming docs