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:
- config map
- prompt string
Example usage:
(ai/completions {:api-key api-key, :base-url base-url}
"hello")Function parameters:
- config map
- vector of message objects
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:
:api-key- mandatory, managed here:base-url- optional, defaults tohttps://api.openai.com/v1
Example:
{:error
{:message "Incorrect API key provided."
:type "invalid_request_error"
:param nil
:code "invalid_api_key"}}When introducing a new version, bump the version number in build.clj. After it's merged into master branch, create a git tag on the last commit and push the tag, it will trigger deploy to Clojars.
There are utility scripts in the bin/ directory for some common tasks:
./bin/nreplstarts nREPL./bin/testruns all tests (accepts all -X arguments, docs)./bin/test-ns clj-openai.core-testruns tests in a single namespace./bin/test-var clj-openai.core-test/completionruns a single test./bin/lintruns kondo and eastwood./bin/coverageruns test coverage check./bin/cirun the project's CI pipeline and builds a jar./bin/local-installinstalls the jar into local maven repo./bin/deploydeploys the jar to clojars,CLOJARS_USERNAMEandCLOJARS_PASSWORDenv vars must be set
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.