|
| 1 | +# Usage - OpenAI |
| 2 | + |
| 3 | +Clojure functions to drive the [OpenAI API](https://platform.openai.com/docs/introduction) |
| 4 | + |
| 5 | +## Configuration |
| 6 | + |
| 7 | +Add the `openai-clojure` dependency |
| 8 | + |
| 9 | +### deps.edn |
| 10 | + |
| 11 | +``` |
| 12 | +net.clojars.wkok/openai-clojure {:mvn/version "0.3.1"} |
| 13 | +``` |
| 14 | + |
| 15 | +### Leiningen project.clj |
| 16 | + |
| 17 | +``` |
| 18 | +[net.clojars.wkok/openai-clojure "0.3.1"] |
| 19 | +``` |
| 20 | + |
| 21 | +## Authentication |
| 22 | + |
| 23 | +### API Key |
| 24 | + |
| 25 | +Set the environment variable `OPENAI_API_KEY` to your OpenAI API key. |
| 26 | + |
| 27 | +An API key can be generated in your [OpenAI account](https://platform.openai.com/account/api-keys) |
| 28 | + |
| 29 | +### Organization |
| 30 | + |
| 31 | +*Optional* - If your OpenAI account uses multiple organizations, set the environment variable `OPENAI_ORGANIZATION` to the one used for your app. |
| 32 | + |
| 33 | +## Quickstart |
| 34 | + |
| 35 | +See the full [API Reference](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api) api documentation for examples of all the supported OpenAI APIs. |
| 36 | + |
| 37 | +Require the `api` namespace |
| 38 | + |
| 39 | +``` |
| 40 | +(:require [wkok.openai-clojure.api :as api]) |
| 41 | +``` |
| 42 | + |
| 43 | +A simple completion prompt could be: |
| 44 | + |
| 45 | +``` |
| 46 | +(api/create-completion {:model "text-davinci-003" |
| 47 | + :prompt "Say this is a test" |
| 48 | + :max_tokens 7 |
| 49 | + :temperature 0}) |
| 50 | +``` |
| 51 | + |
| 52 | +Result: |
| 53 | +``` |
| 54 | +{:id "cmpl-6jY1xInJeGGpzUgsZtkuxDsf5DdBa", |
| 55 | + :object "text_completion", |
| 56 | + :created 1676313593, |
| 57 | + :model "text-davinci-003", |
| 58 | + :choices |
| 59 | + [{:text "\n\nThis is indeed a test", |
| 60 | + :index 0, |
| 61 | + :logprobs nil, |
| 62 | + :finish_reason "length"}], |
| 63 | + :usage {:prompt_tokens 5, :completion_tokens 7, :total_tokens 12}} |
| 64 | +``` |
| 65 | + |
| 66 | +## Supported OpenAI APIs |
| 67 | + |
| 68 | +### Models |
| 69 | + |
| 70 | +* [list-models](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#list-models) |
| 71 | +* [retrieve-model](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#retrieve-model) |
| 72 | + |
| 73 | +Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/models) |
| 74 | + |
| 75 | +### Completions |
| 76 | + |
| 77 | +* [create-completion](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#create-completion) |
| 78 | + |
| 79 | +Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/completions) |
| 80 | + |
| 81 | +### Edits |
| 82 | + |
| 83 | +* [create-edit](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#create-edit) |
| 84 | + |
| 85 | +Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/edits) |
| 86 | + |
| 87 | +### Images |
| 88 | + |
| 89 | +* [create-image](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#create-image) |
| 90 | +* [create-image-edit](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#create-image-edit) |
| 91 | +* [create-image-variation](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#create-image-variation) |
| 92 | + |
| 93 | +Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/images) |
| 94 | + |
| 95 | +### Embeddings |
| 96 | + |
| 97 | +* [create-embedding](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#create-embedding) |
| 98 | + |
| 99 | +Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/embeddings) |
| 100 | + |
| 101 | +### Files |
| 102 | + |
| 103 | +* [list-files](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#list-files) |
| 104 | +* [create-file](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#create-file) |
| 105 | +* [delete-file](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#delete-file) |
| 106 | +* [retrieve-file](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#retrieve-file) |
| 107 | +* [download-file](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#download-file) |
| 108 | + |
| 109 | +Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/files) |
| 110 | + |
| 111 | +### Fine-tunes |
| 112 | + |
| 113 | +* [create-fine-tune](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#create-fine-tune) |
| 114 | +* [list-fine-tunes](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#list-fine-tunes) |
| 115 | +* [retrieve-fine-tune](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#retrieve-fine-tune) |
| 116 | +* [cancel-fine-tune](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#cancel-fine-tune) |
| 117 | +* [list-fine-tune-events](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#list-fine-tune-events) |
| 118 | +* [delete-model](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#delete-model) |
| 119 | + |
| 120 | +Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/fine-tunes) |
| 121 | + |
| 122 | +### Moderations |
| 123 | + |
| 124 | +* [create-moderation](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.3.1/api/wkok.openai-clojure.api#create-moderation) |
| 125 | + |
| 126 | +Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/moderations) |
0 commit comments