Skip to content

Commit

Permalink
Merge pull request #12 from wkok/override-api-key
Browse files Browse the repository at this point in the history
add support to pass api-key as options
  • Loading branch information
wkok authored Mar 19, 2023
2 parents 39f8779 + eb09e38 commit d6f7add
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 104 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## 0.5.0 - 2023-03-19
### Supported API versions
- OpenAI v1.2.0
- Azure OpenAI 2022-12-01
### Changes
- Support passing `:api-key` and `:impl` as options to api functions
- Deprecate support for passing `:impl` as 2nd argument, while remaining backward compatible.

## 0.4.0 - 2023-03-11
### Supported API versions
- OpenAI v1.2.0
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tools and applications which can work with both variants.
* [Usage - OpenAI](/doc/01-usage-openai.md)
* [Usage - Azure OpenAI](/doc/02-usage-azure.md)
* [Streaming Tokens](/doc/03-streaming.md)
* [API Reference](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api)
* [API Reference](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api)

## Supported APIs

Expand All @@ -42,13 +42,13 @@ Add the `openai-clojure` dependency
### deps.edn

```
net.clojars.wkok/openai-clojure {:mvn/version "0.4.0"}
net.clojars.wkok/openai-clojure {:mvn/version "0.5.0"}
```

### Leiningen project.clj

```
[net.clojars.wkok/openai-clojure "0.4.0"]
[net.clojars.wkok/openai-clojure "0.5.0"]
```

## Java
Expand All @@ -63,6 +63,8 @@ Minimum Java 11 required

Set the environment variable `OPENAI_API_KEY` to your OpenAI API key.

