A simple ChatGPT client for Clojure.
(require '[clj-openai.core :as ai])
clj-openai
provides 2 functions: completions
and chat-completions
. They both take config map as first argument. They both return string on success and error map on failure.
Function parameters:
Example usage:
(ai/completions {:api-key api-key, :base-url base-url}
"hello")
Function parameters:
Example usage:
(ai/chat-completions {:api-key api-key, :base-url base-url}
[{:role "user", :content "hello"}])
Config map is passed as first argument to all provided functions. Available config keys:
https://api.openai.com/v1
Example:
{:error
{:message "Incorrect API key provided."
:type "invalid_request_error"
:param nil
:code "invalid_api_key"}}
Start nREPL:
$ ./bin/nrepl
Run the project's tests (accepts all -X arguments, docs):
$ ./bin/test
Run tests in single namespace:
$ ./bin/test-ns clj-openai.core-test
Run a single test:
$ ./bin/test-var clj-openai.core-test/completion
Run the project's CI pipeline and build a jar:
$ ./bin/ci
Install the jar locally:
$ clj -T:build local-install
Deploy the jar to clojars ('CLOJARS_USERNAME' and 'CLOJARS_PASSWORD' env vars must be set):
$ ./bin/deploy
Copyright © 2023 Staifa
EPLv1.0 is just the default for projects generated by deps-new
: you are not
required to open source this project, nor are you required to use EPLv1.0!
Feel free to remove or change the LICENSE
file and remove or update this
section of the README.md
file!
Distributed under the Eclipse Public License version 1.0.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close