You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tool arguments are specified in an Elisp format that mirrors the JSON
@@ -2041,13 +2056,87 @@ This is a sentence that will be filled in later.
2041
2056
:REVIEWS: 0
2042
2057
:END:
2043
2058
2044
-
gptel is really the combination of two libraries: the request API and the =gptel= UI. gptel's opinionated UI -- the chat buffer, the transient menus, the presentation of tool calls and so on -- comprise one way of using gptel, but it is certainly not the only one.
2059
+
gptel is really the combination of two libraries: the request API and
2060
+
the =gptel= UI. For convenience both are made available in a single
2061
+
Emacs package. gptel's opinionated UI -- the chat buffer, the
2062
+
transient menus, the presentation of tool calls and so on -- comprise
2063
+
one way of using gptel, but it is certainly not the only one.
2064
+
2065
+
Accordingly, this cookbook has two sections. [[*Extending gptel's UI]]
2066
+
describes how to customize gptel's UIs beyond simply setting user
2067
+
options, and [[*Building applications with ~gptel-request~]] covers the
2068
+
use of gptel's API for specialized LLM interactions.
2069
+
2070
+
** TODO Extending gptel's UI
2071
+
2072
+
*** Improving the chat buffer experience
2073
+
2074
+
A "chat buffer" is any text, Markdown or Org mode buffer where
2075
+
~gptel-mode~ is turned on.
2076
+
2077
+
**** Resume chat sessions more robustly
2078
+
2079
+
gptel adds metadata to a chat buffer when saving it to a file. Among
2080
+
other information, this metadata includes the model, backend and tools
2081
+
in use, as well as the response boundaries. When opening this file,
2082
+
~gptel-mode~ is not automatically enabled, so modifying the buffer can
2083
+
cause the recorded response boundaries to go out of sync.
2084
+
2085
+
~gptel-mode~ can be automatically enabled on opening the file by
2086
+
adding a [[info:emacs#Specifying File Variables][property-line]] at the top of the file, like
2087
+
2088
+
#+begin_org
2089
+
# -*- eval: (gptel-mode 1) -*-
2090
+
#+end_org
2091
+
2092
+
We can get gptel to include this line automatically as follows:
2093
+
2094
+
#+begin_src emacs-lisp
2095
+
(defun gptel-mode-auto-enable ()
2096
+
"Ensure that this file opens with `gptel-mode' enabled."
2097
+
(save-excursion
2098
+
(let ((enable-local-variables t)) ; Ensure we can modify local variables
2099
+
(if (and (save-excursion
2100
+
(goto-char (point-min))
2101
+
(looking-at ".*-\\*-"))) ; If there's a -*- line
2102
+
;; First remove any existing eval, then add the new one
Note that this will overwrite any other =eval= local variable
2113
+
specification already present on the line.
2114
+
2115
+
**** Automatically persist chats to disk
2116
+
2117
+
*** Extending gptel's Transient menus
2118
+
2119
+
** TODO Building applications with ~gptel-request~
2120
+
2121
+
The entry point to the request library is the ~gptel-request~
2122
+
function, which presents a unified way to interact with any LLM that
2123
+
gptel supports. It can be used as a building block for custom
2124
+
commands that live in your configuration, for custom workflows, or
2125
+
even to build complex packages.
2126
+
2127
+
If you intend to use ~gptel-request~ to write specialized LLM
2128
+
interaction commands or build a different UI, you can require only the
2129
+
=gptel-request= feature:
2130
+
2131
+
#+begin_src emacs-lisp
2132
+
(require 'gptel-request)
2133
+
#+end_src
2045
2134
2046
-
The entry point to the request library is the ~gptel-request~ function, which presents a unified way to interact with any LLM that gptel supports. It can be used as a building block for custom commands that live in your configuration, custom workflows, or even to build complex packages.
2135
+
This way you avoid loading unnecessary code, such as gptel's chat buffer UI or Transient menus.
2047
2136
2048
2137
By way of examples, this chapter describes how to do these things with ~gptel-request~.
2049
2138
2050
-
** Simple ~gptel-request~ commands
2139
+
*** Simple ~gptel-request~ commands
2051
2140
2052
2141
gptel provides gptel-request, a lower level function, to query ChatGPT with custom behavior. It accepts a prompt to send to the the active ~gptel-model~, along with several keyword arguments that modify what will be sent and how the response will be handled:
2053
2142
@@ -2096,7 +2185,7 @@ It is not recommended to grab the buffer contents as a string, as this will caus
2096
2185
2097
2186
We can now write our first (admittedly useless) custom command:
0 commit comments