joshcho / ChatGPT.el

ChatGPT in Emacs
GNU General Public License v3.0
397 stars 34 forks source link

Add options for setting chatgpt-wrapper backend & model #47

Closed barryridge closed 1 year ago

barryridge commented 1 year ago

Fix for #38. Related: #42. Builds on #46.

Allow user to set chatgpt-backend and chatgpt-model variables to change the backend and model respectively used by chatgpt-wrapper.

Sample Doom Emacs config:

(setenv "OPENAI_API_KEY" (string-trim (shell-command-to-string "pass show openai_api_key")))
(use-package! chatgpt
  :defer t
  :config
  (unless (boundp 'python-interpreter)
    (defvaralias 'python-interpreter 'python-shell-interpreter))
  (setq chatgpt-repo-path (expand-file-name "straight/repos/ChatGPT.el/" doom-local-dir))
  (setq chatgpt-backend "chatgpt-api")
  (setq chatgpt-model "default")
  (set-popup-rule! (regexp-quote "*ChatGPT*")
    :side 'bottom :size .5 :ttl nil :quit t :modeline nil)
  :init
  (map! :leader
      (:prefix-map ("a" . "applications")
       (:prefix ("c" . "chatgpt")
        :desc "ChatGPT Query" "q" #'chatgpt-query
        :desc "ChatGPT Reset" "r" #'chatgpt-reset)))
  :bind ("C-c q" . chatgpt-query-stream)
)

Possible values for chatgpt-backend: chatgpt-browser, chatgpt-api.

Possible values for chatgpt-model when using chatgpt-browser backend: default, legacy-paid, legacy-free, gpt4.

Possible values for chatgpt-model when using chatgpt-api backend: default, turbo, turbo-0301, gpt4, gpt4-0314, gpt4-32k, gpt4-32k-0314.

These are based on the values specified in constants.py from chatgpt-wrapper.

barryridge commented 1 year ago

Note the use of GNU Pass to retrieve the OpenAI API key and assign it to an environment variable as required by chatgpt-wrapper. This could be done in other ways of course, e.g. by querying .authinfo.gpg.

ekg commented 1 year ago

Is this working for folks? If so, why not merge it?