From 650c8b108c52503bb6c881d020f1094e94f40741 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:01:59 +0200 Subject: [PATCH 01/27] Add open ai base url variable --- openai.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/openai.el b/openai.el index f418a1e..8bf2f94 100644 --- a/openai.el +++ b/openai.el @@ -82,6 +82,9 @@ auth-source is provided for convenience.") "A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.") +(defvar openai-base-url "https://api.openai.com/v1" + "The base URL for OpenAI API requests.") + (defun openai--resolve-key (key) "If the given KEY is a function call it and return the result, otherwise return KEY." From d65e63a9c7a1552e13e5b36dfa73c9067d129bde Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:02:17 +0200 Subject: [PATCH 02/27] Use base url in embedding --- openai-embedding.el | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/openai-embedding.el b/openai-embedding.el index 87abf9d..8f063fb 100644 --- a/openai-embedding.el +++ b/openai-embedding.el @@ -32,13 +32,14 @@ ;; ;;; API -(cl-defun openai-embedding-create ( input callback - &key - (content-type "application/json") - (key openai-key) - org-id - (model "text-embedding-ada-002") - (user openai-user)) +(cl-defun openai-embedding-create (input callback + &key + (content-type "application/json") + (key openai-key) + org-id + (model "text-embedding-ada-002") + (user openai-user) + (base-url openai-base-url)) "Create an embedding vector representing the input text. INPUT text to get embeddings for, encoded as a string or array of tokens. @@ -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 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 From 2d3797fb0fa0b2ed9df8964800fbe5cbb204ed4e Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:16:10 +0200 Subject: [PATCH 03/27] Use base url in audio.el --- openai-audio.el | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/openai-audio.el b/openai-audio.el index f9ed72f..80f070d 100644 --- a/openai-audio.el +++ b/openai-audio.el @@ -41,20 +41,21 @@ prompt response-format temperature - language) + language + (base-url openai-base-url)) "Send transcribe audio request. 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 CONTENT-TYPE, KEY, ORG-ID, and BASE-URL 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 @@ -78,20 +79,21 @@ TEMPERATURE, and LANGUAGE." (model "whisper-1") prompt response-format - temperature) + temperature + (base-url openai-base-url)) "Send translate audio request. 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 CONTENT-TYPE, KEY, ORG-ID, and BASE-URL 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 From 6419eefca13cfed29d54e0b7ff40ed5d5355e12a Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:19:07 +0200 Subject: [PATCH 04/27] Add base url to chat --- openai-chat.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openai-chat.el b/openai-chat.el index b4d586b..1141479 100644 --- a/openai-chat.el +++ b/openai-chat.el @@ -47,7 +47,8 @@ presence-penalty frequency-penalty logit-bias - (user openai-user)) + (user openai-user) + (base-url openai-base-url)) "Send chat request. Arguments MESSAGES and CALLBACK are required for this type of request. MESSAGES @@ -59,7 +60,7 @@ 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 From 34cb355a26cffb1c6193aa2e5cd6bd335193e9a1 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:20:44 +0200 Subject: [PATCH 05/27] Add base url to completion --- openai-completion.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openai-completion.el b/openai-completion.el index 58c5bd9..7d5128e 100644 --- a/openai-completion.el +++ b/openai-completion.el @@ -51,7 +51,8 @@ frequency-penalty best-of logit-bias - (user openai-user)) + (user openai-user) + (base-url openai-base-url)) "Send completion request. Arguments PROMPT and CALLBACK are required for this type of request. PROMPT is @@ -65,7 +66,7 @@ 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 From 5f235a0299d3e62d66b97aa931e6d8e33ffeba2c Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:24:12 +0200 Subject: [PATCH 06/27] Use base url in edit --- openai-edit.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/openai-edit.el b/openai-edit.el index a4fa403..ee91bb4 100644 --- a/openai-edit.el +++ b/openai-edit.el @@ -40,21 +40,22 @@ (model "text-davinci-edit-001") temperature top-p - n) + n + (base-url openai-base-url)) "Create a new edit for the provided input, instruction, and parameters. 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 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 From f85fd16c31ccfc9a5bea8591df3b702fa91c241c Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:26:46 +0200 Subject: [PATCH 07/27] Use baseurl in engine --- openai-engine.el | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/openai-engine.el b/openai-engine.el index ca9c412..8762bed 100644 --- a/openai-engine.el +++ b/openai-engine.el @@ -38,15 +38,16 @@ &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "Lists the currently available (non-finetuned) models, and provides basic 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 CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 @@ -58,7 +59,8 @@ can overwrite the value by passing it in." &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "Retrieves a model instance, providing basic information about it such as the owner and availability. @@ -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 CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 From 9394f9b802cf6a1b9dde4646305088f9d7fdab79 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:31:20 +0200 Subject: [PATCH 08/27] Add base-url to file --- openai-file.el | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/openai-file.el b/openai-file.el index a7f6f0e..f061786 100644 --- a/openai-file.el +++ b/openai-file.el @@ -36,14 +36,15 @@ &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "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 CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 @@ -55,7 +56,8 @@ can overwrite the value by passing it in." &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "Upload a file that contain document(s) to be used across various endpoints/features. @@ -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 CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 @@ -88,16 +90,17 @@ can overwrite the value by passing it in." &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "Delete a file. 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 CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 @@ -111,16 +114,17 @@ can overwrite the value by passing it in." &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "Return information about a specific file. 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 CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 @@ -134,7 +138,8 @@ can overwrite the value by passing it in." &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "Return the contents of the specified file The arument FILE-ID is id of the file to use for this request. @@ -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 CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 From 3f8380d56bd1c7e87d7683d69470edb845d1cdfe Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:35:46 +0200 Subject: [PATCH 09/27] Use base url in fine-tune --- openai-fine-tune.el | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/openai-fine-tune.el b/openai-fine-tune.el index 42b704b..42c00af 100644 --- a/openai-fine-tune.el +++ b/openai-fine-tune.el @@ -46,7 +46,8 @@ classification-n-classes classification-positive-class classification-betas - suffix) + suffix + (base-url openai-base-url)) "Create a job that fine-tunes a specified model from a given dataset. Response includes details of the enqueued job including job status and the name @@ -64,8 +65,8 @@ The rest of the arugments are optional, please see OpenAI API reference page for more information. Arguments here refer to MODEL, VALIDATION-FILE, N-EPOCHS, BATCH-SIZE, LEARNING-RATE-MULTIPLIER, PROMPT-LOSS-WEIGHT, COMPUTE-CLASSIFICATION-METRICS, CLASSIFICATION-N-CLASSES, -CLASSIFICATION-POSITIVE-CLASS, CLASSIFICATION-BETAS, and SUFFIX" - (openai-request "https://api.openai.com/v1/fine-tunes" +CLASSIFICATION-POSITIVE-CLASS, CLASSIFICATION-BETAS, SUFFIX and BASE-URL" + (openai-request (concat base-url "/fine-tunes") :type "POST" :headers (openai--headers content-type key org-id) :data (openai--json-encode @@ -90,14 +91,15 @@ CLASSIFICATION-POSITIVE-CLASS, CLASSIFICATION-BETAS, and SUFFIX" &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "List your organization's fine-tuning jobs. The argument CALLBACK is execuated after request is made. -Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you +Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL are global options; however, you can overwrite the value by passing it in." - (openai-request "https://api.openai.com/v1/fine-tunes" + (openai-request (concat base-url "/fine-tunes") :type "GET" :headers (openai--headers content-type key org-id) :parser 'json-read @@ -109,16 +111,17 @@ can overwrite the value by passing it in." &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "Get info about the fine-tune job. The FINE-TUNE-ID of the fine-tune job. The argument CALLBACK is execuated after request is made. -Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you +Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL are global options; however, you can overwrite the value by passing it in." - (openai-request (format "https://api.openai.com/v1/fine-tunes/%s" fine-tune-id) + (openai-request (format "%s/fine-tunes/%s" base-url fine-tune-id) :type "GET" :headers (openai--headers content-type key org-id) :parser 'json-read @@ -130,16 +133,17 @@ can overwrite the value by passing it in." &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "Immediately cancel a fine-tune job. The FINE-TUNE-ID of the fine-tune job to cancel. The argument CALLBACK is execuated after request is made. -Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you +Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL are global options; however, you can overwrite the value by passing it in." - (openai-request (format "https://api.openai.com/v1/fine-tunes/%s/cancel" fine-tune-id) + (openai-request (format "%s/fine-tunes/%s/cancel" base-url fine-tune-id) :type "POST" :headers (openai--headers content-type key org-id) :parser 'json-read @@ -151,16 +155,17 @@ can overwrite the value by passing it in." &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "Get fine-grained status update for a fine-tune job. The FINE-TUNE-ID of the fine-tune job to get events for. The argument CALLBACK is execuated after request is made. -Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you +Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL are global options; however, you can overwrite the value by passing it in." - (openai-request (format "https://api.openai.com/v1/fine-tunes/%s/events" fine-tune-id) + (openai-request (format "%s/fine-tunes/%s/events" base-url fine-tune-id) :type "GET" :headers (openai--headers content-type key org-id) :parser 'json-read @@ -172,16 +177,17 @@ can overwrite the value by passing it in." &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "Delete a fine-tuned model. You must have the Owner role in your organization. The MODEL to delete. The argument CALLBACK is execuated after request is made. -Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you +Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL are global options; however, you can overwrite the value by passing it in." - (openai-request (format "https://api.openai.com/v1/models/%s" model) + (openai-request (format "%s/models/%s" base-url model) :type "DELETE" :headers (openai--headers content-type key org-id) :parser 'json-read From c7b614e03f4313a13d29a74172948db2a55b255c Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:38:08 +0200 Subject: [PATCH 10/27] Use base url in image --- openai-image.el | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/openai-image.el b/openai-image.el index ae17ac0..9e06cc8 100644 --- a/openai-image.el +++ b/openai-image.el @@ -39,19 +39,20 @@ n size response-format - (user openai-user)) + (user openai-user) + (base-url openai-base-url)) "Create an image given a PROMPT. 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 CONTENT-TYPE, KEY, ORG-ID, USER and BASE-URL 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 N, SIZE, and RESPONSE-FORMAT." - (openai-request "https://api.openai.com/v1/images/generations" + (openai-request (concat base-url "/images/generations") :type "POST" :headers (openai--headers content-type key org-id) :data (openai--json-encode @@ -74,20 +75,21 @@ for more information. Arguments here refer to N, SIZE, and RESPONSE-FORMAT." n size response-format - (user openai-user)) + (user openai-user) + (base-url openai-base-url)) "Create an edited or extended image given an original IMAGE and a PROMPT. Arguments IMAGE, PROMPT and CALLBACK are required for this type of request. PROMPT is a text description of the desired image(s). IMAGE is the image file to edit. CALLBACK is the execuation after request is made. -Arguments CONTENT-TYPE, KEY, ORG-ID and USER are global options; however, you +Arguments CONTENT-TYPE, KEY, ORG-ID, USER and BASE-URL 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 MASK, N, SIZE, and RESPONSE-FORMAT." - (openai-request "https://api.openai.com/v1/images/edits" + (openai-request (concat base-url "/images/edits") :type "POST" :headers (openai--headers content-type key org-id) :data (openai--json-encode @@ -112,19 +114,20 @@ RESPONSE-FORMAT." n size response-format - (user openai-user)) + (user openai-user) + (base-url openai-base-url)) "Create a variation of a given IMAGE. Argument CALLBACK is function with data pass in, and the argument IMAGE must be a valid PNG file, less than 4MB, and square. -Arguments CONTENT-TYPE, KEY, ORG-ID and USER are global options; however, you +Arguments CONTENT-TYPE, KEY, ORG-ID, USER and BASE-URL 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 MASK, N, SIZE, and RESPONSE-FORMAT." - (openai-request "https://api.openai.com/v1/images/variations" + (openai-request (concat base-url "/images/variations") :type "POST" :headers (openai--headers content-type key org-id) :data (openai--json-encode From f57a8aa0592b72649f6718f53a9c801ff0f6e9c8 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:39:26 +0200 Subject: [PATCH 11/27] Use base-url in model --- openai-model.el | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/openai-model.el b/openai-model.el index 866be95..950d64f 100644 --- a/openai-model.el +++ b/openai-model.el @@ -33,12 +33,13 @@ &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "Return models data and execute the CALLBACK. -Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you +Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL are global options; however, you can overwrite the value by passing it in." - (openai-request "https://api.openai.com/v1/models" + (openai-request (concat base-url "/models") :type "GET" :headers (openai--headers content-type key org-id) :parser 'json-read @@ -50,13 +51,14 @@ can overwrite the value by passing it in." &key (content-type "application/json") (key openai-key) - org-id) + org-id + (base-url openai-base-url)) "Return MODEL data and execute the CALLBACK. -Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you +Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL are global options; however, you can overwrite the value by passing it in." - (openai-request (format "https://api.openai.com/v1/models/%s" model) + (openai-request (format "%s/models/%s" base-url model) :type "GET" :headers (openai--headers content-type key org-id) :parser 'json-read From 118e2936c6f398a7ae05b5b7edde81e15a7f0321 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:40:10 +0200 Subject: [PATCH 12/27] Use base-url in moderation --- openai-moderation.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openai-moderation.el b/openai-moderation.el index 88c651a..ce38809 100644 --- a/openai-moderation.el +++ b/openai-moderation.el @@ -37,19 +37,20 @@ (content-type "application/json") (key openai-key) org-id - (model "text-moderation-latest")) + (model "text-moderation-latest") + (base-url openai-base-url)) "Classifies if text violates OpenAI's Content Policy. Argument INPUT is the text to classify. The argument CALLBACK is execuated after request is made. -Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you +Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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." - (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 From 9d6e10530e255e8cf282a0759cfb81930f64afa8 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:42:25 +0200 Subject: [PATCH 13/27] Update docs to contain base url --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index b9b6fce..9c1620a 100644 --- a/README.md +++ b/README.md @@ -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 From f15e909a48286f9180d38c138261a7c0734ae895 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 12:55:11 +0200 Subject: [PATCH 14/27] Update change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6c55fd..7314baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 54117a8071ad4f5cffb3ff073a52ef61e4d7e32c Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 14:28:29 +0200 Subject: [PATCH 15/27] Fix audio url --- openai-audio.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai-audio.el b/openai-audio.el index 80f070d..af4c29d 100644 --- a/openai-audio.el +++ b/openai-audio.el @@ -93,7 +93,7 @@ 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 (concat base-url "/audio/translations") + (openai-request (concat base-url "/audio/transcriptions") :type "POST" :headers (openai--headers content-type key org-id) :data (openai--json-encode From 1dd0beee4aa1a08e9fb584e39a36108b70402037 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 14:28:54 +0200 Subject: [PATCH 16/27] Update chat docs --- openai-chat.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai-chat.el b/openai-chat.el index 1141479..74bcca1 100644 --- a/openai-chat.el +++ b/openai-chat.el @@ -54,7 +54,7 @@ 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 CONTENT-TYPE, KEY, ORG-ID, USER and BASE-URL 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 From 7288d4c885e34ea658b2e957247fff3d6c8d0531 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 14:29:29 +0200 Subject: [PATCH 17/27] Update completion docs --- openai-completion.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai-completion.el b/openai-completion.el index 7d5128e..124ed83 100644 --- a/openai-completion.el +++ b/openai-completion.el @@ -59,7 +59,7 @@ 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 CONTENT-TYPE, KEY, ORG-ID, USER and BASE-URL 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 From b0df004c6205b45ff4f29cb1182bcbba84ba9012 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 14:30:26 +0200 Subject: [PATCH 18/27] Update edit docs --- openai-edit.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai-edit.el b/openai-edit.el index ee91bb4..ec9eba5 100644 --- a/openai-edit.el +++ b/openai-edit.el @@ -49,7 +49,7 @@ tells the model how to edit the prompt. The argument CALLBACK is executed after request is made. -Arguments CONTENT-TYPE, KEY, and ORG-ID are global options; however, you +Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL are global options; however, you can overwrite the value by passing it in. The rest of the arguments are optional, please see OpenAI API reference page From 0bcc9994ec82504b5ca1d6a86208bc1b8686d3f5 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 14:30:53 +0200 Subject: [PATCH 19/27] Update embedding docs --- openai-embedding.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai-embedding.el b/openai-embedding.el index 8f063fb..cc496e1 100644 --- a/openai-embedding.el +++ b/openai-embedding.el @@ -49,7 +49,7 @@ length. The argument CALLBACK is executed after the request is made. -Arguments CONTENT-TYPE, KEY, ORG-ID and USER are global options; however, you +Arguments CONTENT-TYPE, KEY, ORG-ID, USER and BASE-URL are global options; however, you can overwrite the value by passing it in. The rest of the arguments are optional, please see OpenAI API reference page From d8900b8ca0a2ae270aad89fa46517d9b36141a7a Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 22:43:03 +0200 Subject: [PATCH 20/27] Fix translations endpoint --- openai-audio.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai-audio.el b/openai-audio.el index af4c29d..80f070d 100644 --- a/openai-audio.el +++ b/openai-audio.el @@ -93,7 +93,7 @@ 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 (concat base-url "/audio/transcriptions") + (openai-request (concat base-url "/audio/translations") :type "POST" :headers (openai--headers content-type key org-id) :data (openai--json-encode From 6d5c0e350c642ede059b317b7e10b93fdcb2137b Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 22:45:33 +0200 Subject: [PATCH 21/27] Fix indentation --- openai-embedding.el | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/openai-embedding.el b/openai-embedding.el index cc496e1..2640f55 100644 --- a/openai-embedding.el +++ b/openai-embedding.el @@ -32,14 +32,14 @@ ;; ;;; API -(cl-defun openai-embedding-create (input callback - &key - (content-type "application/json") - (key openai-key) - org-id - (model "text-embedding-ada-002") - (user openai-user) - (base-url openai-base-url)) +(cl-defun openai-embedding-create ( input callback + &key + (content-type "application/json") + (key openai-key) + org-id + (model "text-embedding-ada-002") + (user openai-user) + (base-url openai-base-url)) "Create an embedding vector representing the input text. INPUT text to get embeddings for, encoded as a string or array of tokens. From 6d34906621228382666a127b78f0d09c54f90b93 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 22:55:34 +0200 Subject: [PATCH 22/27] Let openai-base-url be defcustom --- openai.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai.el b/openai.el index 8bf2f94..04dd057 100644 --- a/openai.el +++ b/openai.el @@ -82,7 +82,7 @@ auth-source is provided for convenience.") "A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.") -(defvar openai-base-url "https://api.openai.com/v1" +(defcustom openai-base-url "https://api.openai.com/v1" "The base URL for OpenAI API requests.") (defun openai--resolve-key (key) From 147c96163cd7a868476354a3813e2c7a52b5566f Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 22:56:40 +0200 Subject: [PATCH 23/27] Fix typo --- openai-chat.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai-chat.el b/openai-chat.el index 74bcca1..1b68305 100644 --- a/openai-chat.el +++ b/openai-chat.el @@ -114,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 From 8fb86fa1bbf003ad039cf8b3beb1be20ed545795 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Fri, 7 Apr 2023 22:59:53 +0200 Subject: [PATCH 24/27] Add type and group to openai-base-url --- openai.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openai.el b/openai.el index 04dd057..7ec56cc 100644 --- a/openai.el +++ b/openai.el @@ -83,7 +83,9 @@ auth-source is provided for convenience.") monitor and detect abuse.") (defcustom openai-base-url "https://api.openai.com/v1" - "The base URL for OpenAI API requests.") + "The base URL for OpenAI API requests." + :type 'string + :group 'openai) (defun openai--resolve-key (key) "If the given KEY is a function call it and return the result, otherwise From bb0c9c0b052fbd8845618d4caaf7cbc32f102f74 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Sat, 8 Apr 2023 08:18:15 +0200 Subject: [PATCH 25/27] Place optional argument base-url at the top --- openai-audio.el | 12 ++++++------ openai-chat.el | 6 +++--- openai-completion.el | 6 +++--- openai-edit.el | 6 +++--- openai-embedding.el | 6 +++--- openai-engine.el | 12 ++++++------ openai-file.el | 30 +++++++++++++++--------------- openai-fine-tune.el | 26 +++++++++++++------------- openai-image.el | 18 +++++++++--------- openai-model.el | 12 ++++++------ openai-moderation.el | 6 +++--- 11 files changed, 70 insertions(+), 70 deletions(-) diff --git a/openai-audio.el b/openai-audio.el index 80f070d..e50515f 100644 --- a/openai-audio.el +++ b/openai-audio.el @@ -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 @@ -41,15 +42,14 @@ prompt response-format temperature - language - (base-url openai-base-url)) + language) "Send transcribe audio request. 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, ORG-ID, and BASE-URL 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 @@ -73,21 +73,21 @@ 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 (model "whisper-1") prompt response-format - temperature - (base-url openai-base-url)) + temperature) "Send translate audio request. 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, ORG-ID, and BASE-URL 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 diff --git a/openai-chat.el b/openai-chat.el index 1b68305..a3f125c 100644 --- a/openai-chat.el +++ b/openai-chat.el @@ -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 @@ -47,14 +48,13 @@ presence-penalty frequency-penalty logit-bias - (user openai-user) - (base-url openai-base-url)) + (user openai-user)) "Send chat request. 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, USER and BASE-URL 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 diff --git a/openai-completion.el b/openai-completion.el index 124ed83..1d317c0 100644 --- a/openai-completion.el +++ b/openai-completion.el @@ -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 @@ -51,15 +52,14 @@ frequency-penalty best-of logit-bias - (user openai-user) - (base-url openai-base-url)) + (user openai-user)) "Send completion request. 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, USER and BASE-URL 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 diff --git a/openai-edit.el b/openai-edit.el index ec9eba5..f8073ee 100644 --- a/openai-edit.el +++ b/openai-edit.el @@ -34,14 +34,14 @@ (cl-defun openai-edit-create ( input instruction callback &key + (base-url openai-base-url) (content-type "application/json") (key openai-key) org-id (model "text-davinci-edit-001") temperature top-p - n - (base-url openai-base-url)) + n) "Create a new edit for the provided input, instruction, and parameters. The INPUT is text to use as a starting point for the edit. The INSTRUCTION that @@ -49,7 +49,7 @@ tells the model how to edit the prompt. The argument CALLBACK is executed after request is made. -Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 arguments are optional, please see OpenAI API reference page diff --git a/openai-embedding.el b/openai-embedding.el index 2640f55..8b5452e 100644 --- a/openai-embedding.el +++ b/openai-embedding.el @@ -34,12 +34,12 @@ (cl-defun openai-embedding-create ( input callback &key + (base-url openai-base-url) (content-type "application/json") (key openai-key) org-id (model "text-embedding-ada-002") - (user openai-user) - (base-url openai-base-url)) + (user openai-user)) "Create an embedding vector representing the input text. INPUT text to get embeddings for, encoded as a string or array of tokens. @@ -49,7 +49,7 @@ length. The argument CALLBACK is executed after the request is made. -Arguments CONTENT-TYPE, KEY, ORG-ID, USER and BASE-URL 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 arguments are optional, please see OpenAI API reference page diff --git a/openai-engine.el b/openai-engine.el index 8762bed..63fbfb8 100644 --- a/openai-engine.el +++ b/openai-engine.el @@ -36,16 +36,16 @@ (cl-defun openai-engine-list ( callback &key + (base-url openai-base-url) (content-type "application/json") (key openai-key) - org-id - (base-url openai-base-url)) + org-id) "Lists the currently available (non-finetuned) models, and provides basic 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 BASE-URL 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 (concat base-url "/engines") :type "GET" @@ -57,10 +57,10 @@ 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 - (base-url openai-base-url)) + org-id) "Retrieves a model instance, providing basic information about it such as the owner and availability. @@ -68,7 +68,7 @@ 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 BASE-URL 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 "%s/engines/%s" base-url engine-id) :type "GET" diff --git a/openai-file.el b/openai-file.el index f061786..e61b9f9 100644 --- a/openai-file.el +++ b/openai-file.el @@ -34,15 +34,15 @@ (cl-defun openai-file-list ( callback &key + (base-url openai-base-url) (content-type "application/json") (key openai-key) - org-id - (base-url openai-base-url)) + 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, ORG-ID and BASE-URL 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 (concat base-url "/files") :type "GET" @@ -54,10 +54,10 @@ 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 - (base-url openai-base-url)) + org-id) "Upload a file that contain document(s) to be used across various endpoints/features. @@ -73,7 +73,7 @@ uploaded file. Argument CALLBACK is function with data pass in. -Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 (concat base-url "/files") :type "POST" @@ -88,17 +88,17 @@ 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 - (base-url openai-base-url)) + org-id) "Delete a file. 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, ORG-ID and BASE-URL 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 (concat base-url "/files") :type "DELETE" @@ -112,17 +112,17 @@ 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 - (base-url openai-base-url)) + org-id) "Return information about a specific file. 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, ORG-ID and BASE-URL 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 "%s/files/%s" base-url file-id) :type "GET" @@ -136,10 +136,10 @@ 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 - (base-url openai-base-url)) + org-id) "Return the contents of the specified file The arument FILE-ID is id of the file to use for this request. @@ -147,7 +147,7 @@ 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, ORG-ID and BASE-URL 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 "%s/files/%s/content" base-url file-id) :type "GET" diff --git a/openai-fine-tune.el b/openai-fine-tune.el index 42c00af..9f971dc 100644 --- a/openai-fine-tune.el +++ b/openai-fine-tune.el @@ -33,6 +33,7 @@ (cl-defun openai-fine-tune-create ( training-file callback &key + (base-url openai-base-url) (content-type "application/json") (key openai-key) org-id @@ -46,8 +47,7 @@ classification-n-classes classification-positive-class classification-betas - suffix - (base-url openai-base-url)) + suffix) "Create a job that fine-tunes a specified model from a given dataset. Response includes details of the enqueued job including job status and the name @@ -58,14 +58,14 @@ data. 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. The rest of the arugments are optional, please see OpenAI API reference page for more information. Arguments here refer to MODEL, VALIDATION-FILE, N-EPOCHS, BATCH-SIZE, LEARNING-RATE-MULTIPLIER, PROMPT-LOSS-WEIGHT, COMPUTE-CLASSIFICATION-METRICS, CLASSIFICATION-N-CLASSES, -CLASSIFICATION-POSITIVE-CLASS, CLASSIFICATION-BETAS, SUFFIX and BASE-URL" +CLASSIFICATION-POSITIVE-CLASS, CLASSIFICATION-BETAS and SUFFIX." (openai-request (concat base-url "/fine-tunes") :type "POST" :headers (openai--headers content-type key org-id) @@ -89,15 +89,15 @@ CLASSIFICATION-POSITIVE-CLASS, CLASSIFICATION-BETAS, SUFFIX and BASE-URL" (cl-defun openai-fine-tune-list ( callback &key + (base-url openai-base-url) (content-type "application/json") (key openai-key) - org-id - (base-url openai-base-url)) + org-id) "List your organization's fine-tuning jobs. The argument CALLBACK is execuated after request is made. -Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 (concat base-url "/fine-tunes") :type "GET" @@ -109,17 +109,17 @@ can overwrite the value by passing it in." (cl-defun openai-fine-tune-retrieve ( fine-tune-id callback &key + (base-url openai-base-url) (content-type "application/json") (key openai-key) - org-id - (base-url openai-base-url)) + org-id) "Get info about the fine-tune job. The FINE-TUNE-ID of the fine-tune job. The argument CALLBACK is execuated after request is made. -Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 "%s/fine-tunes/%s" base-url fine-tune-id) :type "GET" @@ -131,17 +131,17 @@ can overwrite the value by passing it in." (cl-defun openai-fine-tune-cancel ( fine-tune-id callback &key + (base-url openai-base-url) (content-type "application/json") (key openai-key) - org-id - (base-url openai-base-url)) + org-id) "Immediately cancel a fine-tune job. The FINE-TUNE-ID of the fine-tune job to cancel. The argument CALLBACK is execuated after request is made. -Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 "%s/fine-tunes/%s/cancel" base-url fine-tune-id) :type "POST" diff --git a/openai-image.el b/openai-image.el index 9e06cc8..40a7144 100644 --- a/openai-image.el +++ b/openai-image.el @@ -33,21 +33,21 @@ (cl-defun openai-image ( prompt callback &key + (base-url openai-base-url) (content-type "application/json") (key openai-key) org-id n size response-format - (user openai-user) - (base-url openai-base-url)) + (user openai-user)) "Create an image given a PROMPT. 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, USER and BASE-URL 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 @@ -68,6 +68,7 @@ for more information. Arguments here refer to N, SIZE, and RESPONSE-FORMAT." (cl-defun openai-image-edit ( image prompt callback &key + (base-url openai-base-url) content-type (key openai-key) org-id @@ -75,15 +76,14 @@ for more information. Arguments here refer to N, SIZE, and RESPONSE-FORMAT." n size response-format - (user openai-user) - (base-url openai-base-url)) + (user openai-user)) "Create an edited or extended image given an original IMAGE and a PROMPT. Arguments IMAGE, PROMPT and CALLBACK are required for this type of request. PROMPT is a text description of the desired image(s). IMAGE is the image file to edit. CALLBACK is the execuation after request is made. -Arguments CONTENT-TYPE, KEY, ORG-ID, USER and BASE-URL 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 @@ -107,6 +107,7 @@ RESPONSE-FORMAT." (cl-defun openai-image-variation ( image callback &key + (base-url openai-base-url) content-type (key openai-key) org-id @@ -114,14 +115,13 @@ RESPONSE-FORMAT." n size response-format - (user openai-user) - (base-url openai-base-url)) + (user openai-user)) "Create a variation of a given IMAGE. Argument CALLBACK is function with data pass in, and the argument IMAGE must be a valid PNG file, less than 4MB, and square. -Arguments CONTENT-TYPE, KEY, ORG-ID, USER and BASE-URL 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 diff --git a/openai-model.el b/openai-model.el index 950d64f..a77ef57 100644 --- a/openai-model.el +++ b/openai-model.el @@ -31,13 +31,13 @@ (cl-defun openai-models ( callback &key + (base-url openai-base-url) (content-type "application/json") (key openai-key) - org-id - (base-url openai-base-url)) + org-id) "Return models data and execute the CALLBACK. -Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 (concat base-url "/models") :type "GET" @@ -49,14 +49,14 @@ can overwrite the value by passing it in." (cl-defun openai-model ( model callback &key + (base-url openai-base-url) (content-type "application/json") (key openai-key) - org-id - (base-url openai-base-url)) + org-id) "Return MODEL data and execute the CALLBACK. -Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 "%s/models/%s" base-url model) :type "GET" diff --git a/openai-moderation.el b/openai-moderation.el index ce38809..c4f5198 100644 --- a/openai-moderation.el +++ b/openai-moderation.el @@ -34,18 +34,18 @@ (cl-defun openai-moderation-create ( input callback &key + (base-url openai-base-url) (content-type "application/json") (key openai-key) org-id - (model "text-moderation-latest") - (base-url openai-base-url)) + (model "text-moderation-latest")) "Classifies if text violates OpenAI's Content Policy. Argument INPUT is the text to classify. The argument CALLBACK is execuated after request is made. -Arguments CONTENT-TYPE, KEY, ORG-ID and BASE-URL 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 From b51af8b9e8489f7801830e0518b1deab88b5985f Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Sat, 8 Apr 2023 15:49:03 +0200 Subject: [PATCH 26/27] Update openai-auth-key --- openai.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openai.el b/openai.el index 7ec56cc..5e49cf1 100644 --- a/openai.el +++ b/openai.el @@ -62,10 +62,11 @@ ;;; Request ;;;###autoload -(defun openai-key-auth-source () - "Retrieve the OpenAI API key from auth-source." +(defun openai-key-auth-source (&optional base-url) + "Retrieve the OpenAI API key from auth-source given a BASE-URL. +If BASE-URL is not specified, it defaults to `openai-base-url'." (if-let ((auth-info (auth-source-search :max 1 - :host "api.openai.com" + :host (url-host (url-generic-parse-url (or base-url openai-base-url))) :require '(:user :secret)))) (funcall (plist-get (car auth-info) :secret)) (error "OpenAI API key not found in auth-source"))) From a936c9180debed140d3808e413a43d538c0f832d Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Sat, 8 Apr 2023 15:51:33 +0200 Subject: [PATCH 27/27] Fix casing --- openai-fine-tune.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai-fine-tune.el b/openai-fine-tune.el index 9f971dc..5fa52d0 100644 --- a/openai-fine-tune.el +++ b/openai-fine-tune.el @@ -58,7 +58,7 @@ data. The argument CALLBACK is execuated after request is made. -Arguments BASe-URL, 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