Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

* Add support for `Audio` requests (#9)
* Implemented `auth-source` and add arguments for `content-type` and `org-id` (#13)
* Add `openai-base-url` variable that configures the Open AI API endpoint base-url (#15)

## 0.1.0
> Released N/A
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ For requests that need your user identifier,
(setq openai-user "[YOUR USER UID]")
```

For using another OpenAI endpoint,

```elisp
(setq openai-base-url "[OPENAI BASE URL]")
```

> 💡 Tip
>
> The two variables `openai-key` and `openai-user` are the default values for
Expand Down
10 changes: 6 additions & 4 deletions openai-audio.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
;;;###autoload
(cl-defun openai-audio-create-transcription ( file callback
&key
(base-url openai-base-url)
(content-type "application/json")
(key openai-key)
org-id
Expand All @@ -48,13 +49,13 @@ Argument FILE is audio file to transcribe, in one of these formats: mp3, mp4,
mpeg, mpga, m4a, wav, or webm. CALLBACK is the execuation after request is
made.

Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you
Arguments BASE-URL, CONTENT-TYPE, KEY and ORG-ID are global options; however, you
can overwrite the value by passing it in.

The rest of the arugments are optional, please see OpenAI API reference page
for more information. Arguments here refer to MODEL PROMPT, RESPONSE-FORMAT,
TEMPERATURE, and LANGUAGE."
(openai-request "https://api.openai.com/v1/audio/transcriptions"
(openai-request (concat base-url "/audio/transcriptions")
:type "POST"
:headers (openai--headers content-type key org-id)
:data (openai--json-encode
Expand All @@ -72,6 +73,7 @@ TEMPERATURE, and LANGUAGE."
;;;###autoload
(cl-defun openai-audio-create-translation ( file callback
&key
(base-url openai-base-url)
(content-type "application/json")
(key openai-key)
org-id
Expand All @@ -85,13 +87,13 @@ Argument FILE is the audio file to translate, in one of these formats: mp3, mp4,
mpeg, mpga, m4a, wav, or webm. CALLBACK is the execuation after request is
made.

Arguments CONTENT-TYPE, KEY and ORG-ID are global options; however, you
Arguments BASE-URL, CONTENT-TYPE, KEY and ORG-ID are global options; however, you
can overwrite the value by passing it in.

The rest of the arugments are optional, please see OpenAI API reference page
for more information. Arguments here refer to MODEL PROMPT, RESPONSE-FORMAT,
and TEMPERATURE."
(openai-request "https://api.openai.com/v1/audio/transcriptions"
(openai-request (concat base-url "/audio/translations")
:type "POST"
:headers (openai--headers content-type key org-id)
:data (openai--json-encode
Expand Down
7 changes: 4 additions & 3 deletions openai-chat.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
;;;###autoload
(cl-defun openai-chat ( messages callback
&key
(base-url openai-base-url)
(content-type "application/json")
(key openai-key)
org-id
Expand All @@ -53,13 +54,13 @@
Arguments MESSAGES and CALLBACK are required for this type of request. MESSAGES
is the conversation data. CALLBACK is the execuation after request is made.

Arguments CONTENT-TYPE, KEY, ORG-ID and USER are global options; however, you
Arguments BASE-URL, CONTENT-TYPE, KEY, ORG-ID and USER are global options; however, you
can overwrite the value by passing it in.

The rest of the arugments are optional, please see OpenAI API reference page
for more information. Arguments here refer to MODEL, TEMPERATURE, TOP-P, N,
STREAM, STOP, MAX-TOKENS, PRESENCE-PENALTY, FREQUENCY-PENALTY, and LOGIT-BIAS."
(openai-request "https://api.openai.com/v1/chat/completions"
(openai-request (concat base-url "/chat/completions")
:type "POST"
:headers (openai--headers content-type key org-id)
:data (openai--json-encode
Expand Down Expand Up @@ -113,7 +114,7 @@ This is a ping pong message, so you will only get one response."
:max-tokens openai-chat-max-tokens
:temperature openai-chat-temperature
:user (unless (string= user "user") user))
(user-error "Abort, canecel chat operation")))
(user-error "Abort, cancel chat operation")))

(provide 'openai-chat)
;;; openai-chat.el ends here
5 changes: 3 additions & 2 deletions openai-completion.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
;;;###autoload
(cl-defun openai-completion ( prompt callback
&key
(base-url openai-base-url)
(content-type "application/json")
(key openai-key)
org-id
Expand All @@ -58,14 +59,14 @@ Arguments PROMPT and CALLBACK are required for this type of request. PROMPT is
either the question or instruction to OpenAI. CALLBACK is the execuation after
request is made.

Arguments CONTENT-TYPE, KEY, ORG-ID and USER are global options; however, you
Arguments BASE-URL, CONTENT-TYPE, KEY, ORG-ID and USER are global options; however, you
can overwrite the value by passing it in.

The rest of the arugments are optional, please see OpenAI API reference page
for more information. Arguments here refer to MODEL, SUFFIX, MAX-TOKENS,
TEMPERATURE, TOP-P, N, STREAM, LOGPROBS, ECHO, STOP, PRESENCE-PENALTY,
FREQUENCY-PENALTY, BEST-OF, and LOGIT-BIAS."
(openai-request "https://api.openai.com/v1/completions"
(openai-request (concat base-url "/completions")
:type "POST"
:headers (openai--headers content-type key org-id)
:data (openai--json-encode
Expand Down
9 changes: 5 additions & 4 deletions openai-edit.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

(cl-defun openai-edit-create ( input instruction callback
&key
(base-url openai-base-url)
(content-type "application/json")
(key openai-key)
org-id
Expand All @@ -46,15 +47,15 @@
The INPUT is text to use as a starting point for the edit. The INSTRUCTION that
tells the model how to edit the prompt.

The argument CALLBACK is execuated after request is made.
The argument CALLBACK is executed after request is made.

Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you
Arguments BASE-URL, CONTENT-TYPE, KEY and ORG-ID are global options; however, you
can overwrite the value by passing it in.

The rest of the arugments are optional, please see OpenAI API reference page
The rest of the arguments are optional, please see OpenAI API reference page
for more information. Arguments here refer to MODEL, TEMPERATURE, TOP-P, and
N."
(openai-request "https://api.openai.com/v1/edits"
(openai-request (concat base-url "/edits")
:type "POST"
:headers (openai--headers content-type key org-id)
:data (openai--json-encode
Expand Down
9 changes: 5 additions & 4 deletions openai-embedding.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

(cl-defun openai-embedding-create ( input callback
&key
(base-url openai-base-url)
(content-type "application/json")
(key openai-key)
org-id
Expand All @@ -46,14 +47,14 @@ To get embeddings for multiple inputs in a single request, pass an array of
strings or array of token arrays. Each input must not exceed 8192 tokens in
length.

The argument CALLBACK is execuated after request is made.
The argument CALLBACK is executed after the request is made.

Arguments CONTENT-TYPE, KEY, ORG-ID and USER are global options; however, you
Arguments BASE-URL, CONTENT-TYPE, KEY, ORG-ID and USER are global options; however, you
can overwrite the value by passing it in.

The rest of the arugments are optional, please see OpenAI API reference page
The rest of the arguments are optional, please see OpenAI API reference page
for more information. Arguments here refer to MODEL."
(openai-request "https://api.openai.com/v1/embeddings"
(openai-request (concat base-url "/embeddings")
:type "POST"
:headers (openai--headers content-type key org-id)
:data (openai--json-encode
Expand Down
10 changes: 6 additions & 4 deletions openai-engine.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

(cl-defun openai-engine-list ( callback
&key
(base-url openai-base-url)
(content-type "application/json")
(key openai-key)
org-id)
Expand All @@ -44,9 +45,9 @@ information about each one such as the owner and availability.

The argument CALLBACK is execuated after request is made.

Arguments CONTENT-TYPE, KEY, ORG-ID and USER are global options; however, you
Arguments BASE-URL, CONTENT-TYPE, KEY and ORG-ID are global options; however, you
can overwrite the value by passing it in."
(openai-request "https://api.openai.com/v1/engines"
(openai-request (concat base-url "/engines")
:type "GET"
:headers (openai--headers content-type key org-id)
:parser 'json-read
Expand All @@ -56,6 +57,7 @@ can overwrite the value by passing it in."

(cl-defun openai-engine-retrieve ( engine-id callback
&key
(base-url openai-base-url)
(content-type "application/json")
(key openai-key)
org-id)
Expand All @@ -66,9 +68,9 @@ The argument ENGINE-ID is the engine to use for this request.

The argument CALLBACK is execuated after request is made.

Arguments CONTENT-TYPE, KEY, ORG-ID and USER are global options; however, you
Arguments BASE-URL, CONTENT-TYPE, KEY and ORG-ID are global options; however, you
can overwrite the value by passing it in."
(openai-request (format "https://api.openai.com/v1/engines/%s" engine-id)
(openai-request (format "%s/engines/%s" base-url engine-id)
:type "GET"
:headers (openai--headers content-type key org-id)
:parser 'json-read
Expand Down
25 changes: 15 additions & 10 deletions openai-file.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@

(cl-defun openai-file-list ( callback
&key
(base-url openai-base-url)
(content-type "application/json")
(key openai-key)
org-id)
"Return a list of files that belong to the user's organization.

The argument CALLBACK is execuated after request is made.

Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you
Arguments BASE-URL, CONTENT-TYPE, KEY and ORG-ID are global options; however, you
can overwrite the value by passing it in."
(openai-request "https://api.openai.com/v1/files"
(openai-request (concat base-url "/files")
:type "GET"
:headers (openai--headers content-type key org-id)
:parser 'json-read
Expand All @@ -53,6 +54,7 @@ can overwrite the value by passing it in."

(cl-defun openai-file-upload ( file purpose callback
&key
(base-url openai-base-url)
(content-type "application/json")
(key openai-key)
org-id)
Expand All @@ -71,9 +73,9 @@ uploaded file.

Argument CALLBACK is function with data pass in.

Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you
Arguments BASE-URL, CONTENT-TYPE, KEY and ORG-ID are global options; however, you
can overwrite the value by passing it in."
(openai-request "https://api.openai.com/v1/files"
(openai-request (concat base-url "/files")
:type "POST"
:headers (openai--headers content-type key org-id)
:data (openai--json-encode
Expand All @@ -86,6 +88,7 @@ can overwrite the value by passing it in."

(cl-defun openai-file-delete ( file-id callback
&key
(base-url openai-base-url)
(content-type "application/json")
(key openai-key)
org-id)
Expand All @@ -95,9 +98,9 @@ The arument FILE-ID is id of the file to use for this request.

Argument CALLBACK is function with data pass in.

Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you
Arguments BASE-URL, CONTENT-TYPE, KEY and ORG-ID are global options; however, you
can overwrite the value by passing it in."
(openai-request "https://api.openai.com/v1/files"
(openai-request (concat base-url "/files")
:type "DELETE"
:headers (openai--headers content-type key org-id)
:data (openai--json-encode
Expand All @@ -109,6 +112,7 @@ can overwrite the value by passing it in."

(cl-defun openai-file-retrieve ( file-id callback
&key
(base-url openai-base-url)
(content-type "application/json")
(key openai-key)
org-id)
Expand All @@ -118,9 +122,9 @@ The arument FILE-ID is id of the file to use for this request.

The argument CALLBACK is execuated after request is made.

Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you
Arguments BASE-URL, CONTENT-TYPE, KEY and ORG-ID are global options; however, you
can overwrite the value by passing it in."
(openai-request (format "https://api.openai.com/v1/files/%s" file-id)
(openai-request (format "%s/files/%s" base-url file-id)
:type "GET"
:headers (openai--headers content-type key org-id)
:data (openai--json-encode
Expand All @@ -132,6 +136,7 @@ can overwrite the value by passing it in."

(cl-defun openai-file-retrieve-content ( file-id callback
&key
(base-url openai-base-url)
(content-type "application/json")
(key openai-key)
org-id)
Expand All @@ -142,9 +147,9 @@ The arument FILE-ID is id of the file to use for this request.
The argument CALLBACK is execuated after request is made.


Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you
Arguments BASE-URL, CONTENT-TYPE, KEY and ORG-ID are global options; however, you
can overwrite the value by passing it in."
(openai-request (format "https://api.openai.com/v1/files/%s/content" file-id)
(openai-request (format "%s/files/%s/content" base-url file-id)
:type "GET"
:headers (openai--headers content-type key org-id)
:data (openai--json-encode
Expand Down
Loading