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 +2048,156 @@ This is a sentence that will be filled in later.
2041
2048
:REVIEWS: 0
2042
2049
:END:
2043
2050
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.
2051
+
gptel is really the combination of two libraries: the request API and
2052
+
the =gptel= UI. For convenience both are made available in a single
2053
+
Emacs package. gptel's opinionated UI -- the chat buffer, the
2054
+
transient menus, the presentation of tool calls and so on -- comprise
2055
+
one way of using gptel, but it is certainly not the only one.
2056
+
2057
+
Accordingly, this cookbook has two sections. [[*Extending gptel's UI]]
2058
+
describes how to customize gptel's UIs beyond simply setting user
2059
+
options, and [[*Building applications with ~gptel-request~]] covers the
2060
+
use of gptel's API for specialized LLM interactions.
2061
+
2062
+
** TODO Extending gptel's UI
2063
+
2064
+
*** Improving the chat buffer experience
2065
+
2066
+
A "chat buffer" is any text, Markdown or Org mode buffer where
2067
+
~gptel-mode~ is turned on. This is a regular Emacs buffer and is
2068
+
freely editable.
2069
+
2070
+
While gptel provides a few knobs for modifying its behavior in chat
2071
+
buffers ([[*gptel chat buffer UI]]), it makes minimal assumptions about
2072
+
the format of the chat or the structure, layout of chat buffers. In
2073
+
particular, it does not add any automatic behavior. This section
2074
+
provides recipes for some quality of life improvements to gptel chat
2075
+
buffer behavior.
2076
+
2077
+
**** Automatically persist chats to disk
2078
+
2079
+
LLM chats can be one-off, transient interactions whose value is
2080
+
limited to the moment, or perhaps to the side effects they produce via
2081
+
tool calls (such as editing code in other files). In this case there
2082
+
is little reason to keep the chat buffers around. But the
2083
+
conversations may also contain information you may want to refer to in
2084
+
the future.
2085
+
2086
+
Since they are regular Emacs buffers, they can be written to disk via
2087
+
~save-buffer~ (=C-x C-s= by default), but you will have to manually
2088
+
specify a location and a filename. With a little elisp, you can
2089
+
automate this process so the chat buffers are automatically written to
2090
+
a predtermined directory with a timestamped name when you run
2091
+
~save-buffer~:
2092
+
2093
+
#+begin_src emacs-lisp
2094
+
(defvar gptel-mode-chat-directory
2095
+
(file-name-concat (xdg-data-home) "gptel-chat")
2096
+
"Directory in which to store gptel chats")
2097
+
2098
+
(defun gptel-mode-assign-filename ()
2099
+
"If this is a dissociated chat buffer, save it to a predetermined location.
2100
+
2101
+
Intended to be added to `before-save-hook' in gptel chat buffers. Use a
~gptel-save-state-hook~ runs just before gptel updates its metadata in
2173
+
the file.
2174
+
2175
+
Note that this function will overwrite any other =eval= local variable
2176
+
specification already present on the line.
2177
+
2178
+
*** Extending gptel's Transient menus
2179
+
2180
+
** TODO Building applications with ~gptel-request~
2181
+
2182
+
The entry point to the request library is the ~gptel-request~
2183
+
function, which presents a unified way to interact with any LLM that
2184
+
gptel supports. It can be used as a building block for custom
2185
+
commands that live in your configuration, for custom workflows, or
2186
+
even to build complex packages.
2187
+
2188
+
If you intend to use ~gptel-request~ to write specialized LLM
2189
+
interaction commands or build a different UI, you can require only the
2190
+
=gptel-request= feature:
2191
+
2192
+
#+begin_src emacs-lisp
2193
+
(require 'gptel-request)
2194
+
#+end_src
2045
2195
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.
2196
+
This way you avoid loading unnecessary code, such as gptel's chat buffer UI or Transient menus.
2047
2197
2048
2198
By way of examples, this chapter describes how to do these things with ~gptel-request~.
2049
2199
2050
-
** Simple ~gptel-request~ commands
2200
+
*** Simple ~gptel-request~ commands
2051
2201
2052
2202
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
2203
@@ -2096,7 +2246,7 @@ It is not recommended to grab the buffer contents as a string, as this will caus
2096
2246
2097
2247
We can now write our first (admittedly useless) custom command:
0 commit comments