* gptel.el (gptel--restore-state): When there is no "GPTEL_BOUNDS"
org property, `read' asks for stdin instead. Fix by only calling
`read' when this property is non-nil.
Thanks to @Elilif for spotting this bug.
* gptel.el (gptel--save-state, gptel--restore-state,
gptel-temperature, gptel-model, gptel-max-tokens,
gptel-directives, gptel--always, gptel--button-buttonize,
gptel--system-message, gptel--bounds): Write gptel parameters as
file-local variables when saving chats in Markdown or text files.
The local variable gptel--bounds stores the locations of the
responses from the LLM. This is not a great solution, but the best
I can think to do without adding more syntax to the document.
Chats can be restored by turning on `gptel-mode'. One of the
problem with this approach is that if the buffer is modified
before `gptel-mode' is turned on, the state data is out of date.
Another problem is that this metadata block as printed in the
buffer can become quite long. A better approach is needed.
Define helper functions `gptel--always' and
`gptel--button-buttonize' to work around Emacs 27.1 support.
* README.org: Mention saving and restoring chats where
appropriate.
* gptel.el (gptel--insert-response, gptel-pre-response-hook): New
user option `gptel-pre-response-hook' that runs before the
response is inserted into the buffer. This can be used to prepare
the buffer in some user-specified way for the response.
* gptel-curl.el (gptel-curl--stream-filter): Run
`gptel-pre-response-hook' before inserting streaming responses.
* gptel-curl.el (gptel-curl-get-response): Don't convert response
into org-mode unless the buffer from which the request originated
is in org-mode. This makes `gptel-default-mode' less binding, and
only used when creating a new chat session with `gptel'. Also,
gptel should now do the right thing depending on whether the
current buffer is in text, Markdown or Org modes.
* gptel.el (gptel-mode, gptel-set-topic, gptel--create-prompt,
gptel-set-topic, gptel--get-topic-start, gptel--get-bounds,
gptel--save-state, gptel--restore-state): Add support for saving
and restoring gptel state for Org buffers. Support for Markdown
buffers is not yet implemented.
`gptel--save-state' and `gptel--restore-state' save and restores
state using Org properties. With `gptel-mode' active, these are
run automatically when saving the buffer or enabling `gptel-mode'
respectively.
The command `gptel-set-topic' can be used to set a topic for the
current heading, which is stored as an Org property. The topic
name is unused (as of now), but the presence of this property
limits the text context sent to ChatGPT to the heading text up to
the cursor position.
Autload `gptel-mode' since the user may want to enable this (to
restore sessions) without having loaded gptel.el.
gptel.el (gptel-request): when using `gptel-request', let-bind
`gptel--system-message' around call to `gptel--create-prompt' when
the prompt argument is null. This allows `gptel-request' to be
used to send the buffer as a prompt with a different system
message from `gptel--system-message' for that buffer.
---------
Co-authored-by: Neil Fulwiler <neil@fulwiler.me>
* gptel.el (gptel-crowdsourced-prompts-file): This file holds
prompts compiled by the community.
* gptel-transient.el (gptel--read-crowdsourced-prompt,
gptel--crowdsourced-prompts, gptel-system-prompt--setup,
gptel--crowdsourced-prompts-url): Fetch crowdsourced system
prompts from https://github.com/f/awesome-chatgpt-prompts and pick
one to use from the transient menu.
* gptel.el (gptel-proxy): Support a proxy when interacting with openai
endpoint. In many organizations the openai api can only be accessed
via proxy. This is easily supported by curl.
gptel-curl.el (gptel-curl--get-args): tidy up `gptel-curl--get-args'.
---------
Co-authored-by: PalaceChan <XXX>
* gptel.el (gptel-directives): Bump required transient version to
0.4.0. Remove placeholder about hard-coded directives from
the docstring for `gptel-directives'.
* gptel-transient.el (gptel-system-prompt,
gptel-system-prompt--setup): Dynamically generate the system
prompt menu in `gptel-menu'. Delete helper functions that
hard-coded the list of system prompts/directives before.
* gptel-transient.el (gptel--system-prompt-programming,
gptel--system-prompt-default, gptel--system-prompt-writing,
gptel--system-prompt-chat, gptel-system-prompt): Define explicit helper
functions to set the system prompt. This is a temporary workaround for #45
until dynamic transients are supported in a new transient release.
* gptel-curl.el (gptel-curl--stream-cleanup): `gptel-post-response-hook' should
run in the buffer that was current when the request was sent. This was not the
case for the curl method (with response streaming). Fixed.
* gptel.el (gptel--insert-response):
* gptel-transient.el (gptel--suffix-send):
* gptel-curl.el (gptel-curl--stream-filter, gptel-curl--stream-insert-response,
gptel-curl--stream-cleanup):
Handle read-only gptel buffers by redirecting the output to a new buffer (that
pops up automatically). To track this,
- the `:position' argument of the INFO plist, which is a marker, is moved to the
new output buffer.
- the `:buffer' argument of the INFO plist is unmodified, it always points to
the buffer that the request originated from.
* gptel-curl.el (gptel-curl-get-response): Set buffer-local model parameters in
the correct (i.e. gptel) buffer, not in Curl's process buffer. This fixes#43.
* gptel-transient.el (gptel--suffix-send, gptel-menu): When
reading input from the minibuffer and sending the output to an
existing gptel session, only use the prompt read from the
minibuffer. Reword the "Overwrite/Delete prompt" option.
* gptel.el (gptel): `gptel' only pops to the gptel buffer when
called interactively.
* gptel-transient.el: Pop up the gptel session buffer when the
prompt is sent to it, but don't select it. Also message the user
that the response has been redirected to the gptel session.
* gptel-transient.el (gptel-menu, gptel--suffix-send,
gptel--suffix-send-existing, gptel--suffix-send-new): Rewrite
`gptel-menu' to allow for selecting prompt sources and response
sinks independently. Sensible combinations of the following are
now possible:
- prompt from minibuffer
- Replace prompt with response
- Response to echo area
- Response to new gptel session
- Response to existing gptel session
- Response to kill-ring
The transient suffixes `gptel--suffix-send-existing' and
`gptel--suffix-send-new' are now obsolete and have been removed.
* gptel-transient.el: Add `gptel-rewrite-menu' (accessible via the
main `gptel-menu') to rewrite/refactor the selected region,
including the choice to Ediff it linewise/wordwise afterwards.
* gptel.el (gptel-send): Replace references to `gptel-send-menu'.
* gptel-transient.el: Rename `gptel-send-menu' t `gptel-menu'.
This shorter name is apropos of its increased feature set (in the
forthcoming commits).
* gptel.el (gptel--insert-response, gptel-request):
- Add an in-place key to gptel-request. When true, the default
callbacks will not delimit the API responses with newlines.
- Add a strea option to gptel-request. Only works with the default
filter/stream-insert callback, so it's marked as for internal use
for now.
* gptel-curl.el (gptel-curl--stream-insert-response): Ditto.
* gptel.el (gptel--url-parse-response, gptel--url-get-response,
gptel--insert-response, gptel-send):
- Use shorter keys for passing the info plist,
- record errors in the info plist,
- separate user messaging from the callback and more.
- Make the API more functional (i.e. less imperative)
This is in preparation for adding `gptel-request', an API for
defining custom commands.
Note: The streaming filter and callback are mostly unchanged.
Streaming is not planned to be accessible via `gptel-request'.
* gptel-curl.el (gptel-curl--parse-response, gptel-curl--sentinel,
gptel-curl--stream-filter, gptel-curl--stream-insert-response,
gptel-curl--stream-cleanup, gptel-curl-get-response): Ditto.
* gptel.el (gptel--url-parse-response, gptel--insert-response):
Use the same error codes/descriptions across url-retrieve/Curl,
with and without streaming responses.
* gptel-curl.el (gptel-curl--parse-response,
gptel-curl--stream-filter, gptel-curl--stream-cleanup): Ditto.
* gptel-curl.el (gptel-curl--stream-filter,
gptel-curl--stream-cleanup): When streaming responses, move the
error handling from the Curl process filter to the cleanup
sentinel. This simplifies the filter code a fair bit.