(For alternative options to pass the API Key see [options](/doc/01-usage-openai.md#options))

An API key can be generated in your [OpenAI account](https://platform.openai.com/account/api-keys)

#### Organization
Expand All @@ -75,7 +77,7 @@ See: [Authentication - Azure OpenAI](/doc/02-usage-azure.md#authentication)

## Quickstart

See the full [API Reference](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api) for examples of all the supported OpenAI APIs.
See the full [API Reference](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api) for examples of all the supported OpenAI APIs.

Require the `api` namespace

Expand Down
2 changes: 1 addition & 1 deletion build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(:require [org.corfield.build :as bb]))

(def lib 'net.clojars.wkok/openai-clojure)
(def version "0.4.0")
(def version "0.5.0")

(defn test "Run the tests." [opts]
(bb/run-tests opts))
Expand Down
63 changes: 37 additions & 26 deletions doc/01-usage-openai.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Add the `openai-clojure` dependency
### deps.edn

```
net.clojars.wkok/openai-clojure {:mvn/version "0.4.0"}
net.clojars.wkok/openai-clojure {:mvn/version "0.5.0"}
```

### Leiningen project.clj

```
[net.clojars.wkok/openai-clojure "0.4.0"]
[net.clojars.wkok/openai-clojure "0.5.0"]
```

## Authentication
Expand All @@ -30,9 +30,20 @@ An API key can be generated in your [OpenAI account](https://platform.openai.com

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

### Options

Alternatively the `api-key` and/or `organization` can be passed in the `options` argument of each api function

```
(api/create-completion {:model "text-davinci-003"
:prompt "Say this is a test"}
{:api-key "xxxxx"
:organization "abcd"})
```

## Quickstart

See the full [API Reference](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api) api documentation for examples of all the supported OpenAI APIs.
See the full [API Reference](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api) api documentation for examples of all the supported OpenAI APIs.

Require the `api` namespace

Expand Down Expand Up @@ -70,73 +81,73 @@ Result:

### Models

* [list-models](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#list-models)
* [retrieve-model](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#retrieve-model)
* [list-models](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#list-models)
* [retrieve-model](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#retrieve-model)

Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/models)

### Completions

* [create-completion](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-completion)
* [create-completion](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-completion)

Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/completions)

### Chat

* [create-chat-completion](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-chat-completion)
* [create-chat-completion](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-chat-completion)

Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/chat)

### Edits

* [create-edit](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-edit)
* [create-edit](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-edit)

Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/edits)

### Images

* [create-image](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-image)
* [create-image-edit](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-image-edit)
* [create-image-variation](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-image-variation)
* [create-image](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-image)
* [create-image-edit](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-image-edit)
* [create-image-variation](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-image-variation)

Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/images)

### Embeddings

* [create-embedding](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-embedding)
* [create-embedding](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-embedding)

Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/embeddings)

### Audio

* [create-transcription](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-transcription)
* [create-translation](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-translation)
* [create-transcription](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-transcription)
* [create-translation](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-translation)

Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/audio)

### Files

* [list-files](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#list-files)
* [create-file](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-file)
* [delete-file](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#delete-file)
* [retrieve-file](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#retrieve-file)
* [download-file](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#download-file)
* [list-files](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#list-files)
* [create-file](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-file)
* [delete-file](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#delete-file)
* [retrieve-file](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#retrieve-file)
* [download-file](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#download-file)

Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/files)

### Fine-tunes

* [create-fine-tune](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-fine-tune)
* [list-fine-tunes](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#list-fine-tunes)
* [retrieve-fine-tune](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#retrieve-fine-tune)
* [cancel-fine-tune](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#cancel-fine-tune)
* [list-fine-tune-events](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#list-fine-tune-events)
* [delete-model](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#delete-model)
* [create-fine-tune](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-fine-tune)
* [list-fine-tunes](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#list-fine-tunes)
* [retrieve-fine-tune](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#retrieve-fine-tune)
* [cancel-fine-tune](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#cancel-fine-tune)
* [list-fine-tune-events](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#list-fine-tune-events)
* [delete-model](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#delete-model)

Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/fine-tunes)

### Moderations

* [create-moderation](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-moderation)
* [create-moderation](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-moderation)

Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/moderations)
34 changes: 24 additions & 10 deletions doc/02-usage-azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,41 @@ Add the `openai-clojure` dependency
### deps.edn

```
net.clojars.wkok/openai-clojure {:mvn/version "0.4.0"}
net.clojars.wkok/openai-clojure {:mvn/version "0.5.0"}
```

### Leiningen project.clj

```
[net.clojars.wkok/openai-clojure "0.4.0"]
[net.clojars.wkok/openai-clojure "0.5.0"]
```

## Authentication

### API Key

Set the environment variable `AZURE_OPENAI_API_KEY` to your Azure OpenAI API key.

An API key can be retrieved from your [Azure account](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quickstart?pivots=programming-language-python#retrieve-key-and-endpoint)

## Endpoint
### Endpoint

Set the environment variable `AZURE_OPENAI_API_ENDPOINT` to your [Azure OpenAPI endpoint](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quickstart?pivots=programming-language-python#retrieve-key-and-endpoint), example: *https://myendpoint.openai.azure.com*

### Options

Alternatively the `api-key` can be passed in the `options` argument of each api function

```
(api/create-completion {:model "text-davinci-003"
:prompt "Say this is a test"}
{:api-key "xxxxx"
:impl :azure})
```

## Quickstart

See the full [API Reference](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api) api documentation for examples of all the supported OpenAI APIs.
See the full [API Reference](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api) api documentation for examples of all the supported OpenAI APIs.

Require the `api` namespace

Expand All @@ -41,10 +54,11 @@ Require the `api` namespace
A simple completion prompt could be:

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

Result:
Expand All @@ -65,12 +79,12 @@ Result:

### Completions

* [create-completion](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-completion)
* [create-completion](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-completion)

Also see the [Azure OpenAI documentation](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#completions)

### Embeddings

* [create-embedding](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.4.0/api/wkok.openai-clojure.api#create-embedding)
* [create-embedding](https://cljdoc.org/d/net.clojars.wkok/openai-clojure/0.5.0/api/wkok.openai-clojure.api#create-embedding)

Also see the [Azure OpenAI documentation](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#embeddings)
Loading

0 comments on commit d6f7add

Please sign in to comment.