2023-03-09 16:56:26 -08:00
|
|
|
|
;;; gptel-transient.el --- Transient menu for GPTel -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
|
|
;; Copyright (C) 2023 Karthik Chikmagalur
|
|
|
|
|
|
|
|
|
|
;; Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
|
|
|
|
|
;; Keywords: convenience
|
|
|
|
|
|
|
|
|
|
;; SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
2024-01-18 02:40:58 +00:00
|
|
|
|
(require 'cl-lib)
|
2023-03-09 16:56:26 -08:00
|
|
|
|
(require 'gptel)
|
|
|
|
|
(require 'transient)
|
|
|
|
|
|
2023-04-09 03:34:16 -07:00
|
|
|
|
(declare-function ediff-regions-internal "ediff")
|
|
|
|
|
(declare-function ediff-make-cloned-buffer "ediff-utils")
|
|
|
|
|
|
2024-02-04 21:06:14 -08:00
|
|
|
|
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
;; * Helper functions and vars
|
|
|
|
|
|
|
|
|
|
(defvar gptel--set-buffer-locally nil
|
|
|
|
|
"Set model parameters from `gptel-menu' buffer-locally.
|
|
|
|
|
|
|
|
|
|
Affects the system message too.")
|
|
|
|
|
|
|
|
|
|
(defun gptel--set-with-scope (sym value &optional scope)
|
|
|
|
|
"Set SYMBOL's symbol-value to VALUE with SCOPE.
|
|
|
|
|
|
|
|
|
|
If SCOPE is non-nil, set it buffer-locally, else clear any
|
|
|
|
|
buffer-local value and set its default global value."
|
|
|
|
|
(if scope
|
|
|
|
|
(set (make-local-variable sym) value)
|
|
|
|
|
(kill-local-variable sym)
|
|
|
|
|
(set sym value)))
|
|
|
|
|
|
|
|
|
|
(defun gptel--get-directive (args)
|
|
|
|
|
"Find the additional directive in the transient ARGS.
|
|
|
|
|
|
|
|
|
|
Meant to be called when `gptel-menu' is active."
|
|
|
|
|
(cl-some (lambda (s) (and (stringp s) (string-prefix-p ":" s)
|
|
|
|
|
(concat "\n\n" (substring s 1))))
|
|
|
|
|
args))
|
|
|
|
|
|
|
|
|
|
(defun gptel--instructions-make-overlay (text &optional ov)
|
|
|
|
|
"TODO"
|
|
|
|
|
(save-excursion
|
|
|
|
|
(cond
|
|
|
|
|
((use-region-p) (goto-char (region-beginning)))
|
|
|
|
|
((gptel--in-response-p) (gptel-beginning-of-response))
|
|
|
|
|
(t (text-property-search-backward 'gptel 'response)))
|
|
|
|
|
(skip-chars-forward "\n \t")
|
|
|
|
|
(if (and ov (overlayp ov))
|
|
|
|
|
(move-overlay ov (point) (point) (current-buffer))
|
|
|
|
|
(setq ov (make-overlay (point) (point) nil t)))
|
|
|
|
|
(overlay-put ov 'before-string nil)
|
|
|
|
|
;; (unless (or (bobp) (eq (char-before) "\n"))
|
|
|
|
|
;; (overlay-put ov 'before-string (propertize "\n" 'font-lock-face 'shadow)))
|
|
|
|
|
(overlay-put ov 'category 'gptel)
|
|
|
|
|
(overlay-put
|
|
|
|
|
ov 'after-string
|
|
|
|
|
(concat
|
|
|
|
|
(propertize (concat "GPTEL: " text)
|
|
|
|
|
'font-lock-face '(:inherit shadow :box t))
|
|
|
|
|
"\n"))
|
|
|
|
|
ov))
|
|
|
|
|
|
|
|
|
|
(defun gptel--transient-read-variable (prompt initial-input history)
|
|
|
|
|
"Read value from minibuffer and interpret the result as a Lisp object.
|
|
|
|
|
|
|
|
|
|
PROMPT, INITIAL-INPUT and HISTORY are as in the Transient reader
|
|
|
|
|
documention."
|
|
|
|
|
(ignore-errors
|
|
|
|
|
(read-from-minibuffer prompt initial-input read-expression-map t history)))
|
2024-02-04 21:06:14 -08:00
|
|
|
|
|
2023-04-09 03:34:16 -07:00
|
|
|
|
(defun gptel--refactor-or-rewrite ()
|
|
|
|
|
"Rewrite should be refactored into refactor.
|
|
|
|
|
|
|
|
|
|
Or is it the other way around?"
|
|
|
|
|
(if (derived-mode-p 'prog-mode)
|
|
|
|
|
"Refactor" "Rewrite"))
|
|
|
|
|
|
|
|
|
|
(defvar-local gptel--rewrite-message nil)
|
|
|
|
|
(defun gptel--rewrite-message ()
|
|
|
|
|
"Set a generic refactor/rewrite message for the buffer."
|
|
|
|
|
(if (derived-mode-p 'prog-mode)
|
|
|
|
|
(format "You are a %s programmer. Refactor the following code. Generate only code, no explanation."
|
2024-03-20 02:06:48 +01:00
|
|
|
|
(thread-last (symbol-name major-mode)
|
|
|
|
|
(string-remove-suffix "-mode")
|
|
|
|
|
(string-remove-suffix "-ts")))
|
2023-04-09 03:34:16 -07:00
|
|
|
|
(format "You are a prose editor. Rewrite the following text to be more professional.")))
|
|
|
|
|
|
2023-07-10 02:09:16 -07:00
|
|
|
|
(defvar gptel--crowdsourced-prompts-url
|
|
|
|
|
"https://github.com/f/awesome-chatgpt-prompts/raw/main/prompts.csv"
|
gptel: docstrings for multi-LLM support, bump version
* gptel.el (gptel, gptel--insert-response, gptel-temperature,
gptel-pre-response-hook, gptel-response-filter-functions,
gptel-stream, gptel--convert-org, gptel-pre-response-hook,
gptel-max-tokens, gptel-mode, gptel-request,
gptel--insert-response, gptel-set-topic, gptel--convert-org):
Replace mentions of "ChatGPT" with "LLM" or equivalent. Update
package description and remove commented out obsolete code.
Bump version to 0.6.5.
* gptel-transient.el (gptel--crowdsourced-prompts-url,
gptel--crowdsourced-prompts, gptel-menu, gptel-system-prompt,
gptel-rewrite-menu, gptel--infix-max-tokens,
gptel--suffix-system-message): Ditto.
* gptel-ollama.el (gptel--request-data): Ditto
* gptel-kagi.el (gptel--request-data): Ditto
* gptel-curl.el (gptel-curl--stream-insert-response,
gptel-curl--stream-cleanup, gptel-curl--stream-filter): Ditto
2024-02-03 14:20:41 -08:00
|
|
|
|
"URL for crowdsourced LLM system prompts.")
|
2023-07-10 02:09:16 -07:00
|
|
|
|
|
|
|
|
|
(defvar gptel--crowdsourced-prompts
|
|
|
|
|
(make-hash-table :test #'equal)
|
gptel: docstrings for multi-LLM support, bump version
* gptel.el (gptel, gptel--insert-response, gptel-temperature,
gptel-pre-response-hook, gptel-response-filter-functions,
gptel-stream, gptel--convert-org, gptel-pre-response-hook,
gptel-max-tokens, gptel-mode, gptel-request,
gptel--insert-response, gptel-set-topic, gptel--convert-org):
Replace mentions of "ChatGPT" with "LLM" or equivalent. Update
package description and remove commented out obsolete code.
Bump version to 0.6.5.
* gptel-transient.el (gptel--crowdsourced-prompts-url,
gptel--crowdsourced-prompts, gptel-menu, gptel-system-prompt,
gptel-rewrite-menu, gptel--infix-max-tokens,
gptel--suffix-system-message): Ditto.
* gptel-ollama.el (gptel--request-data): Ditto
* gptel-kagi.el (gptel--request-data): Ditto
* gptel-curl.el (gptel-curl--stream-insert-response,
gptel-curl--stream-cleanup, gptel-curl--stream-filter): Ditto
2024-02-03 14:20:41 -08:00
|
|
|
|
"Crowdsourced LLM system prompts.")
|
2023-07-10 02:09:16 -07:00
|
|
|
|
|
|
|
|
|
(defun gptel--crowdsourced-prompts ()
|
gptel: docstrings for multi-LLM support, bump version
* gptel.el (gptel, gptel--insert-response, gptel-temperature,
gptel-pre-response-hook, gptel-response-filter-functions,
gptel-stream, gptel--convert-org, gptel-pre-response-hook,
gptel-max-tokens, gptel-mode, gptel-request,
gptel--insert-response, gptel-set-topic, gptel--convert-org):
Replace mentions of "ChatGPT" with "LLM" or equivalent. Update
package description and remove commented out obsolete code.
Bump version to 0.6.5.
* gptel-transient.el (gptel--crowdsourced-prompts-url,
gptel--crowdsourced-prompts, gptel-menu, gptel-system-prompt,
gptel-rewrite-menu, gptel--infix-max-tokens,
gptel--suffix-system-message): Ditto.
* gptel-ollama.el (gptel--request-data): Ditto
* gptel-kagi.el (gptel--request-data): Ditto
* gptel-curl.el (gptel-curl--stream-insert-response,
gptel-curl--stream-cleanup, gptel-curl--stream-filter): Ditto
2024-02-03 14:20:41 -08:00
|
|
|
|
"Acquire and read crowdsourced LLM system prompts.
|
2023-07-10 02:09:16 -07:00
|
|
|
|
|
|
|
|
|
These are stored in the variable `gptel--crowdsourced-prompts',
|
|
|
|
|
which see."
|
|
|
|
|
(when (hash-table-p gptel--crowdsourced-prompts)
|
|
|
|
|
(when (hash-table-empty-p gptel--crowdsourced-prompts)
|
|
|
|
|
(unless gptel-crowdsourced-prompts-file
|
|
|
|
|
(run-at-time 0 nil #'gptel-system-prompt)
|
|
|
|
|
(user-error "No crowdsourced prompts available"))
|
|
|
|
|
(unless (and (file-exists-p gptel-crowdsourced-prompts-file)
|
|
|
|
|
(time-less-p
|
|
|
|
|
(time-subtract (current-time) (days-to-time 14))
|
|
|
|
|
(file-attribute-modification-time
|
|
|
|
|
(file-attributes gptel-crowdsourced-prompts-file))))
|
|
|
|
|
(when (y-or-n-p
|
|
|
|
|
(concat
|
|
|
|
|
"Fetch crowdsourced system prompts from "
|
|
|
|
|
(propertize "https://github.com/f/awesome-chatgpt-prompts" 'face 'link)
|
|
|
|
|
"?"))
|
|
|
|
|
;; Fetch file
|
|
|
|
|
(message "Fetching prompts...")
|
2024-02-03 01:24:13 +01:00
|
|
|
|
(let ((dir (file-name-directory gptel-crowdsourced-prompts-file)))
|
|
|
|
|
(unless (file-exists-p dir) (mkdir dir 'create-parents))
|
|
|
|
|
(if (url-copy-file gptel--crowdsourced-prompts-url
|
|
|
|
|
gptel-crowdsourced-prompts-file
|
|
|
|
|
'ok-if-already-exists)
|
|
|
|
|
(message "Fetching prompts... done.")
|
|
|
|
|
(message "Could not retrieve new prompts.")))))
|
2023-07-10 02:09:16 -07:00
|
|
|
|
(if (not (file-readable-p gptel-crowdsourced-prompts-file))
|
|
|
|
|
(progn (message "No crowdsourced prompts available")
|
|
|
|
|
(call-interactively #'gptel-system-prompt))
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(insert-file-contents gptel-crowdsourced-prompts-file)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(forward-line 1)
|
|
|
|
|
(while (not (eobp))
|
|
|
|
|
(when-let ((act (read (current-buffer))))
|
|
|
|
|
(forward-char)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(while (re-search-forward "\"\"" (line-end-position) t)
|
|
|
|
|
(replace-match "\\\\\"")))
|
|
|
|
|
(when-let ((prompt (read (current-buffer))))
|
|
|
|
|
(puthash act prompt gptel--crowdsourced-prompts)))
|
|
|
|
|
(forward-line 1)))))
|
|
|
|
|
gptel--crowdsourced-prompts))
|
|
|
|
|
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
|
|
|
|
|
;; * Transient classes and methods for gptel
|
|
|
|
|
|
|
|
|
|
(defclass gptel--switches (transient-lisp-variable)
|
|
|
|
|
((display-if-true :initarg :display-if-true :initform "for this buffer")
|
|
|
|
|
(display-if-false :initarg :display-if-false :initform "globally"))
|
|
|
|
|
"Boolean lisp variable class for gptel-transient.")
|
|
|
|
|
|
|
|
|
|
(cl-defmethod transient-infix-read ((obj gptel--switches))
|
|
|
|
|
"Cycle through the mutually exclusive switches."
|
|
|
|
|
(not (oref obj value)))
|
|
|
|
|
|
|
|
|
|
(cl-defmethod transient-format-value ((obj gptel--switches))
|
|
|
|
|
(with-slots (value display-if-true display-if-false) obj
|
|
|
|
|
(format
|
|
|
|
|
(propertize "(%s)" 'face 'transient-delimiter)
|
|
|
|
|
(concat
|
|
|
|
|
(propertize display-if-false
|
|
|
|
|
'face (if value 'transient-inactive-value 'transient-value))
|
|
|
|
|
(propertize "|" 'face 'transient-delimiter)
|
|
|
|
|
(propertize display-if-true
|
|
|
|
|
'face (if value 'transient-value 'transient-inactive-value))))))
|
|
|
|
|
|
|
|
|
|
(defclass gptel-lisp-variable (transient-lisp-variable)
|
|
|
|
|
((display-nil :initarg :display-nil))
|
|
|
|
|
"Lisp variables that show :display-nil instead of nil.")
|
|
|
|
|
|
|
|
|
|
(cl-defmethod transient-format-value
|
|
|
|
|
((obj gptel-lisp-variable))
|
|
|
|
|
(propertize (prin1-to-string (or (oref obj value)
|
|
|
|
|
(oref obj display-nil)))
|
|
|
|
|
'face 'transient-value))
|
|
|
|
|
|
|
|
|
|
(cl-defmethod transient-infix-set ((obj gptel-lisp-variable) value)
|
|
|
|
|
(funcall (oref obj set-value)
|
|
|
|
|
(oref obj variable)
|
|
|
|
|
(oset obj value value)
|
|
|
|
|
gptel--set-buffer-locally))
|
|
|
|
|
|
|
|
|
|
(defclass gptel-provider-variable (transient-lisp-variable)
|
|
|
|
|
((model :initarg :model)
|
|
|
|
|
(model-value :initarg :model-value)
|
|
|
|
|
(always-read :initform t)
|
|
|
|
|
(set-value :initarg :set-value :initform #'set))
|
|
|
|
|
"Class used for gptel-backends.")
|
|
|
|
|
|
|
|
|
|
(cl-defmethod transient-format-value ((obj gptel-provider-variable))
|
|
|
|
|
(propertize (concat (gptel-backend-name (oref obj value)) ":"
|
|
|
|
|
(buffer-local-value (oref obj model) transient--original-buffer))
|
|
|
|
|
'face 'transient-value))
|
|
|
|
|
|
|
|
|
|
(cl-defmethod transient-infix-set ((obj gptel-provider-variable) value)
|
|
|
|
|
(pcase-let ((`(,backend-value ,model-value) value))
|
|
|
|
|
(funcall (oref obj set-value)
|
|
|
|
|
(oref obj variable)
|
|
|
|
|
(oset obj value backend-value)
|
|
|
|
|
gptel--set-buffer-locally)
|
|
|
|
|
(funcall (oref obj set-value)
|
|
|
|
|
(oref obj model)
|
|
|
|
|
(oset obj model-value model-value)
|
|
|
|
|
gptel--set-buffer-locally)))
|
|
|
|
|
|
|
|
|
|
(defclass gptel-option-overlaid (transient-option)
|
|
|
|
|
((display-nil :initarg :display-nil)
|
|
|
|
|
(overlay :initarg :overlay))
|
|
|
|
|
"Transient options for overlays displayed in the working buffer.")
|
|
|
|
|
|
|
|
|
|
(cl-defmethod transient-format-value ((obj gptel-option-overlaid))
|
|
|
|
|
"set up the in-buffer overlay for additional directive, a string.
|
|
|
|
|
|
|
|
|
|
Also format its value in the Transient menu."
|
|
|
|
|
(let ((value (oref obj value))
|
|
|
|
|
(ov (oref obj overlay))
|
|
|
|
|
(argument (oref obj argument)))
|
|
|
|
|
;; Making an overlay
|
|
|
|
|
(if (or (not value) (string-empty-p value))
|
|
|
|
|
(when ov (delete-overlay ov))
|
|
|
|
|
(with-current-buffer transient--original-buffer
|
|
|
|
|
(oset obj overlay (gptel--instructions-make-overlay value ov)))
|
|
|
|
|
(letrec ((ov-clear-hook
|
|
|
|
|
(lambda () (when-let* ((ov (oref obj overlay))
|
|
|
|
|
((overlayp ov)))
|
|
|
|
|
(remove-hook 'transient-exit-hook
|
|
|
|
|
ov-clear-hook)
|
|
|
|
|
(delete-overlay ov)))))
|
|
|
|
|
(add-hook 'transient-exit-hook ov-clear-hook)))
|
|
|
|
|
;; Updating transient menu display
|
|
|
|
|
(if value
|
|
|
|
|
(propertize (concat argument (truncate-string-to-width value 25 nil nil "..."))
|
|
|
|
|
'face 'transient-value)
|
|
|
|
|
(propertize
|
|
|
|
|
(concat "(" (symbol-name (oref obj display-nil)) ")")
|
|
|
|
|
'face 'transient-inactive-value))))
|
|
|
|
|
|
2024-02-04 21:06:14 -08:00
|
|
|
|
|
2023-04-09 03:34:16 -07:00
|
|
|
|
;; * Transient Prefixes
|
|
|
|
|
|
|
|
|
|
(define-obsolete-function-alias 'gptel-send-menu 'gptel-menu "0.3.2")
|
|
|
|
|
|
2023-04-09 04:19:02 -07:00
|
|
|
|
;; BUG: The `:incompatible' spec doesn't work if there's a `:description' below it.
|
2023-04-09 03:34:16 -07:00
|
|
|
|
;;;###autoload (autoload 'gptel-menu "gptel-transient" nil t)
|
|
|
|
|
(transient-define-prefix gptel-menu ()
|
gptel: docstrings for multi-LLM support, bump version
* gptel.el (gptel, gptel--insert-response, gptel-temperature,
gptel-pre-response-hook, gptel-response-filter-functions,
gptel-stream, gptel--convert-org, gptel-pre-response-hook,
gptel-max-tokens, gptel-mode, gptel-request,
gptel--insert-response, gptel-set-topic, gptel--convert-org):
Replace mentions of "ChatGPT" with "LLM" or equivalent. Update
package description and remove commented out obsolete code.
Bump version to 0.6.5.
* gptel-transient.el (gptel--crowdsourced-prompts-url,
gptel--crowdsourced-prompts, gptel-menu, gptel-system-prompt,
gptel-rewrite-menu, gptel--infix-max-tokens,
gptel--suffix-system-message): Ditto.
* gptel-ollama.el (gptel--request-data): Ditto
* gptel-kagi.el (gptel--request-data): Ditto
* gptel-curl.el (gptel-curl--stream-insert-response,
gptel-curl--stream-cleanup, gptel-curl--stream-filter): Ditto
2024-02-03 14:20:41 -08:00
|
|
|
|
"Change parameters of prompt to send to the LLM."
|
2023-04-09 04:19:02 -07:00
|
|
|
|
;; :incompatible '(("-m" "-n" "-k" "-e"))
|
|
|
|
|
[:description
|
2024-03-14 22:53:45 -07:00
|
|
|
|
(lambda ()
|
|
|
|
|
(string-replace
|
|
|
|
|
"\n" "⮐ "
|
|
|
|
|
(truncate-string-to-width
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
gptel--system-message (max (- (window-width) 12) 14) nil nil t)))
|
2024-03-14 22:53:45 -07:00
|
|
|
|
[""
|
|
|
|
|
"Instructions"
|
2024-03-15 14:53:35 -07:00
|
|
|
|
("s" "Set system message" gptel-system-prompt :transient t)
|
2024-03-15 22:47:59 -07:00
|
|
|
|
(gptel--infix-add-directive)]]
|
2024-03-20 19:46:41 -07:00
|
|
|
|
[["Model Parameters"
|
|
|
|
|
:pad-keys t
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
(gptel--infix-variable-scope)
|
gptel: Add multi-llm support
README.org: Update README with new information and a multi-llm demo.
gptel.el (gptel-host, gptel--known-backends, gptel--api-key,
gptel--create-prompt, gptel--request-data, gptel--parse-buffer, gptel-request,
gptel--parse-response, gptel--openai, gptel--debug, gptel--restore-state,
gptel, gptel-backend):
Integrate multiple LLMs through the introcution of gptel-backends. Each backend
is composed of two pieces:
1. An instance of a cl-struct, containing connection, authentication and model
information. See the cl-struct `gptel-backend` for details. A separate
cl-struct type is defined for each supported backend (OpenAI, Azure, GPT4All and
Ollama) that inherits from the generic gptel-backend type.
2. cl-generic implementations of specific tasks, like gathering up and
formatting context (previous user queries and LLM responses), parsing responses
or responses streams etc. The four tasks currently specialized this way are
carried out by `gptel--parse-buffer` and `gptel--request-data` (for constructing
the query) and `gptel--parse-response` and `gptel-curl--parse-stream` (for
parsing the response). See their implementations for details. Some effort has
been made to limit the number of times dispatching is done when reading
streaming responses.
When a backend is created, it is registered in the collection
`gptel--known-backends` and can be accessed by name later, such as from the
transient menu.
Only one of these backends is active at any time in a buffer, stored in the
buffer-local variable `gptel-backend`. Most messaging, authentication etc
accounts for the active backend, although there might be some leftovers.
When using `gptel-request` or `gptel-send`, the active backend can be changed or
let-bound.
- Obsolete `gptel-host`
- Fix the rear-sticky property when restoring sessions from files.
- Document some variables (not user options), like `gptel--debug`
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure,
gptel-make-gpt4all): This file (currently always loaded) sets up the generic
backend struct and includes constructors for creating OpenAI, GPT4All and Azure
backends. They all use the same API so a single set of defgeneric
implemenations suffices for all of them.
gptel-ollama.el (gptel-make-ollama): This file includes the cl-struct,
constructor and requisite defgeneric implementations for Ollama support.
gptel-transient.el (gptel-menu, gptel-provider-variable, gptel--infix-provider,
gptel-suffix-send):
- Provide access to all available LLM backends and models from `gptel-menu`.
- Adjust keybindings in gptel-menu: setting the model and query parameters is
now bound to two char keybinds, while redirecting input and output is bound to
single keys.
2023-10-23 23:40:52 -07:00
|
|
|
|
(gptel--infix-provider)
|
2023-04-09 04:19:02 -07:00
|
|
|
|
(gptel--infix-max-tokens)
|
|
|
|
|
(gptel--infix-num-messages-to-send)
|
2024-03-15 14:53:35 -07:00
|
|
|
|
(gptel--infix-temperature :if (lambda () gptel-expert-commands))]
|
gptel: Add response regeneration, history and ediff
* gptel.el (gptel--attach-response-history, gptel--ediff,
gptel--next-variant, gptel--previous-variant,
gptel--mark-response):
Add `gptel--attach-response-history` -- this can be used to add
text properties to the next gptel response in the buffer. This
is (currently) useful for tracking changes when the response
overwrites existing text.
The next three commands -- `gptel--ediff`,
`gptel--previous-variant`, `gptel--next-variant` -- provide
facilities for manipulating a gptel response at point when there
is history. `gptel--mark-response` marks the response at point.
These are considered internal functions for now and can be
accessed from the transient menu, where they work together with
`gptel--regenerate`.
The input arguments to these commands are expected to change to
support copilot-style functionality in the near future.
* gptel-transient.el (gptel-menu, gptel--suffix-send,
gptel--regenerate):
Change the transient menu layout to be more compact (with a newly
added column.) When overwriting the prompt with a response, save
the prompt to the gptel response's history. Add
`gptel--regenerate` to regenerate a response. This is accessible
from the transient menu when the point is inside response text.
2024-02-04 21:09:53 -08:00
|
|
|
|
["Prompt from"
|
2024-03-15 14:53:35 -07:00
|
|
|
|
("m" "Minibuffer instead" "m")
|
gptel: Add response regeneration, history and ediff
* gptel.el (gptel--attach-response-history, gptel--ediff,
gptel--next-variant, gptel--previous-variant,
gptel--mark-response):
Add `gptel--attach-response-history` -- this can be used to add
text properties to the next gptel response in the buffer. This
is (currently) useful for tracking changes when the response
overwrites existing text.
The next three commands -- `gptel--ediff`,
`gptel--previous-variant`, `gptel--next-variant` -- provide
facilities for manipulating a gptel response at point when there
is history. `gptel--mark-response` marks the response at point.
These are considered internal functions for now and can be
accessed from the transient menu, where they work together with
`gptel--regenerate`.
The input arguments to these commands are expected to change to
support copilot-style functionality in the near future.
* gptel-transient.el (gptel-menu, gptel--suffix-send,
gptel--regenerate):
Change the transient menu layout to be more compact (with a newly
added column.) When overwriting the prompt with a response, save
the prompt to the gptel response's history. Add
`gptel--regenerate` to regenerate a response. This is accessible
from the transient menu when the point is inside response text.
2024-02-04 21:09:53 -08:00
|
|
|
|
("y" "Kill-ring instead" "y")
|
|
|
|
|
""
|
2024-03-15 14:53:35 -07:00
|
|
|
|
("i" "Respond in place" "i")]
|
gptel: Add response regeneration, history and ediff
* gptel.el (gptel--attach-response-history, gptel--ediff,
gptel--next-variant, gptel--previous-variant,
gptel--mark-response):
Add `gptel--attach-response-history` -- this can be used to add
text properties to the next gptel response in the buffer. This
is (currently) useful for tracking changes when the response
overwrites existing text.
The next three commands -- `gptel--ediff`,
`gptel--previous-variant`, `gptel--next-variant` -- provide
facilities for manipulating a gptel response at point when there
is history. `gptel--mark-response` marks the response at point.
These are considered internal functions for now and can be
accessed from the transient menu, where they work together with
`gptel--regenerate`.
The input arguments to these commands are expected to change to
support copilot-style functionality in the near future.
* gptel-transient.el (gptel-menu, gptel--suffix-send,
gptel--regenerate):
Change the transient menu layout to be more compact (with a newly
added column.) When overwriting the prompt with a response, save
the prompt to the gptel response's history. Add
`gptel--regenerate` to regenerate a response. This is accessible
from the transient menu when the point is inside response text.
2024-02-04 21:09:53 -08:00
|
|
|
|
["Response to"
|
2024-03-15 14:53:35 -07:00
|
|
|
|
("e" "Echo area instead" "e")
|
2024-01-22 17:11:26 -08:00
|
|
|
|
("g" "gptel session" "g"
|
2023-04-09 04:19:02 -07:00
|
|
|
|
:class transient-option
|
2024-01-22 17:11:26 -08:00
|
|
|
|
:prompt "Existing or new gptel session: "
|
2023-04-09 04:19:02 -07:00
|
|
|
|
:reader
|
2024-01-22 17:11:26 -08:00
|
|
|
|
(lambda (prompt _ _history)
|
|
|
|
|
(read-buffer
|
2024-01-05 21:53:20 -08:00
|
|
|
|
prompt (generate-new-buffer-name
|
|
|
|
|
(concat "*" (gptel-backend-name gptel-backend) "*"))
|
2024-01-22 17:11:26 -08:00
|
|
|
|
nil (lambda (buf-name)
|
|
|
|
|
(if (consp buf-name) (setq buf-name (car buf-name)))
|
|
|
|
|
(let ((buf (get-buffer buf-name)))
|
|
|
|
|
(and (buffer-local-value 'gptel-mode buf)
|
|
|
|
|
(not (eq (current-buffer) buf))))))))
|
|
|
|
|
("b" "Any buffer" "b"
|
2023-04-09 04:19:02 -07:00
|
|
|
|
:class transient-option
|
2024-01-22 17:11:26 -08:00
|
|
|
|
:prompt "Output to buffer: "
|
2023-04-09 04:19:02 -07:00
|
|
|
|
:reader
|
2024-01-22 17:11:26 -08:00
|
|
|
|
(lambda (prompt _ _history)
|
|
|
|
|
(read-buffer prompt (buffer-name (other-buffer)) nil)))
|
gptel: Add response regeneration, history and ediff
* gptel.el (gptel--attach-response-history, gptel--ediff,
gptel--next-variant, gptel--previous-variant,
gptel--mark-response):
Add `gptel--attach-response-history` -- this can be used to add
text properties to the next gptel response in the buffer. This
is (currently) useful for tracking changes when the response
overwrites existing text.
The next three commands -- `gptel--ediff`,
`gptel--previous-variant`, `gptel--next-variant` -- provide
facilities for manipulating a gptel response at point when there
is history. `gptel--mark-response` marks the response at point.
These are considered internal functions for now and can be
accessed from the transient menu, where they work together with
`gptel--regenerate`.
The input arguments to these commands are expected to change to
support copilot-style functionality in the near future.
* gptel-transient.el (gptel-menu, gptel--suffix-send,
gptel--regenerate):
Change the transient menu layout to be more compact (with a newly
added column.) When overwriting the prompt with a response, save
the prompt to the gptel response's history. Add
`gptel--regenerate` to regenerate a response. This is accessible
from the transient menu when the point is inside response text.
2024-02-04 21:09:53 -08:00
|
|
|
|
("k" "Kill-ring" "k")]]
|
|
|
|
|
[["Send"
|
|
|
|
|
(gptel--suffix-send)
|
|
|
|
|
("M-RET" "Regenerate" gptel--regenerate :if gptel--in-response-p)]
|
2023-04-09 04:12:13 -07:00
|
|
|
|
[:description gptel--refactor-or-rewrite
|
|
|
|
|
:if use-region-p
|
|
|
|
|
("r"
|
|
|
|
|
;;FIXME: Transient complains if I use `gptel--refactor-or-rewrite' here. It
|
|
|
|
|
;;reads this function as a suffix instead of a function that returns the
|
|
|
|
|
;;description.
|
|
|
|
|
(lambda () (if (derived-mode-p 'prog-mode)
|
|
|
|
|
"Refactor" "Rewrite"))
|
|
|
|
|
gptel-rewrite-menu)]
|
gptel: Add response regeneration, history and ediff
* gptel.el (gptel--attach-response-history, gptel--ediff,
gptel--next-variant, gptel--previous-variant,
gptel--mark-response):
Add `gptel--attach-response-history` -- this can be used to add
text properties to the next gptel response in the buffer. This
is (currently) useful for tracking changes when the response
overwrites existing text.
The next three commands -- `gptel--ediff`,
`gptel--previous-variant`, `gptel--next-variant` -- provide
facilities for manipulating a gptel response at point when there
is history. `gptel--mark-response` marks the response at point.
These are considered internal functions for now and can be
accessed from the transient menu, where they work together with
`gptel--regenerate`.
The input arguments to these commands are expected to change to
support copilot-style functionality in the near future.
* gptel-transient.el (gptel-menu, gptel--suffix-send,
gptel--regenerate):
Change the transient menu layout to be more compact (with a newly
added column.) When overwriting the prompt with a response, save
the prompt to the gptel response's history. Add
`gptel--regenerate` to regenerate a response. This is accessible
from the transient menu when the point is inside response text.
2024-02-04 21:09:53 -08:00
|
|
|
|
["Tweak Response" :if gptel--in-response-p :pad-keys t
|
|
|
|
|
("SPC" "Mark" gptel--mark-response)
|
|
|
|
|
("P" "Previous variant" gptel--previous-variant
|
|
|
|
|
:if gptel--at-response-history-p
|
|
|
|
|
:transient t)
|
|
|
|
|
("N" "Next variant" gptel--previous-variant
|
|
|
|
|
:if gptel--at-response-history-p
|
|
|
|
|
:transient t)
|
|
|
|
|
("E" "Ediff previous" gptel--ediff
|
2024-03-13 21:58:24 -07:00
|
|
|
|
:if gptel--at-response-history-p)]
|
2024-03-14 22:53:45 -07:00
|
|
|
|
["Dry Run" :if (lambda () (or gptel-log-level gptel-expert-commands))
|
|
|
|
|
("I" "Inspect query (Lisp)"
|
2024-03-13 21:58:24 -07:00
|
|
|
|
(lambda ()
|
|
|
|
|
"Inspect the query that will be sent as a lisp object."
|
|
|
|
|
(interactive)
|
2024-03-15 15:12:07 -07:00
|
|
|
|
(let* ((extra (gptel--get-directive
|
2024-03-14 22:53:45 -07:00
|
|
|
|
(transient-args
|
|
|
|
|
transient-current-command)))
|
|
|
|
|
(gptel--system-message
|
|
|
|
|
(concat gptel--system-message extra)))
|
|
|
|
|
(gptel--sanitize-model)
|
|
|
|
|
(gptel--inspect-query))))
|
|
|
|
|
("J" "Inspect query (JSON)"
|
2024-03-13 21:58:24 -07:00
|
|
|
|
(lambda ()
|
|
|
|
|
"Inspect the query that will be sent as a JSON object."
|
|
|
|
|
(interactive)
|
2024-03-15 15:12:07 -07:00
|
|
|
|
(let* ((extra (gptel--get-directive
|
2024-03-14 22:53:45 -07:00
|
|
|
|
(transient-args
|
|
|
|
|
transient-current-command)))
|
|
|
|
|
(gptel--system-message
|
|
|
|
|
(concat gptel--system-message extra)))
|
|
|
|
|
(gptel--sanitize-model)
|
|
|
|
|
(gptel--inspect-query 'json))))]]
|
2024-01-18 02:33:39 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(gptel--sanitize-model)
|
|
|
|
|
(transient-setup 'gptel-menu))
|
2023-03-09 16:56:26 -08:00
|
|
|
|
|
2023-04-09 04:16:09 -07:00
|
|
|
|
;; ** Prefix for setting the system prompt.
|
2023-05-19 21:01:01 -07:00
|
|
|
|
(defun gptel-system-prompt--setup (_)
|
|
|
|
|
"Set up suffixes for system prompt."
|
|
|
|
|
(transient-parse-suffixes
|
|
|
|
|
'gptel-system-prompt
|
|
|
|
|
(cl-loop for (type . prompt) in gptel-directives
|
2024-02-28 07:36:06 +01:00
|
|
|
|
;; Avoid clashes with the custom directive key
|
2024-03-15 14:53:35 -07:00
|
|
|
|
with unused-keys = (delete ?s (number-sequence ?a ?z))
|
2024-01-11 17:41:09 -08:00
|
|
|
|
with width = (window-width)
|
2023-05-19 21:01:01 -07:00
|
|
|
|
for name = (symbol-name type)
|
2024-02-28 07:36:06 +01:00
|
|
|
|
for key = (seq-find (lambda (k) (member k unused-keys)) name (seq-first unused-keys))
|
|
|
|
|
do (setq unused-keys (delete key unused-keys))
|
2023-12-25 13:58:23 -08:00
|
|
|
|
;; The explicit declaration ":transient transient--do-return" here
|
|
|
|
|
;; appears to be required for Transient v0.5 and up. Without it, these
|
|
|
|
|
;; are treated as suffixes when invoking `gptel-system-prompt' directly,
|
|
|
|
|
;; and infixes when going through `gptel-menu'.
|
|
|
|
|
;; TODO: Raise an issue with Transient.
|
2024-02-28 07:36:06 +01:00
|
|
|
|
collect (list (key-description (list key))
|
2024-01-11 17:41:09 -08:00
|
|
|
|
(concat (capitalize name) " "
|
|
|
|
|
(propertize " " 'display '(space :align-to 20))
|
|
|
|
|
(propertize
|
|
|
|
|
(concat
|
|
|
|
|
"("
|
|
|
|
|
(string-replace
|
|
|
|
|
"\n" " "
|
|
|
|
|
(truncate-string-to-width prompt (- width 30) nil nil t))
|
|
|
|
|
")")
|
|
|
|
|
'face 'shadow))
|
|
|
|
|
`(lambda () (interactive)
|
2024-03-13 15:29:08 -07:00
|
|
|
|
(message "Directive: %s"
|
|
|
|
|
,(string-replace "\n" "⮐ "
|
|
|
|
|
(truncate-string-to-width prompt 100 nil nil t)))
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
(gptel--set-with-scope 'gptel--system-message ,prompt
|
|
|
|
|
gptel--set-buffer-locally))
|
2024-01-11 17:41:09 -08:00
|
|
|
|
:transient 'transient--do-return)
|
2023-05-19 21:01:01 -07:00
|
|
|
|
into prompt-suffixes
|
2023-07-10 02:09:16 -07:00
|
|
|
|
finally return
|
|
|
|
|
(nconc
|
|
|
|
|
prompt-suffixes
|
|
|
|
|
(list (list "SPC" "Pick crowdsourced prompt"
|
2023-12-25 13:58:23 -08:00
|
|
|
|
'gptel--read-crowdsourced-prompt
|
2023-12-26 10:22:47 -08:00
|
|
|
|
;; NOTE: Quitting the completing read when picking a
|
|
|
|
|
;; crowdsourced prompt will cause the transient to exit
|
|
|
|
|
;; instead of returning to the system prompt menu.
|
|
|
|
|
:transient 'transient--do-exit))))))
|
2023-05-03 14:29:45 -07:00
|
|
|
|
|
2023-03-09 16:56:26 -08:00
|
|
|
|
(transient-define-prefix gptel-system-prompt ()
|
2024-03-14 22:53:45 -07:00
|
|
|
|
"Set the LLM system message for LLM interactions in this buffer.
|
2023-03-09 16:56:26 -08:00
|
|
|
|
|
2024-03-14 22:53:45 -07:00
|
|
|
|
The \"system message\" establishes directives for the chat
|
|
|
|
|
session and modifies the behavior of the LLM. Some examples of
|
|
|
|
|
system prompts are:
|
2023-03-09 16:56:26 -08:00
|
|
|
|
|
|
|
|
|
You are a helpful assistant. Answer as concisely as possible.
|
|
|
|
|
Reply only with shell commands and no prose.
|
|
|
|
|
You are a poet. Reply only in verse.
|
|
|
|
|
|
2024-03-14 22:53:45 -07:00
|
|
|
|
More extensive system messages can be useful for specific tasks.
|
|
|
|
|
|
2023-03-24 17:30:02 -07:00
|
|
|
|
Customize `gptel-directives' for task-specific prompts."
|
2023-03-09 16:56:26 -08:00
|
|
|
|
[:description
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
(lambda () (string-replace
|
|
|
|
|
"\n" "⮐ "
|
|
|
|
|
(truncate-string-to-width
|
|
|
|
|
gptel--system-message (max (- (window-width) 12) 14) nil nil t)))
|
|
|
|
|
[(gptel--suffix-system-message)]
|
|
|
|
|
[(gptel--infix-variable-scope)]]
|
|
|
|
|
[:class transient-column
|
|
|
|
|
:setup-children gptel-system-prompt--setup
|
|
|
|
|
:pad-keys t])
|
2023-03-09 16:56:26 -08:00
|
|
|
|
|
2023-04-09 04:16:09 -07:00
|
|
|
|
;; ** Prefix for rewriting/refactoring
|
|
|
|
|
|
2023-04-09 04:12:13 -07:00
|
|
|
|
(transient-define-prefix gptel-rewrite-menu ()
|
gptel: docstrings for multi-LLM support, bump version
* gptel.el (gptel, gptel--insert-response, gptel-temperature,
gptel-pre-response-hook, gptel-response-filter-functions,
gptel-stream, gptel--convert-org, gptel-pre-response-hook,
gptel-max-tokens, gptel-mode, gptel-request,
gptel--insert-response, gptel-set-topic, gptel--convert-org):
Replace mentions of "ChatGPT" with "LLM" or equivalent. Update
package description and remove commented out obsolete code.
Bump version to 0.6.5.
* gptel-transient.el (gptel--crowdsourced-prompts-url,
gptel--crowdsourced-prompts, gptel-menu, gptel-system-prompt,
gptel-rewrite-menu, gptel--infix-max-tokens,
gptel--suffix-system-message): Ditto.
* gptel-ollama.el (gptel--request-data): Ditto
* gptel-kagi.el (gptel--request-data): Ditto
* gptel-curl.el (gptel-curl--stream-insert-response,
gptel-curl--stream-cleanup, gptel-curl--stream-filter): Ditto
2024-02-03 14:20:41 -08:00
|
|
|
|
"Rewrite or refactor text region using an LLM."
|
2023-04-09 04:12:13 -07:00
|
|
|
|
[:description
|
|
|
|
|
(lambda ()
|
|
|
|
|
(format "Directive: %s"
|
|
|
|
|
(truncate-string-to-width
|
|
|
|
|
(or gptel--rewrite-message (gptel--rewrite-message))
|
|
|
|
|
(max (- (window-width) 14) 20) nil nil t)))
|
|
|
|
|
(gptel--infix-rewrite-prompt)]
|
|
|
|
|
[[:description "Diff Options"
|
|
|
|
|
("-w" "Wordwise diff" "-w")]
|
|
|
|
|
[:description
|
|
|
|
|
(lambda () (if (derived-mode-p 'prog-mode)
|
|
|
|
|
"Refactor" "Rewrite"))
|
|
|
|
|
(gptel--suffix-rewrite)
|
|
|
|
|
(gptel--suffix-rewrite-and-replace)
|
|
|
|
|
(gptel--suffix-rewrite-and-ediff)]]
|
|
|
|
|
(interactive)
|
|
|
|
|
(unless gptel--rewrite-message
|
|
|
|
|
(setq gptel--rewrite-message (gptel--rewrite-message)))
|
|
|
|
|
(transient-setup 'gptel-rewrite-menu))
|
2023-04-09 04:16:09 -07:00
|
|
|
|
|
2024-02-04 21:06:14 -08:00
|
|
|
|
|
2023-04-09 04:16:09 -07:00
|
|
|
|
;; * Transient Infixes
|
|
|
|
|
|
|
|
|
|
;; ** Infixes for model parameters
|
|
|
|
|
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
(transient-define-infix gptel--infix-variable-scope ()
|
|
|
|
|
"Set gptel's model parameters and system message in this buffer or globally."
|
|
|
|
|
:argument "scope"
|
|
|
|
|
:variable 'gptel--set-buffer-locally
|
|
|
|
|
:class 'gptel--switches
|
|
|
|
|
:format " %k %d %v"
|
|
|
|
|
:key "="
|
|
|
|
|
:description (propertize "Set" 'face 'transient-inactive-argument))
|
2024-03-13 22:05:11 -07:00
|
|
|
|
|
2023-03-09 16:56:26 -08:00
|
|
|
|
(transient-define-infix gptel--infix-num-messages-to-send ()
|
|
|
|
|
"Number of recent messages to send with each exchange.
|
|
|
|
|
|
|
|
|
|
By default, the full conversation history is sent with every new
|
|
|
|
|
prompt. This retains the full context of the conversation, but
|
|
|
|
|
can be expensive in token size. Set how many recent messages to
|
|
|
|
|
include."
|
2024-03-13 22:05:11 -07:00
|
|
|
|
:description "previous responses"
|
|
|
|
|
:class 'gptel-lisp-variable
|
2023-03-09 16:56:26 -08:00
|
|
|
|
:variable 'gptel--num-messages-to-send
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
:set-value #'gptel--set-with-scope
|
2024-03-13 22:05:11 -07:00
|
|
|
|
:display-nil 'all
|
|
|
|
|
:format " %k %v %d"
|
gptel: Add multi-llm support
README.org: Update README with new information and a multi-llm demo.
gptel.el (gptel-host, gptel--known-backends, gptel--api-key,
gptel--create-prompt, gptel--request-data, gptel--parse-buffer, gptel-request,
gptel--parse-response, gptel--openai, gptel--debug, gptel--restore-state,
gptel, gptel-backend):
Integrate multiple LLMs through the introcution of gptel-backends. Each backend
is composed of two pieces:
1. An instance of a cl-struct, containing connection, authentication and model
information. See the cl-struct `gptel-backend` for details. A separate
cl-struct type is defined for each supported backend (OpenAI, Azure, GPT4All and
Ollama) that inherits from the generic gptel-backend type.
2. cl-generic implementations of specific tasks, like gathering up and
formatting context (previous user queries and LLM responses), parsing responses
or responses streams etc. The four tasks currently specialized this way are
carried out by `gptel--parse-buffer` and `gptel--request-data` (for constructing
the query) and `gptel--parse-response` and `gptel-curl--parse-stream` (for
parsing the response). See their implementations for details. Some effort has
been made to limit the number of times dispatching is done when reading
streaming responses.
When a backend is created, it is registered in the collection
`gptel--known-backends` and can be accessed by name later, such as from the
transient menu.
Only one of these backends is active at any time in a buffer, stored in the
buffer-local variable `gptel-backend`. Most messaging, authentication etc
accounts for the active backend, although there might be some leftovers.
When using `gptel-request` or `gptel-send`, the active backend can be changed or
let-bound.
- Obsolete `gptel-host`
- Fix the rear-sticky property when restoring sessions from files.
- Document some variables (not user options), like `gptel--debug`
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure,
gptel-make-gpt4all): This file (currently always loaded) sets up the generic
backend struct and includes constructors for creating OpenAI, GPT4All and Azure
backends. They all use the same API so a single set of defgeneric
implemenations suffices for all of them.
gptel-ollama.el (gptel-make-ollama): This file includes the cl-struct,
constructor and requisite defgeneric implementations for Ollama support.
gptel-transient.el (gptel-menu, gptel-provider-variable, gptel--infix-provider,
gptel-suffix-send):
- Provide access to all available LLM backends and models from `gptel-menu`.
- Adjust keybindings in gptel-menu: setting the model and query parameters is
now bound to two char keybinds, while redirecting input and output is bound to
single keys.
2023-10-23 23:40:52 -07:00
|
|
|
|
:key "-n"
|
2023-03-14 02:06:01 -07:00
|
|
|
|
:prompt "Number of past messages to include for context (leave empty for all): "
|
2023-07-21 12:33:00 +08:00
|
|
|
|
:reader 'gptel--transient-read-variable)
|
2023-03-09 16:56:26 -08:00
|
|
|
|
|
|
|
|
|
(transient-define-infix gptel--infix-max-tokens ()
|
|
|
|
|
"Max tokens per response.
|
|
|
|
|
|
|
|
|
|
This is roughly the number of words in the response. 100-300 is a
|
|
|
|
|
reasonable range for short answers, 400 or more for longer
|
gptel: docstrings for multi-LLM support, bump version
* gptel.el (gptel, gptel--insert-response, gptel-temperature,
gptel-pre-response-hook, gptel-response-filter-functions,
gptel-stream, gptel--convert-org, gptel-pre-response-hook,
gptel-max-tokens, gptel-mode, gptel-request,
gptel--insert-response, gptel-set-topic, gptel--convert-org):
Replace mentions of "ChatGPT" with "LLM" or equivalent. Update
package description and remove commented out obsolete code.
Bump version to 0.6.5.
* gptel-transient.el (gptel--crowdsourced-prompts-url,
gptel--crowdsourced-prompts, gptel-menu, gptel-system-prompt,
gptel-rewrite-menu, gptel--infix-max-tokens,
gptel--suffix-system-message): Ditto.
* gptel-ollama.el (gptel--request-data): Ditto
* gptel-kagi.el (gptel--request-data): Ditto
* gptel-curl.el (gptel-curl--stream-insert-response,
gptel-curl--stream-cleanup, gptel-curl--stream-filter): Ditto
2024-02-03 14:20:41 -08:00
|
|
|
|
responses."
|
2023-03-09 16:56:26 -08:00
|
|
|
|
:description "Response length (tokens)"
|
2024-03-13 22:05:11 -07:00
|
|
|
|
:class 'gptel-lisp-variable
|
2023-03-24 17:30:02 -07:00
|
|
|
|
:variable 'gptel-max-tokens
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
:set-value #'gptel--set-with-scope
|
2024-03-13 22:05:11 -07:00
|
|
|
|
:display-nil 'auto
|
gptel: Add multi-llm support
README.org: Update README with new information and a multi-llm demo.
gptel.el (gptel-host, gptel--known-backends, gptel--api-key,
gptel--create-prompt, gptel--request-data, gptel--parse-buffer, gptel-request,
gptel--parse-response, gptel--openai, gptel--debug, gptel--restore-state,
gptel, gptel-backend):
Integrate multiple LLMs through the introcution of gptel-backends. Each backend
is composed of two pieces:
1. An instance of a cl-struct, containing connection, authentication and model
information. See the cl-struct `gptel-backend` for details. A separate
cl-struct type is defined for each supported backend (OpenAI, Azure, GPT4All and
Ollama) that inherits from the generic gptel-backend type.
2. cl-generic implementations of specific tasks, like gathering up and
formatting context (previous user queries and LLM responses), parsing responses
or responses streams etc. The four tasks currently specialized this way are
carried out by `gptel--parse-buffer` and `gptel--request-data` (for constructing
the query) and `gptel--parse-response` and `gptel-curl--parse-stream` (for
parsing the response). See their implementations for details. Some effort has
been made to limit the number of times dispatching is done when reading
streaming responses.
When a backend is created, it is registered in the collection
`gptel--known-backends` and can be accessed by name later, such as from the
transient menu.
Only one of these backends is active at any time in a buffer, stored in the
buffer-local variable `gptel-backend`. Most messaging, authentication etc
accounts for the active backend, although there might be some leftovers.
When using `gptel-request` or `gptel-send`, the active backend can be changed or
let-bound.
- Obsolete `gptel-host`
- Fix the rear-sticky property when restoring sessions from files.
- Document some variables (not user options), like `gptel--debug`
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure,
gptel-make-gpt4all): This file (currently always loaded) sets up the generic
backend struct and includes constructors for creating OpenAI, GPT4All and Azure
backends. They all use the same API so a single set of defgeneric
implemenations suffices for all of them.
gptel-ollama.el (gptel-make-ollama): This file includes the cl-struct,
constructor and requisite defgeneric implementations for Ollama support.
gptel-transient.el (gptel-menu, gptel-provider-variable, gptel--infix-provider,
gptel-suffix-send):
- Provide access to all available LLM backends and models from `gptel-menu`.
- Adjust keybindings in gptel-menu: setting the model and query parameters is
now bound to two char keybinds, while redirecting input and output is bound to
single keys.
2023-10-23 23:40:52 -07:00
|
|
|
|
:key "-c"
|
2023-03-09 16:56:26 -08:00
|
|
|
|
:prompt "Response length in tokens (leave empty: default, 80-200: short, 200-500: long): "
|
2023-07-21 12:33:00 +08:00
|
|
|
|
:reader 'gptel--transient-read-variable)
|
2023-03-09 16:56:26 -08:00
|
|
|
|
|
gptel: Add multi-llm support
README.org: Update README with new information and a multi-llm demo.
gptel.el (gptel-host, gptel--known-backends, gptel--api-key,
gptel--create-prompt, gptel--request-data, gptel--parse-buffer, gptel-request,
gptel--parse-response, gptel--openai, gptel--debug, gptel--restore-state,
gptel, gptel-backend):
Integrate multiple LLMs through the introcution of gptel-backends. Each backend
is composed of two pieces:
1. An instance of a cl-struct, containing connection, authentication and model
information. See the cl-struct `gptel-backend` for details. A separate
cl-struct type is defined for each supported backend (OpenAI, Azure, GPT4All and
Ollama) that inherits from the generic gptel-backend type.
2. cl-generic implementations of specific tasks, like gathering up and
formatting context (previous user queries and LLM responses), parsing responses
or responses streams etc. The four tasks currently specialized this way are
carried out by `gptel--parse-buffer` and `gptel--request-data` (for constructing
the query) and `gptel--parse-response` and `gptel-curl--parse-stream` (for
parsing the response). See their implementations for details. Some effort has
been made to limit the number of times dispatching is done when reading
streaming responses.
When a backend is created, it is registered in the collection
`gptel--known-backends` and can be accessed by name later, such as from the
transient menu.
Only one of these backends is active at any time in a buffer, stored in the
buffer-local variable `gptel-backend`. Most messaging, authentication etc
accounts for the active backend, although there might be some leftovers.
When using `gptel-request` or `gptel-send`, the active backend can be changed or
let-bound.
- Obsolete `gptel-host`
- Fix the rear-sticky property when restoring sessions from files.
- Document some variables (not user options), like `gptel--debug`
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure,
gptel-make-gpt4all): This file (currently always loaded) sets up the generic
backend struct and includes constructors for creating OpenAI, GPT4All and Azure
backends. They all use the same API so a single set of defgeneric
implemenations suffices for all of them.
gptel-ollama.el (gptel-make-ollama): This file includes the cl-struct,
constructor and requisite defgeneric implementations for Ollama support.
gptel-transient.el (gptel-menu, gptel-provider-variable, gptel--infix-provider,
gptel-suffix-send):
- Provide access to all available LLM backends and models from `gptel-menu`.
- Adjust keybindings in gptel-menu: setting the model and query parameters is
now bound to two char keybinds, while redirecting input and output is bound to
single keys.
2023-10-23 23:40:52 -07:00
|
|
|
|
(transient-define-infix gptel--infix-provider ()
|
|
|
|
|
"AI Provider for Chat."
|
2024-03-13 22:05:11 -07:00
|
|
|
|
:description "GPT Model"
|
gptel: Add multi-llm support
README.org: Update README with new information and a multi-llm demo.
gptel.el (gptel-host, gptel--known-backends, gptel--api-key,
gptel--create-prompt, gptel--request-data, gptel--parse-buffer, gptel-request,
gptel--parse-response, gptel--openai, gptel--debug, gptel--restore-state,
gptel, gptel-backend):
Integrate multiple LLMs through the introcution of gptel-backends. Each backend
is composed of two pieces:
1. An instance of a cl-struct, containing connection, authentication and model
information. See the cl-struct `gptel-backend` for details. A separate
cl-struct type is defined for each supported backend (OpenAI, Azure, GPT4All and
Ollama) that inherits from the generic gptel-backend type.
2. cl-generic implementations of specific tasks, like gathering up and
formatting context (previous user queries and LLM responses), parsing responses
or responses streams etc. The four tasks currently specialized this way are
carried out by `gptel--parse-buffer` and `gptel--request-data` (for constructing
the query) and `gptel--parse-response` and `gptel-curl--parse-stream` (for
parsing the response). See their implementations for details. Some effort has
been made to limit the number of times dispatching is done when reading
streaming responses.
When a backend is created, it is registered in the collection
`gptel--known-backends` and can be accessed by name later, such as from the
transient menu.
Only one of these backends is active at any time in a buffer, stored in the
buffer-local variable `gptel-backend`. Most messaging, authentication etc
accounts for the active backend, although there might be some leftovers.
When using `gptel-request` or `gptel-send`, the active backend can be changed or
let-bound.
- Obsolete `gptel-host`
- Fix the rear-sticky property when restoring sessions from files.
- Document some variables (not user options), like `gptel--debug`
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure,
gptel-make-gpt4all): This file (currently always loaded) sets up the generic
backend struct and includes constructors for creating OpenAI, GPT4All and Azure
backends. They all use the same API so a single set of defgeneric
implemenations suffices for all of them.
gptel-ollama.el (gptel-make-ollama): This file includes the cl-struct,
constructor and requisite defgeneric implementations for Ollama support.
gptel-transient.el (gptel-menu, gptel-provider-variable, gptel--infix-provider,
gptel-suffix-send):
- Provide access to all available LLM backends and models from `gptel-menu`.
- Adjust keybindings in gptel-menu: setting the model and query parameters is
now bound to two char keybinds, while redirecting input and output is bound to
single keys.
2023-10-23 23:40:52 -07:00
|
|
|
|
:class 'gptel-provider-variable
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
:prompt "Model: "
|
gptel: Add multi-llm support
README.org: Update README with new information and a multi-llm demo.
gptel.el (gptel-host, gptel--known-backends, gptel--api-key,
gptel--create-prompt, gptel--request-data, gptel--parse-buffer, gptel-request,
gptel--parse-response, gptel--openai, gptel--debug, gptel--restore-state,
gptel, gptel-backend):
Integrate multiple LLMs through the introcution of gptel-backends. Each backend
is composed of two pieces:
1. An instance of a cl-struct, containing connection, authentication and model
information. See the cl-struct `gptel-backend` for details. A separate
cl-struct type is defined for each supported backend (OpenAI, Azure, GPT4All and
Ollama) that inherits from the generic gptel-backend type.
2. cl-generic implementations of specific tasks, like gathering up and
formatting context (previous user queries and LLM responses), parsing responses
or responses streams etc. The four tasks currently specialized this way are
carried out by `gptel--parse-buffer` and `gptel--request-data` (for constructing
the query) and `gptel--parse-response` and `gptel-curl--parse-stream` (for
parsing the response). See their implementations for details. Some effort has
been made to limit the number of times dispatching is done when reading
streaming responses.
When a backend is created, it is registered in the collection
`gptel--known-backends` and can be accessed by name later, such as from the
transient menu.
Only one of these backends is active at any time in a buffer, stored in the
buffer-local variable `gptel-backend`. Most messaging, authentication etc
accounts for the active backend, although there might be some leftovers.
When using `gptel-request` or `gptel-send`, the active backend can be changed or
let-bound.
- Obsolete `gptel-host`
- Fix the rear-sticky property when restoring sessions from files.
- Document some variables (not user options), like `gptel--debug`
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure,
gptel-make-gpt4all): This file (currently always loaded) sets up the generic
backend struct and includes constructors for creating OpenAI, GPT4All and Azure
backends. They all use the same API so a single set of defgeneric
implemenations suffices for all of them.
gptel-ollama.el (gptel-make-ollama): This file includes the cl-struct,
constructor and requisite defgeneric implementations for Ollama support.
gptel-transient.el (gptel-menu, gptel-provider-variable, gptel--infix-provider,
gptel-suffix-send):
- Provide access to all available LLM backends and models from `gptel-menu`.
- Adjust keybindings in gptel-menu: setting the model and query parameters is
now bound to two char keybinds, while redirecting input and output is bound to
single keys.
2023-10-23 23:40:52 -07:00
|
|
|
|
:variable 'gptel-backend
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
:set-value #'gptel--set-with-scope
|
gptel: Add multi-llm support
README.org: Update README with new information and a multi-llm demo.
gptel.el (gptel-host, gptel--known-backends, gptel--api-key,
gptel--create-prompt, gptel--request-data, gptel--parse-buffer, gptel-request,
gptel--parse-response, gptel--openai, gptel--debug, gptel--restore-state,
gptel, gptel-backend):
Integrate multiple LLMs through the introcution of gptel-backends. Each backend
is composed of two pieces:
1. An instance of a cl-struct, containing connection, authentication and model
information. See the cl-struct `gptel-backend` for details. A separate
cl-struct type is defined for each supported backend (OpenAI, Azure, GPT4All and
Ollama) that inherits from the generic gptel-backend type.
2. cl-generic implementations of specific tasks, like gathering up and
formatting context (previous user queries and LLM responses), parsing responses
or responses streams etc. The four tasks currently specialized this way are
carried out by `gptel--parse-buffer` and `gptel--request-data` (for constructing
the query) and `gptel--parse-response` and `gptel-curl--parse-stream` (for
parsing the response). See their implementations for details. Some effort has
been made to limit the number of times dispatching is done when reading
streaming responses.
When a backend is created, it is registered in the collection
`gptel--known-backends` and can be accessed by name later, such as from the
transient menu.
Only one of these backends is active at any time in a buffer, stored in the
buffer-local variable `gptel-backend`. Most messaging, authentication etc
accounts for the active backend, although there might be some leftovers.
When using `gptel-request` or `gptel-send`, the active backend can be changed or
let-bound.
- Obsolete `gptel-host`
- Fix the rear-sticky property when restoring sessions from files.
- Document some variables (not user options), like `gptel--debug`
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure,
gptel-make-gpt4all): This file (currently always loaded) sets up the generic
backend struct and includes constructors for creating OpenAI, GPT4All and Azure
backends. They all use the same API so a single set of defgeneric
implemenations suffices for all of them.
gptel-ollama.el (gptel-make-ollama): This file includes the cl-struct,
constructor and requisite defgeneric implementations for Ollama support.
gptel-transient.el (gptel-menu, gptel-provider-variable, gptel--infix-provider,
gptel-suffix-send):
- Provide access to all available LLM backends and models from `gptel-menu`.
- Adjust keybindings in gptel-menu: setting the model and query parameters is
now bound to two char keybinds, while redirecting input and output is bound to
single keys.
2023-10-23 23:40:52 -07:00
|
|
|
|
:model 'gptel-model
|
|
|
|
|
:key "-m"
|
|
|
|
|
:reader (lambda (prompt &rest _)
|
2024-03-15 19:05:32 -07:00
|
|
|
|
(cl-loop
|
|
|
|
|
for (name . backend) in gptel--known-backends
|
|
|
|
|
nconc (cl-loop for model in (gptel-backend-models backend)
|
|
|
|
|
collect (list (concat name ":" model) backend model))
|
|
|
|
|
into models-alist finally return
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
(cdr (assoc (completing-read prompt models-alist nil t)
|
2024-03-15 19:05:32 -07:00
|
|
|
|
models-alist)))))
|
2023-03-09 16:56:26 -08:00
|
|
|
|
|
|
|
|
|
(transient-define-infix gptel--infix-temperature ()
|
|
|
|
|
"Temperature of request."
|
2024-03-15 14:53:35 -07:00
|
|
|
|
:description "Temperature (0 - 2.0)"
|
2023-03-09 16:56:26 -08:00
|
|
|
|
:class 'transient-lisp-variable
|
2023-03-24 17:30:02 -07:00
|
|
|
|
:variable 'gptel-temperature
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
:set-value #'gptel--set-with-scope
|
gptel: Add multi-llm support
README.org: Update README with new information and a multi-llm demo.
gptel.el (gptel-host, gptel--known-backends, gptel--api-key,
gptel--create-prompt, gptel--request-data, gptel--parse-buffer, gptel-request,
gptel--parse-response, gptel--openai, gptel--debug, gptel--restore-state,
gptel, gptel-backend):
Integrate multiple LLMs through the introcution of gptel-backends. Each backend
is composed of two pieces:
1. An instance of a cl-struct, containing connection, authentication and model
information. See the cl-struct `gptel-backend` for details. A separate
cl-struct type is defined for each supported backend (OpenAI, Azure, GPT4All and
Ollama) that inherits from the generic gptel-backend type.
2. cl-generic implementations of specific tasks, like gathering up and
formatting context (previous user queries and LLM responses), parsing responses
or responses streams etc. The four tasks currently specialized this way are
carried out by `gptel--parse-buffer` and `gptel--request-data` (for constructing
the query) and `gptel--parse-response` and `gptel-curl--parse-stream` (for
parsing the response). See their implementations for details. Some effort has
been made to limit the number of times dispatching is done when reading
streaming responses.
When a backend is created, it is registered in the collection
`gptel--known-backends` and can be accessed by name later, such as from the
transient menu.
Only one of these backends is active at any time in a buffer, stored in the
buffer-local variable `gptel-backend`. Most messaging, authentication etc
accounts for the active backend, although there might be some leftovers.
When using `gptel-request` or `gptel-send`, the active backend can be changed or
let-bound.
- Obsolete `gptel-host`
- Fix the rear-sticky property when restoring sessions from files.
- Document some variables (not user options), like `gptel--debug`
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure,
gptel-make-gpt4all): This file (currently always loaded) sets up the generic
backend struct and includes constructors for creating OpenAI, GPT4All and Azure
backends. They all use the same API so a single set of defgeneric
implemenations suffices for all of them.
gptel-ollama.el (gptel-make-ollama): This file includes the cl-struct,
constructor and requisite defgeneric implementations for Ollama support.
gptel-transient.el (gptel-menu, gptel-provider-variable, gptel--infix-provider,
gptel-suffix-send):
- Provide access to all available LLM backends and models from `gptel-menu`.
- Adjust keybindings in gptel-menu: setting the model and query parameters is
now bound to two char keybinds, while redirecting input and output is bound to
single keys.
2023-10-23 23:40:52 -07:00
|
|
|
|
:key "-t"
|
2024-03-15 14:53:35 -07:00
|
|
|
|
:prompt "Temperature controls the response randomness (0.0-2.0, leave empty for default): "
|
2023-07-21 12:33:00 +08:00
|
|
|
|
:reader 'gptel--transient-read-variable)
|
2023-03-09 16:56:26 -08:00
|
|
|
|
|
2023-04-09 04:16:09 -07:00
|
|
|
|
;; ** Infix for the refactor/rewrite system message
|
|
|
|
|
|
2024-03-15 15:12:07 -07:00
|
|
|
|
(transient-define-infix gptel--infix-add-directive ()
|
2024-03-14 22:53:45 -07:00
|
|
|
|
"Additional directive intended for the next query only.
|
|
|
|
|
|
|
|
|
|
This is useful to define a quick task on top of a more extensive
|
2024-03-15 22:47:59 -07:00
|
|
|
|
or detailed system message.
|
2024-03-14 22:53:45 -07:00
|
|
|
|
|
|
|
|
|
For example, with code/text selected:
|
|
|
|
|
|
|
|
|
|
- Rewrite this function to do X while avoiding Y.
|
|
|
|
|
- Change the tone of the following paragraph to be more direct.
|
|
|
|
|
|
|
|
|
|
Or in an extended conversation:
|
|
|
|
|
|
|
|
|
|
- Phrase you next response in ten words or less.
|
|
|
|
|
- Pretend for now that you're an anthropologist."
|
|
|
|
|
:class 'gptel-option-overlaid
|
|
|
|
|
;; :variable 'gptel--instructions
|
|
|
|
|
:display-nil 'none
|
|
|
|
|
:overlay nil
|
|
|
|
|
:argument ":"
|
|
|
|
|
:prompt "Instructions for next response only: "
|
|
|
|
|
:reader (lambda (prompt initial history)
|
|
|
|
|
(let* ((extra (read-string prompt initial history)))
|
|
|
|
|
(unless (string-empty-p extra) extra)))
|
|
|
|
|
:format " %k %d %v"
|
|
|
|
|
:key "d"
|
|
|
|
|
:argument ":"
|
2024-03-15 14:53:35 -07:00
|
|
|
|
:description "Add directive"
|
2024-03-14 22:53:45 -07:00
|
|
|
|
:transient t)
|
|
|
|
|
|
2023-04-09 04:12:13 -07:00
|
|
|
|
(transient-define-infix gptel--infix-rewrite-prompt ()
|
|
|
|
|
"Chat directive (system message) to use for rewriting or refactoring."
|
|
|
|
|
:description (lambda () (if (derived-mode-p 'prog-mode)
|
|
|
|
|
"Set directives for refactor"
|
|
|
|
|
"Set directives for rewrite"))
|
|
|
|
|
:format "%k %d"
|
|
|
|
|
:class 'transient-lisp-variable
|
|
|
|
|
:variable 'gptel--rewrite-message
|
|
|
|
|
:key "h"
|
|
|
|
|
:prompt "Set directive for rewrite: "
|
|
|
|
|
:reader (lambda (prompt _ history)
|
|
|
|
|
(read-string
|
|
|
|
|
prompt (gptel--rewrite-message) history)))
|
2023-03-09 22:58:54 -08:00
|
|
|
|
|
2024-02-04 21:06:14 -08:00
|
|
|
|
|
2023-04-09 04:16:09 -07:00
|
|
|
|
;; * Transient Suffixes
|
|
|
|
|
|
|
|
|
|
;; ** Suffix to send prompt
|
2023-04-09 04:19:02 -07:00
|
|
|
|
|
|
|
|
|
(transient-define-suffix gptel--suffix-send (args)
|
|
|
|
|
"Send ARGS."
|
|
|
|
|
:key "RET"
|
|
|
|
|
:description "Send prompt"
|
2024-03-13 22:05:11 -07:00
|
|
|
|
(interactive (list (transient-args
|
|
|
|
|
(or transient-current-command 'gptel-menu))))
|
2023-04-09 04:19:02 -07:00
|
|
|
|
(let ((stream gptel-stream)
|
gptel: Add multi-llm support
README.org: Update README with new information and a multi-llm demo.
gptel.el (gptel-host, gptel--known-backends, gptel--api-key,
gptel--create-prompt, gptel--request-data, gptel--parse-buffer, gptel-request,
gptel--parse-response, gptel--openai, gptel--debug, gptel--restore-state,
gptel, gptel-backend):
Integrate multiple LLMs through the introcution of gptel-backends. Each backend
is composed of two pieces:
1. An instance of a cl-struct, containing connection, authentication and model
information. See the cl-struct `gptel-backend` for details. A separate
cl-struct type is defined for each supported backend (OpenAI, Azure, GPT4All and
Ollama) that inherits from the generic gptel-backend type.
2. cl-generic implementations of specific tasks, like gathering up and
formatting context (previous user queries and LLM responses), parsing responses
or responses streams etc. The four tasks currently specialized this way are
carried out by `gptel--parse-buffer` and `gptel--request-data` (for constructing
the query) and `gptel--parse-response` and `gptel-curl--parse-stream` (for
parsing the response). See their implementations for details. Some effort has
been made to limit the number of times dispatching is done when reading
streaming responses.
When a backend is created, it is registered in the collection
`gptel--known-backends` and can be accessed by name later, such as from the
transient menu.
Only one of these backends is active at any time in a buffer, stored in the
buffer-local variable `gptel-backend`. Most messaging, authentication etc
accounts for the active backend, although there might be some leftovers.
When using `gptel-request` or `gptel-send`, the active backend can be changed or
let-bound.
- Obsolete `gptel-host`
- Fix the rear-sticky property when restoring sessions from files.
- Document some variables (not user options), like `gptel--debug`
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure,
gptel-make-gpt4all): This file (currently always loaded) sets up the generic
backend struct and includes constructors for creating OpenAI, GPT4All and Azure
backends. They all use the same API so a single set of defgeneric
implemenations suffices for all of them.
gptel-ollama.el (gptel-make-ollama): This file includes the cl-struct,
constructor and requisite defgeneric implementations for Ollama support.
gptel-transient.el (gptel-menu, gptel-provider-variable, gptel--infix-provider,
gptel-suffix-send):
- Provide access to all available LLM backends and models from `gptel-menu`.
- Adjust keybindings in gptel-menu: setting the model and query parameters is
now bound to two char keybinds, while redirecting input and output is bound to
single keys.
2023-10-23 23:40:52 -07:00
|
|
|
|
(in-place (and (member "i" args) t))
|
2023-04-09 04:19:02 -07:00
|
|
|
|
(output-to-other-buffer-p)
|
2023-10-31 20:18:00 -07:00
|
|
|
|
(backend gptel-backend)
|
2023-12-21 21:13:40 -08:00
|
|
|
|
(model gptel-model)
|
gptel: Add multi-llm support
README.org: Update README with new information and a multi-llm demo.
gptel.el (gptel-host, gptel--known-backends, gptel--api-key,
gptel--create-prompt, gptel--request-data, gptel--parse-buffer, gptel-request,
gptel--parse-response, gptel--openai, gptel--debug, gptel--restore-state,
gptel, gptel-backend):
Integrate multiple LLMs through the introcution of gptel-backends. Each backend
is composed of two pieces:
1. An instance of a cl-struct, containing connection, authentication and model
information. See the cl-struct `gptel-backend` for details. A separate
cl-struct type is defined for each supported backend (OpenAI, Azure, GPT4All and
Ollama) that inherits from the generic gptel-backend type.
2. cl-generic implementations of specific tasks, like gathering up and
formatting context (previous user queries and LLM responses), parsing responses
or responses streams etc. The four tasks currently specialized this way are
carried out by `gptel--parse-buffer` and `gptel--request-data` (for constructing
the query) and `gptel--parse-response` and `gptel-curl--parse-stream` (for
parsing the response). See their implementations for details. Some effort has
been made to limit the number of times dispatching is done when reading
streaming responses.
When a backend is created, it is registered in the collection
`gptel--known-backends` and can be accessed by name later, such as from the
transient menu.
Only one of these backends is active at any time in a buffer, stored in the
buffer-local variable `gptel-backend`. Most messaging, authentication etc
accounts for the active backend, although there might be some leftovers.
When using `gptel-request` or `gptel-send`, the active backend can be changed or
let-bound.
- Obsolete `gptel-host`
- Fix the rear-sticky property when restoring sessions from files.
- Document some variables (not user options), like `gptel--debug`
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure,
gptel-make-gpt4all): This file (currently always loaded) sets up the generic
backend struct and includes constructors for creating OpenAI, GPT4All and Azure
backends. They all use the same API so a single set of defgeneric
implemenations suffices for all of them.
gptel-ollama.el (gptel-make-ollama): This file includes the cl-struct,
constructor and requisite defgeneric implementations for Ollama support.
gptel-transient.el (gptel-menu, gptel-provider-variable, gptel--infix-provider,
gptel-suffix-send):
- Provide access to all available LLM backends and models from `gptel-menu`.
- Adjust keybindings in gptel-menu: setting the model and query parameters is
now bound to two char keybinds, while redirecting input and output is bound to
single keys.
2023-10-23 23:40:52 -07:00
|
|
|
|
(backend-name (gptel-backend-name gptel-backend))
|
2023-04-09 04:19:02 -07:00
|
|
|
|
(buffer) (position)
|
2023-05-03 13:42:44 -07:00
|
|
|
|
(callback) (gptel-buffer-name)
|
2024-03-15 15:12:07 -07:00
|
|
|
|
(system-extra (gptel--get-directive args))
|
2024-01-22 17:11:26 -08:00
|
|
|
|
;; Input redirection: grab prompt from elsewhere?
|
2023-04-09 04:19:02 -07:00
|
|
|
|
(prompt
|
2024-01-11 17:21:13 -08:00
|
|
|
|
(cond
|
2024-03-15 14:53:35 -07:00
|
|
|
|
((member "m" args)
|
2024-01-11 17:21:13 -08:00
|
|
|
|
(read-string
|
|
|
|
|
(format "Ask %s: " (gptel-backend-name gptel-backend))
|
2024-03-21 10:40:31 -07:00
|
|
|
|
(and (use-region-p)
|
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
|
(region-beginning) (region-end)))))
|
2024-01-11 17:21:13 -08:00
|
|
|
|
((member "y" args)
|
|
|
|
|
(unless (car-safe kill-ring)
|
2024-01-19 14:19:22 -08:00
|
|
|
|
(user-error "`kill-ring' is empty! Nothing to send"))
|
2024-01-11 17:21:13 -08:00
|
|
|
|
(if current-prefix-arg
|
|
|
|
|
(read-from-kill-ring "Prompt from kill-ring: ")
|
|
|
|
|
(current-kill 0))))))
|
2024-01-22 17:11:26 -08:00
|
|
|
|
|
|
|
|
|
;; Output redirection: Send response elsewhere?
|
2023-04-09 04:19:02 -07:00
|
|
|
|
(cond
|
2024-03-15 14:53:35 -07:00
|
|
|
|
((member "e" args)
|
2023-04-09 04:19:02 -07:00
|
|
|
|
(setq stream nil)
|
|
|
|
|
(setq callback
|
|
|
|
|
(lambda (resp info)
|
|
|
|
|
(if resp
|
gptel: Add multi-llm support
README.org: Update README with new information and a multi-llm demo.
gptel.el (gptel-host, gptel--known-backends, gptel--api-key,
gptel--create-prompt, gptel--request-data, gptel--parse-buffer, gptel-request,
gptel--parse-response, gptel--openai, gptel--debug, gptel--restore-state,
gptel, gptel-backend):
Integrate multiple LLMs through the introcution of gptel-backends. Each backend
is composed of two pieces:
1. An instance of a cl-struct, containing connection, authentication and model
information. See the cl-struct `gptel-backend` for details. A separate
cl-struct type is defined for each supported backend (OpenAI, Azure, GPT4All and
Ollama) that inherits from the generic gptel-backend type.
2. cl-generic implementations of specific tasks, like gathering up and
formatting context (previous user queries and LLM responses), parsing responses
or responses streams etc. The four tasks currently specialized this way are
carried out by `gptel--parse-buffer` and `gptel--request-data` (for constructing
the query) and `gptel--parse-response` and `gptel-curl--parse-stream` (for
parsing the response). See their implementations for details. Some effort has
been made to limit the number of times dispatching is done when reading
streaming responses.
When a backend is created, it is registered in the collection
`gptel--known-backends` and can be accessed by name later, such as from the
transient menu.
Only one of these backends is active at any time in a buffer, stored in the
buffer-local variable `gptel-backend`. Most messaging, authentication etc
accounts for the active backend, although there might be some leftovers.
When using `gptel-request` or `gptel-send`, the active backend can be changed or
let-bound.
- Obsolete `gptel-host`
- Fix the rear-sticky property when restoring sessions from files.
- Document some variables (not user options), like `gptel--debug`
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure,
gptel-make-gpt4all): This file (currently always loaded) sets up the generic
backend struct and includes constructors for creating OpenAI, GPT4All and Azure
backends. They all use the same API so a single set of defgeneric
implemenations suffices for all of them.
gptel-ollama.el (gptel-make-ollama): This file includes the cl-struct,
constructor and requisite defgeneric implementations for Ollama support.
gptel-transient.el (gptel-menu, gptel-provider-variable, gptel--infix-provider,
gptel-suffix-send):
- Provide access to all available LLM backends and models from `gptel-menu`.
- Adjust keybindings in gptel-menu: setting the model and query parameters is
now bound to two char keybinds, while redirecting input and output is bound to
single keys.
2023-10-23 23:40:52 -07:00
|
|
|
|
(message "%s response: %s" backend-name resp)
|
|
|
|
|
(message "%s response error: %s" backend-name (plist-get info :status))))))
|
|
|
|
|
((member "k" args)
|
2023-04-09 04:19:02 -07:00
|
|
|
|
(setq stream nil)
|
|
|
|
|
(setq callback
|
|
|
|
|
(lambda (resp info)
|
|
|
|
|
(if (not resp)
|
gptel: Add multi-llm support
README.org: Update README with new information and a multi-llm demo.
gptel.el (gptel-host, gptel--known-backends, gptel--api-key,
gptel--create-prompt, gptel--request-data, gptel--parse-buffer, gptel-request,
gptel--parse-response, gptel--openai, gptel--debug, gptel--restore-state,
gptel, gptel-backend):
Integrate multiple LLMs through the introcution of gptel-backends. Each backend
is composed of two pieces:
1. An instance of a cl-struct, containing connection, authentication and model
information. See the cl-struct `gptel-backend` for details. A separate
cl-struct type is defined for each supported backend (OpenAI, Azure, GPT4All and
Ollama) that inherits from the generic gptel-backend type.
2. cl-generic implementations of specific tasks, like gathering up and
formatting context (previous user queries and LLM responses), parsing responses
or responses streams etc. The four tasks currently specialized this way are
carried out by `gptel--parse-buffer` and `gptel--request-data` (for constructing
the query) and `gptel--parse-response` and `gptel-curl--parse-stream` (for
parsing the response). See their implementations for details. Some effort has
been made to limit the number of times dispatching is done when reading
streaming responses.
When a backend is created, it is registered in the collection
`gptel--known-backends` and can be accessed by name later, such as from the
transient menu.
Only one of these backends is active at any time in a buffer, stored in the
buffer-local variable `gptel-backend`. Most messaging, authentication etc
accounts for the active backend, although there might be some leftovers.
When using `gptel-request` or `gptel-send`, the active backend can be changed or
let-bound.
- Obsolete `gptel-host`
- Fix the rear-sticky property when restoring sessions from files.
- Document some variables (not user options), like `gptel--debug`
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure,
gptel-make-gpt4all): This file (currently always loaded) sets up the generic
backend struct and includes constructors for creating OpenAI, GPT4All and Azure
backends. They all use the same API so a single set of defgeneric
implemenations suffices for all of them.
gptel-ollama.el (gptel-make-ollama): This file includes the cl-struct,
constructor and requisite defgeneric implementations for Ollama support.
gptel-transient.el (gptel-menu, gptel-provider-variable, gptel--infix-provider,
gptel-suffix-send):
- Provide access to all available LLM backends and models from `gptel-menu`.
- Adjust keybindings in gptel-menu: setting the model and query parameters is
now bound to two char keybinds, while redirecting input and output is bound to
single keys.
2023-10-23 23:40:52 -07:00
|
|
|
|
(message "%s response error: %s" backend-name (plist-get info :status))
|
2023-04-09 04:19:02 -07:00
|
|
|
|
(kill-new resp)
|
2024-01-18 02:37:46 +00:00
|
|
|
|
(message "%s response: \"%s\" copied to kill-ring."
|
|
|
|
|
backend-name
|
|
|
|
|
(truncate-string-to-width resp 30))))))
|
2023-05-03 13:42:44 -07:00
|
|
|
|
((setq gptel-buffer-name
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
(cl-some (lambda (s) (and (stringp s) (string-prefix-p "g" s)
|
gptel: Add multi-llm support
README.org: Update README with new information and a multi-llm demo.
gptel.el (gptel-host, gptel--known-backends, gptel--api-key,
gptel--create-prompt, gptel--request-data, gptel--parse-buffer, gptel-request,
gptel--parse-response, gptel--openai, gptel--debug, gptel--restore-state,
gptel, gptel-backend):
Integrate multiple LLMs through the introcution of gptel-backends. Each backend
is composed of two pieces:
1. An instance of a cl-struct, containing connection, authentication and model
information. See the cl-struct `gptel-backend` for details. A separate
cl-struct type is defined for each supported backend (OpenAI, Azure, GPT4All and
Ollama) that inherits from the generic gptel-backend type.
2. cl-generic implementations of specific tasks, like gathering up and
formatting context (previous user queries and LLM responses), parsing responses
or responses streams etc. The four tasks currently specialized this way are
carried out by `gptel--parse-buffer` and `gptel--request-data` (for constructing
the query) and `gptel--parse-response` and `gptel-curl--parse-stream` (for
parsing the response). See their implementations for details. Some effort has
been made to limit the number of times dispatching is done when reading
streaming responses.
When a backend is created, it is registered in the collection
`gptel--known-backends` and can be accessed by name later, such as from the
transient menu.
Only one of these backends is active at any time in a buffer, stored in the
buffer-local variable `gptel-backend`. Most messaging, authentication etc
accounts for the active backend, although there might be some leftovers.
When using `gptel-request` or `gptel-send`, the active backend can be changed or
let-bound.
- Obsolete `gptel-host`
- Fix the rear-sticky property when restoring sessions from files.
- Document some variables (not user options), like `gptel--debug`
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure,
gptel-make-gpt4all): This file (currently always loaded) sets up the generic
backend struct and includes constructors for creating OpenAI, GPT4All and Azure
backends. They all use the same API so a single set of defgeneric
implemenations suffices for all of them.
gptel-ollama.el (gptel-make-ollama): This file includes the cl-struct,
constructor and requisite defgeneric implementations for Ollama support.
gptel-transient.el (gptel-menu, gptel-provider-variable, gptel--infix-provider,
gptel-suffix-send):
- Provide access to all available LLM backends and models from `gptel-menu`.
- Adjust keybindings in gptel-menu: setting the model and query parameters is
now bound to two char keybinds, while redirecting input and output is bound to
single keys.
2023-10-23 23:40:52 -07:00
|
|
|
|
(substring s 1)))
|
2023-04-09 04:19:02 -07:00
|
|
|
|
args))
|
|
|
|
|
(setq output-to-other-buffer-p t)
|
2024-01-22 17:11:26 -08:00
|
|
|
|
(let ((reduced-prompt ;For inserting into the gptel buffer as
|
|
|
|
|
;context, not the prompt used for the
|
|
|
|
|
;request itself
|
2023-04-10 22:45:43 -07:00
|
|
|
|
(or prompt
|
|
|
|
|
(if (use-region-p)
|
|
|
|
|
(buffer-substring-no-properties (region-beginning)
|
|
|
|
|
(region-end))
|
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
|
(save-excursion
|
|
|
|
|
(text-property-search-backward
|
|
|
|
|
'gptel 'response
|
|
|
|
|
(when (get-char-property (max (point-min) (1- (point)))
|
|
|
|
|
'gptel)
|
|
|
|
|
t))
|
|
|
|
|
(point))
|
2023-11-07 21:19:25 -08:00
|
|
|
|
(gptel--at-word-end (point)))))))
|
2024-01-22 17:11:26 -08:00
|
|
|
|
(cond
|
|
|
|
|
((buffer-live-p (get-buffer gptel-buffer-name))
|
|
|
|
|
;; Insert into existing gptel session
|
|
|
|
|
(progn
|
|
|
|
|
(setq buffer (get-buffer gptel-buffer-name))
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(unless (or buffer-read-only
|
|
|
|
|
(get-char-property (point) 'read-only))
|
|
|
|
|
(insert reduced-prompt))
|
|
|
|
|
(setq position (point))
|
|
|
|
|
(when gptel-mode
|
|
|
|
|
(gptel--update-status " Waiting..." 'warning)))))
|
|
|
|
|
;; Insert into new gptel session
|
|
|
|
|
(t (setq buffer
|
|
|
|
|
(gptel gptel-buffer-name
|
|
|
|
|
(condition-case nil
|
|
|
|
|
(gptel--get-api-key)
|
|
|
|
|
((error user-error)
|
|
|
|
|
(setq gptel-api-key
|
|
|
|
|
(read-passwd
|
|
|
|
|
(format "%s API key: "
|
|
|
|
|
(gptel-backend-name
|
|
|
|
|
gptel-backend))))))
|
|
|
|
|
reduced-prompt))
|
|
|
|
|
;; Set backend and model in new session from current buffer
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(setq gptel-backend backend)
|
|
|
|
|
(setq gptel-model model)
|
|
|
|
|
(gptel--update-status " Waiting..." 'warning)
|
|
|
|
|
(setq position (point)))))))
|
|
|
|
|
((setq gptel-buffer-name
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
(cl-some (lambda (s) (and (stringp s) (string-prefix-p "b" s)
|
2024-01-22 17:11:26 -08:00
|
|
|
|
(substring s 1)))
|
|
|
|
|
args))
|
|
|
|
|
(setq output-to-other-buffer-p t)
|
|
|
|
|
(setq buffer (get-buffer-create gptel-buffer-name))
|
|
|
|
|
(with-current-buffer buffer (setq position (point)))))
|
|
|
|
|
|
2024-03-14 22:53:45 -07:00
|
|
|
|
(gptel-request
|
|
|
|
|
prompt
|
|
|
|
|
:buffer (or buffer (current-buffer))
|
|
|
|
|
:position position
|
|
|
|
|
:in-place (and in-place (not output-to-other-buffer-p))
|
|
|
|
|
:stream stream
|
|
|
|
|
:system (concat gptel--system-message system-extra)
|
|
|
|
|
:callback callback)
|
2023-04-09 04:19:02 -07:00
|
|
|
|
|
2024-03-14 22:53:45 -07:00
|
|
|
|
;; NOTE: Possible future race condition here if Emacs ever drops the GIL.
|
|
|
|
|
;; The HTTP request callback might modify the buffer before the in-place
|
|
|
|
|
;; text is killed below.
|
2023-04-09 04:19:02 -07:00
|
|
|
|
(when in-place
|
2024-01-22 17:11:26 -08:00
|
|
|
|
;; Kill the latest prompt
|
2023-04-09 04:19:02 -07:00
|
|
|
|
(let ((beg
|
|
|
|
|
(if (use-region-p)
|
|
|
|
|
(region-beginning)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(text-property-search-backward
|
|
|
|
|
'gptel 'response
|
|
|
|
|
(when (get-char-property (max (point-min) (1- (point)))
|
|
|
|
|
'gptel)
|
|
|
|
|
t))
|
|
|
|
|
(point))))
|
|
|
|
|
(end (if (use-region-p) (region-end) (point))))
|
gptel: Add response regeneration, history and ediff
* gptel.el (gptel--attach-response-history, gptel--ediff,
gptel--next-variant, gptel--previous-variant,
gptel--mark-response):
Add `gptel--attach-response-history` -- this can be used to add
text properties to the next gptel response in the buffer. This
is (currently) useful for tracking changes when the response
overwrites existing text.
The next three commands -- `gptel--ediff`,
`gptel--previous-variant`, `gptel--next-variant` -- provide
facilities for manipulating a gptel response at point when there
is history. `gptel--mark-response` marks the response at point.
These are considered internal functions for now and can be
accessed from the transient menu, where they work together with
`gptel--regenerate`.
The input arguments to these commands are expected to change to
support copilot-style functionality in the near future.
* gptel-transient.el (gptel-menu, gptel--suffix-send,
gptel--regenerate):
Change the transient menu layout to be more compact (with a newly
added column.) When overwriting the prompt with a response, save
the prompt to the gptel response's history. Add
`gptel--regenerate` to regenerate a response. This is accessible
from the transient menu when the point is inside response text.
2024-02-04 21:09:53 -08:00
|
|
|
|
(unless output-to-other-buffer-p
|
|
|
|
|
;; store the killed text in gptel-history
|
|
|
|
|
(gptel--attach-response-history
|
|
|
|
|
(list (buffer-substring-no-properties beg end))))
|
2023-04-09 04:19:02 -07:00
|
|
|
|
(kill-region beg end)))
|
|
|
|
|
|
2023-04-09 22:57:51 -07:00
|
|
|
|
(when output-to-other-buffer-p
|
|
|
|
|
(message (concat "Prompt sent to buffer: "
|
2023-05-03 13:42:44 -07:00
|
|
|
|
(propertize gptel-buffer-name 'face 'help-key-binding)))
|
2023-04-09 22:57:51 -07:00
|
|
|
|
(display-buffer
|
|
|
|
|
buffer '((display-buffer-reuse-window
|
|
|
|
|
display-buffer-pop-up-window)
|
|
|
|
|
(reusable-frames . visible))))))
|
2023-04-09 04:19:02 -07:00
|
|
|
|
|
gptel: Add response regeneration, history and ediff
* gptel.el (gptel--attach-response-history, gptel--ediff,
gptel--next-variant, gptel--previous-variant,
gptel--mark-response):
Add `gptel--attach-response-history` -- this can be used to add
text properties to the next gptel response in the buffer. This
is (currently) useful for tracking changes when the response
overwrites existing text.
The next three commands -- `gptel--ediff`,
`gptel--previous-variant`, `gptel--next-variant` -- provide
facilities for manipulating a gptel response at point when there
is history. `gptel--mark-response` marks the response at point.
These are considered internal functions for now and can be
accessed from the transient menu, where they work together with
`gptel--regenerate`.
The input arguments to these commands are expected to change to
support copilot-style functionality in the near future.
* gptel-transient.el (gptel-menu, gptel--suffix-send,
gptel--regenerate):
Change the transient menu layout to be more compact (with a newly
added column.) When overwriting the prompt with a response, save
the prompt to the gptel response's history. Add
`gptel--regenerate` to regenerate a response. This is accessible
from the transient menu when the point is inside response text.
2024-02-04 21:09:53 -08:00
|
|
|
|
;; ** Suffix to regenerate response
|
|
|
|
|
|
|
|
|
|
(defun gptel--regenerate ()
|
|
|
|
|
"Regenerate gptel response at point."
|
|
|
|
|
(interactive)
|
|
|
|
|
(when (gptel--in-response-p)
|
|
|
|
|
(pcase-let* ((`(,beg . ,end) (gptel--get-bounds))
|
|
|
|
|
(history (get-char-property (point) 'gptel-history))
|
|
|
|
|
(prev-responses (cons (buffer-substring-no-properties beg end)
|
|
|
|
|
history)))
|
|
|
|
|
(when gptel-mode ;Remove prefix/suffix
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char beg)
|
|
|
|
|
(when (looking-back (concat "\n+" (regexp-quote (gptel-response-prefix-string)))
|
|
|
|
|
(point-min) 'greedy)
|
|
|
|
|
(setq beg (match-beginning 0)))
|
|
|
|
|
(goto-char end)
|
|
|
|
|
(when (looking-at
|
|
|
|
|
(concat "\n+" (regexp-quote (gptel-prompt-prefix-string))))
|
|
|
|
|
(setq end (match-end 0)))))
|
|
|
|
|
(delete-region beg end)
|
|
|
|
|
(gptel--attach-response-history prev-responses)
|
|
|
|
|
(call-interactively #'gptel--suffix-send))))
|
|
|
|
|
|
2023-04-09 04:16:09 -07:00
|
|
|
|
;; ** Set system message
|
2023-07-10 02:09:16 -07:00
|
|
|
|
(defun gptel--read-crowdsourced-prompt ()
|
|
|
|
|
"Pick a crowdsourced system prompt for gptel.
|
|
|
|
|
|
|
|
|
|
This uses the prompts in the variable
|
|
|
|
|
`gptel--crowdsourced-prompts', which see."
|
|
|
|
|
(interactive)
|
|
|
|
|
(if (not (hash-table-empty-p (gptel--crowdsourced-prompts)))
|
|
|
|
|
(let ((choice
|
|
|
|
|
(completing-read
|
|
|
|
|
"Pick and edit prompt: "
|
|
|
|
|
(lambda (str pred action)
|
|
|
|
|
(if (eq action 'metadata)
|
|
|
|
|
`(metadata
|
|
|
|
|
(affixation-function .
|
|
|
|
|
(lambda (cands)
|
|
|
|
|
(mapcar
|
|
|
|
|
(lambda (c)
|
|
|
|
|
(list c ""
|
|
|
|
|
(concat (propertize " " 'display '(space :align-to 22))
|
|
|
|
|
" " (propertize (gethash c gptel--crowdsourced-prompts)
|
|
|
|
|
'face 'completions-annotations))))
|
|
|
|
|
cands))))
|
|
|
|
|
(complete-with-action action gptel--crowdsourced-prompts str pred)))
|
|
|
|
|
nil t)))
|
|
|
|
|
(when-let ((prompt (gethash choice gptel--crowdsourced-prompts)))
|
|
|
|
|
(setq gptel--system-message prompt)
|
2023-12-29 13:19:23 -08:00
|
|
|
|
(call-interactively #'gptel--suffix-system-message)))
|
2023-07-10 02:09:16 -07:00
|
|
|
|
(message "No prompts available.")))
|
|
|
|
|
|
2023-03-09 16:56:26 -08:00
|
|
|
|
(transient-define-suffix gptel--suffix-system-message ()
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
"Edit LLM system message.
|
|
|
|
|
|
|
|
|
|
When LOCAL is non-nil, set the system message only in the current buffer."
|
2023-12-26 10:22:47 -08:00
|
|
|
|
:transient 'transient--do-exit
|
2024-03-15 22:47:59 -07:00
|
|
|
|
:description "Set or edit system message"
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
:format " %k %d"
|
2024-03-15 14:53:35 -07:00
|
|
|
|
:key "s"
|
2023-03-09 16:56:26 -08:00
|
|
|
|
(interactive)
|
|
|
|
|
(let ((orig-buf (current-buffer))
|
|
|
|
|
(msg-start (make-marker)))
|
|
|
|
|
(with-current-buffer (get-buffer-create "*gptel-system*")
|
2023-12-16 16:00:09 -08:00
|
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
|
(erase-buffer)
|
|
|
|
|
(text-mode)
|
2023-12-29 15:27:47 -08:00
|
|
|
|
(setq header-line-format
|
|
|
|
|
(concat
|
|
|
|
|
"Edit your system message below and press "
|
|
|
|
|
(propertize "C-c C-c" 'face 'help-key-binding)
|
|
|
|
|
" when ready, or "
|
|
|
|
|
(propertize "C-c C-k" 'face 'help-key-binding)
|
|
|
|
|
" to abort."))
|
2023-12-16 16:00:09 -08:00
|
|
|
|
(insert
|
|
|
|
|
"# Example: You are a helpful assistant. Answer as concisely as possible.\n"
|
|
|
|
|
"# Example: Reply only with shell commands and no prose.\n"
|
2023-12-29 15:27:47 -08:00
|
|
|
|
"# Example: You are a poet. Reply only in verse.\n\n")
|
2023-12-16 16:00:09 -08:00
|
|
|
|
(add-text-properties
|
2023-12-29 15:27:47 -08:00
|
|
|
|
(point-min) (1- (point))
|
2023-12-16 16:00:09 -08:00
|
|
|
|
(list 'read-only t 'face 'font-lock-comment-face))
|
|
|
|
|
;; TODO: make-separator-line requires Emacs 28.1+.
|
|
|
|
|
;; (insert (propertize (make-separator-line) 'rear-nonsticky t))
|
|
|
|
|
(set-marker msg-start (point))
|
2024-01-30 21:06:03 -08:00
|
|
|
|
(save-excursion
|
|
|
|
|
(insert (buffer-local-value 'gptel--system-message orig-buf))
|
|
|
|
|
(push-mark nil 'nomsg))
|
2023-12-16 16:00:09 -08:00
|
|
|
|
(activate-mark))
|
2023-03-09 16:56:26 -08:00
|
|
|
|
(display-buffer (current-buffer)
|
|
|
|
|
`((display-buffer-below-selected)
|
|
|
|
|
(body-function . ,#'select-window)
|
|
|
|
|
(window-height . ,#'fit-window-to-buffer)))
|
2023-11-20 11:21:50 -08:00
|
|
|
|
(let ((quit-to-menu
|
|
|
|
|
(lambda ()
|
|
|
|
|
(interactive)
|
2023-12-16 16:00:09 -08:00
|
|
|
|
(local-unset-key (kbd "C-c C-c"))
|
|
|
|
|
(local-unset-key (kbd "C-c C-k"))
|
2023-11-20 11:21:50 -08:00
|
|
|
|
(quit-window)
|
|
|
|
|
(display-buffer
|
|
|
|
|
orig-buf
|
|
|
|
|
`((display-buffer-reuse-window
|
|
|
|
|
display-buffer-use-some-window)
|
|
|
|
|
(body-function . ,#'select-window)))
|
|
|
|
|
(call-interactively #'gptel-menu))))
|
|
|
|
|
(local-set-key (kbd "C-c C-c")
|
|
|
|
|
(lambda ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((system-message
|
|
|
|
|
(buffer-substring msg-start (point-max))))
|
|
|
|
|
(with-current-buffer orig-buf
|
gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default. This is following
the discussion in #249.
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally. The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.
Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.
* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 18:30:49 -07:00
|
|
|
|
(gptel--set-with-scope 'gptel--system-message system-message
|
|
|
|
|
gptel--set-buffer-locally)))
|
2023-11-20 11:21:50 -08:00
|
|
|
|
(funcall quit-to-menu)))
|
|
|
|
|
(local-set-key (kbd "C-c C-k") quit-to-menu)))))
|
2023-03-09 16:56:26 -08:00
|
|
|
|
|
2023-04-09 04:16:09 -07:00
|
|
|
|
;; ** Suffixes for rewriting/refactoring
|
|
|
|
|
|
2023-04-09 04:12:13 -07:00
|
|
|
|
(transient-define-suffix gptel--suffix-rewrite ()
|
|
|
|
|
"Rewrite or refactor region contents."
|
|
|
|
|
:key "r"
|
|
|
|
|
:description #'gptel--refactor-or-rewrite
|
|
|
|
|
(interactive)
|
|
|
|
|
(let* ((prompt (buffer-substring-no-properties
|
|
|
|
|
(region-beginning) (region-end)))
|
|
|
|
|
(stream gptel-stream)
|
|
|
|
|
(gptel--system-message gptel--rewrite-message))
|
|
|
|
|
(gptel-request prompt :stream stream)))
|
|
|
|
|
|
|
|
|
|
(transient-define-suffix gptel--suffix-rewrite-and-replace ()
|
|
|
|
|
"Refactor region contents and replace it."
|
|
|
|
|
:key "R"
|
|
|
|
|
:description (lambda () (concat (gptel--refactor-or-rewrite) " in place"))
|
|
|
|
|
(interactive)
|
|
|
|
|
(let* ((prompt (buffer-substring-no-properties
|
|
|
|
|
(region-beginning) (region-end)))
|
|
|
|
|
(stream gptel-stream)
|
|
|
|
|
(gptel--system-message gptel--rewrite-message))
|
|
|
|
|
(kill-region (region-beginning) (region-end))
|
|
|
|
|
(message "Original text saved to kill-ring.")
|
|
|
|
|
(gptel-request prompt :stream stream :in-place t)))
|
|
|
|
|
|
|
|
|
|
(transient-define-suffix gptel--suffix-rewrite-and-ediff (args)
|
|
|
|
|
"Refactoring or rewrite region contents and run Ediff."
|
|
|
|
|
:key "E"
|
|
|
|
|
:description (lambda () (concat (gptel--refactor-or-rewrite) " and Ediff"))
|
|
|
|
|
(interactive (list (transient-args transient-current-command)))
|
2024-01-02 19:37:55 -08:00
|
|
|
|
(letrec ((prompt (buffer-substring-no-properties
|
2023-04-09 04:12:13 -07:00
|
|
|
|
(region-beginning) (region-end)))
|
2024-01-02 19:37:55 -08:00
|
|
|
|
(gptel--system-message gptel--rewrite-message)
|
|
|
|
|
;; TODO: Technically we should save the window config at the time
|
|
|
|
|
;; `ediff-setup-hook' runs, but this will do for now.
|
|
|
|
|
(cwc (current-window-configuration))
|
|
|
|
|
(gptel--ediff-restore
|
|
|
|
|
(lambda ()
|
|
|
|
|
(when (window-configuration-p cwc)
|
|
|
|
|
(set-window-configuration cwc))
|
|
|
|
|
(remove-hook 'ediff-quit-hook gptel--ediff-restore))))
|
2023-04-09 04:12:13 -07:00
|
|
|
|
(message "Waiting for response... ")
|
|
|
|
|
(gptel-request
|
|
|
|
|
prompt
|
|
|
|
|
:context (cons (region-beginning) (region-end))
|
|
|
|
|
:callback
|
|
|
|
|
(lambda (response info)
|
|
|
|
|
(if (not response)
|
|
|
|
|
(message "ChatGPT response error: %s" (plist-get info :status))
|
|
|
|
|
(let* ((gptel-buffer (plist-get info :buffer))
|
|
|
|
|
(gptel-bounds (plist-get info :context))
|
|
|
|
|
(buffer-mode
|
|
|
|
|
(buffer-local-value 'major-mode gptel-buffer)))
|
|
|
|
|
(pcase-let ((`(,new-buf ,new-beg ,new-end)
|
|
|
|
|
(with-current-buffer (get-buffer-create "*gptel-rewrite-Region.B-*")
|
2024-01-02 19:37:55 -08:00
|
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
|
(erase-buffer)
|
|
|
|
|
(funcall buffer-mode)
|
|
|
|
|
(insert response)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(list (current-buffer) (point-min) (point-max))))))
|
2023-04-09 04:12:13 -07:00
|
|
|
|
(require 'ediff)
|
2024-01-02 19:37:55 -08:00
|
|
|
|
(add-hook 'ediff-quit-hook gptel--ediff-restore)
|
2023-04-09 04:12:13 -07:00
|
|
|
|
(apply
|
|
|
|
|
#'ediff-regions-internal
|
|
|
|
|
(get-buffer (ediff-make-cloned-buffer gptel-buffer "-Region.A-"))
|
|
|
|
|
(car gptel-bounds) (cdr gptel-bounds)
|
|
|
|
|
new-buf new-beg new-end
|
|
|
|
|
nil
|
|
|
|
|
(if (transient-arg-value "-w" args)
|
|
|
|
|
(list 'ediff-regions-wordwise 'word-wise nil)
|
|
|
|
|
(list 'ediff-regions-linewise nil nil))))))))))
|
|
|
|
|
|
2023-03-09 16:56:26 -08:00
|
|
|
|
(provide 'gptel-transient)
|
|
|
|
|
;;; gptel-transient.el ends here
|
2023-04-09 04:16:09 -07:00
|
|
|
|
|
|
|
|
|
;; Local Variables:
|
|
|
|
|
;; outline-regexp: "^;; \\*+"
|
|
|
|
|
;; eval: (outline-minor-mode 1)
|
|
|
|
|
;; End:
|