Liking cljdoc? Tell your friends :D

Usage - OpenAI

Clojure functions to drive the OpenAI API

Configuration

Add the openai-clojure dependency

deps.edn

net.clojars.wkok/openai-clojure {:mvn/version "0.3.1"}

Leiningen project.clj

[net.clojars.wkok/openai-clojure "0.3.1"]

Authentication

API Key

Set the environment variable OPENAI_API_KEY to your OpenAI API key.

An API key can be generated in your OpenAI account

Organization

Optional - If your OpenAI account uses multiple organizations, set the environment variable OPENAI_ORGANIZATION to the one used for your app.

Quickstart

See the full API Reference api documentation for examples of all the supported OpenAI APIs.

Require the api namespace

(:require [wkok.openai-clojure.api :as api])

A simple completion prompt could be:

(api/create-completion {:model "text-davinci-003"
                        :prompt "Say this is a test"
                        :max_tokens 7
                        :temperature 0})

Result:

{:id "cmpl-6jY1xInJeGGpzUgsZtkuxDsf5DdBa",
 :object "text_completion",
 :created 1676313593,
 :model "text-davinci-003",
 :choices
 [{:text "\n\nThis is indeed a test",
   :index 0,
   :logprobs nil,
   :finish_reason "length"}],
 :usage {:prompt_tokens 5, :completion_tokens 7, :total_tokens 12}}

Supported OpenAI APIs

Models

Also see the OpenAI documentation

Completions

Also see the OpenAI documentation

Edits

Also see the OpenAI documentation

Images

Also see the OpenAI documentation

Embeddings

Also see the OpenAI documentation

Files

Also see the OpenAI documentation

Fine-tunes

Also see the OpenAI documentation

Moderations

Also see the OpenAI documentation

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close