Skip to content

Commit

Permalink
Add robby-api-url customization variable.
Browse files Browse the repository at this point in the history
Put the base API url in a customization variable, instead of hard-coding
it. This should let users use alternate OpenAI compatible providers.

Fixes #1.
  • Loading branch information
stevemolitor committed Mar 30, 2024
1 parent 635dc0f commit 34cc413
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
9 changes: 8 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ builder to create custom commands without having to write code.
- [[#built-in-action-functions][Built-in Action Functions]]
- [[#built-in-grounding-functions][Built-in Grounding Functions]]
- [[#customization][Customization]]
- [[#openai-url][OpenAI URL]]
- [[#api-options][API Options]]
- [[#animated-gifs][Animated Gifs]]

* Requirements
Expand Down Expand Up @@ -468,7 +470,12 @@ Replace =%= with =%%= in TEXT to avoid format string errors calling ~message~.
*** ~robby-remove-trailing-end-of-line~
Remove the end of line character at the very end of a string if present.
* Customization
Use ~customize-group~ | ~robby~ to see the various customization options. Robby will validate values as appropriate, for example ~robby-chat-temperature~ values must be between =0.0= and =2.0=.
Use ~customize-group~ | ~robby~ to see the various customization options. Robby will validate values as appropriate, for example ~robby-chat-temperature~ values must be between =0.0= and =2.0=.

** OpenAI URL
Customize the ~robby-chat-api~ variable to use a different OpenAI compatible provider. By default it is set to =https://api.openai.com/v1/chat/completions=.

** API Options

The ~robby-chat-api~ customization group species the OpenAI API options. Here are
a few important ones:
Expand Down
5 changes: 5 additions & 0 deletions robby-customization.el
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ It should include a `%s' placeholder for the spinner."
:type 'string
:group 'robby)

(defcustom robby-api-url "https://api.openai.com/v1/chat/completions"
"URL to use for OpenAI API requests."
:type 'string
:group 'robby)

;;; chat api options
(defgroup robby-chat-api nil
"Options to pass to the chat API."
Expand Down
8 changes: 3 additions & 5 deletions robby-request.el
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
(require 'url-vars)

(require 'robby-api-key)
(require 'robby-customization)
(require 'robby-logging)
(require 'robby-utils)

;;; constants
(defconst robby--request-url "https://api.openai.com/v1/chat/completions")

;;; util functions
(defun robby--request-parse-error-data (data)
"Get error from response DATA."
Expand Down Expand Up @@ -102,7 +100,7 @@ STREAMP is non-nil if the response is a stream."
"curl"
proc-buffer
"curl"
robby--request-url
robby-api-url
curl-options)
(error (funcall on-error err)))))
(let ((remaining "")
Expand Down Expand Up @@ -163,7 +161,7 @@ ON-ERROR is the callback for when an error is received."
(message-log-max nil))
(robby--log (format "#url-retrieve request JSON payload:\n%s\n" url-request-data))
(url-retrieve
robby--request-url
robby-api-url
(lambda (_status)
(goto-char (point-min))
(re-search-forward "^{")
Expand Down

0 comments on commit 34cc413

Please sign in to comment.