Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Azure-OpenAI service in chatgpt-shell.el #145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

doctorguile
Copy link

update the chatgpt-shell-auth-header function to generate the appropriate header based on the selected service.

Also, add new custom variables chatgpt-shell-azure-openai-deployment and chatgpt-shell-azure-openai-api-version for Azure-OpenAI configuration.

Modify chatgpt-shell--api-url function to construct the appropriate API URL based on the selected service.

update the `chatgpt-shell-auth-header` function to generate the
appropriate header based on the selected service.

Also, add new custom variables `chatgpt-shell-azure-openai-deployment`
and `chatgpt-shell-azure-openai-api-version` for Azure-OpenAI
configuration.

Modify `chatgpt-shell--api-url` function to construct the appropriate API URL based on the selected service.
@xenodium
Copy link
Owner

Thanks a lot for the PR! I'm not an Azure user, though I'm thinking we may want to try to consolidate service configurations. Maybe something along the lines of:

(defcustom chatgpt-shell-provider (chatgpt-shell-make-openai-provider)
  "ChatGPT service provider.

Defaults to `chatgpt-shell-make-openai-provider'.

Alternatively, use `chatgpt-shell-make-azure-openai-provider'.")

(cl-defun chatgpt-shell-make-openai-provider (&key (api-url-base "https://api.openai.com")
                                                  (api-url-path "/v1/chat/completions"))
  (list
   (cons 'header
         (format "Authorization: Bearer %s" (chatgpt-shell-openai-key)))
   (cons 'url
         (concat api-url-base chatgpt-shell-api-url-path))))

(cl-defun chatgpt-shell-make-azure-openai-provider (&key (api-url-base "https://api.openai.com")
                                                         deployment-name
                                                         (version "2023-03-15-preview"))
  (unless deployment-name
    (user-error "`deployment-name' must be set"))
  (list
   (cons 'header
         (format "api-key: %s" (chatgpt-shell-openai-key)))
   (cons 'url
         (format "/openai/deployments/%s/chat/completions?api-version=%s"
                 deployment-name version))))

Client code avoids switching with cond, and we use something like:

(map-elt chatgpt-shell-provider  'header)
(map-elt chatgpt-shell-provider 'url)

I've not tested this code. We may need to swap some of the values with lambdas and (funcall (map-elt chatgpt-shell-provider 'header)) to prevent issues at package load time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants