https://github.com/atgreen/cl-completions
A Common Lisp LLM completions library
https://github.com/atgreen/cl-completions
Last synced: 2 months ago
JSON representation
A Common Lisp LLM completions library
- Host: GitHub
- URL: https://github.com/atgreen/cl-completions
- Owner: atgreen
- Created: 2024-03-27T11:38:23.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-05-17T11:00:48.000Z (12 months ago)
- Last Synced: 2024-05-17T12:24:53.260Z (12 months ago)
- Language: Common Lisp
- Size: 40 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- trackawesomelist - cl-completions (⭐17) - LLM completions. (Recently Updated / [Mar 08, 2025](/content/2025/03/08/README.md))
README
# cl-completions
> A Common Lisp LLM completions libraryUsage
------`cl-completions` is available via [ocicl](https://github.com/ocicl/ocicl). Install it like so:
```
$ ocicl install completions
````cl-completions` supports [ollama](https://ollama.com/), [OpenAI](https://openai.com/blog/openai-api), and [Anthropic](https://anthropic.com/api) APIs.
To use the ollama API:
```
(let ((completer (make-instance 'ollama-completer :model "mistral:latest")))
(get-completion completer "It's a beautiful day for " 100))
```To use the OpenAI API:
```
(let ((completer (make-instance 'openai-completer :api-key (uiop:getenv "OPENAI_API_KEY"))))
(get-completion completer "It's a beautiful day for " 100))
```To use the Anthropic API:
```
(let ((completer (make-instance 'anthropic-completer :api-key (uiop:getenv "ANTHROPIC_API_KEY"))))
(get-completion completer "It's a beautiful day for " 100))
```In addition, the OpenAI completer supports callback functions, like so:
```
(defun-tool time-of-day ()
"Useful if you want to know what time it is."
(let ((decoded-time (multiple-value-list (get-decoded-time))))
(format nil "Current time: ~2,'0D:~2,'0D:~2,'0D~%"
(third decoded-time)
(second decoded-time)
(first decoded-time))))(defun-tool get-temperature ((location string "Where to get the temperature for."))
"Get the temperature for a specific location"
(cond
((equal location "Toronto")
"cold")
(t "warm")))(let ((c (make-instance 'openai-completer
:api-key (uiop:getenv "OPENAI_API_KEY")
:tools '(time-of-day get-temperature))))
(get-completion c "I'm in Toronto. What's the time and temperature here?" 20))
```This code generates output like:
```
The current time in Toronto is 20:01:22 and it's cold there right now
```The default read timeout for a response from the completer is 120
seconds. You can modify this by setting `completions:*read-timeout*`
to a new value.Related Projects
-----------------Related projects include:
* [cl-text-splitter](https://github.com/atgreen/cl-text-splitter): a text splitting library
* [cl-embeddings](https://github.com/atgreen/cl-embeddings): an LLM embeddings library
* [cl-chroma](https://github.com/atgreen/cl-chroma): for a Lisp interface to the [Chroma](https://www.trychroma.com/) vector database.
* [cl-chat](https://github.com/atgreen/cl-chat): a wrapper around `completions` to maintain chat history,Author and License
-------------------``cl-completions`` was written by [Anthony
Green](https://github.com/atgreen) and is distributed under the terms
of the MIT license.