Commit graph

204 commits

Author SHA1 Message Date
Karthik Chikmagalur
cc6c5e7321 gptel: saving and restoring state, and limiting context
* 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.
2023-07-19 20:41:56 -07:00
Neil Fulwiler
4356f6fbec
gptel: correct system message with gptel-request
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>
2023-07-13 15:31:18 -07:00
Karthik Chikmagalur
9c4af204a3 gptel-transient: Add crowdsourced prompts
* 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.
2023-07-10 02:36:28 -07:00
Karthik Chikmagalur
07f27be696 gptel-transient: UI tweak for custom prompt
gptel-transient (gptel--suffix-system-message): Place cursor at
the beginning of the system message when editing it.
2023-07-10 01:49:51 -07:00
Karthik Chikmagalur
bb8b37d8c0 gptel, gptel-curl: Fix byte-compile warnings
gptel.el (gptel--request-data): Also use :json-false to encode nil in the http
request.
2023-06-23 16:44:16 -07:00
Filipe Guerreiro
3d98ce8eee
gptel: Add new turbo 0613 models (#77)
gptel.el (gptel-model): Update choices for the OpenAI model.  Add the 16k and 32k token versions of the gpt-3.5 and gpt-4 model respectively.
2023-06-23 13:22:31 -07:00
Marcus Kammer
e6df1a5e33
gptel: Use :require for auth-source-search (#78)
gptel.el (gptel-api-key-from-auth-source): To read from .authinfo.gpg the key parameter :require for auth-source-search is needed.
2023-06-18 12:10:43 -07:00
Karthik Chikmagalur
a7207a3835 README: Add TOC 2023-06-12 17:27:52 -07:00
Karthik Chikmagalur
30700cc88a README: Mention extensions, gptel-proxy 2023-06-09 14:09:28 -07:00
Palace
20af9a8b99 gptel: curl proxy support (#69)
* 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>
2023-06-05 21:23:21 -07:00
Tianshu Wang
e6a1468bd2
gptel: Make API host configurable (#67)
* Make API host configurable

* Update README.org
2023-05-31 20:24:13 -07:00
Karthik Chikmagalur
42132d3662 README: tweak description of package 2023-05-31 18:35:08 -07:00
Karthik Chikmagalur
37c381c2e5 README: Update with acknowledgments and more
* README.org: update with acknowledgments (#4)
2023-05-19 23:29:12 -07:00
Karthik Chikmagalur
219e163dc7 gptel-curl: Add gptel-abort
* gptel-curl.el (gptel-abort): Command to cancel any active gptel
Curl request in the current buffer.
2023-05-19 22:26:38 -07:00
Karthik Chikmagalur
706ad703db gptel-transient: Allow arbitrary system prompts/directives
* 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.
2023-05-19 21:01:01 -07:00
Karthik Chikmagalur
09729ee718 gptel: Create customization group
gptel.el (gptel-default-mode): Also make `gptel-default-mode' a user
option.
2023-05-09 11:34:59 -07:00
Karthik Chikmagalur
d13b0c4ab7 gptel-transient: Fix gptel-system-prompt
* 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.
2023-05-03 14:29:45 -07:00
Karthik Chikmagalur
422eba8048 gptel-curl: Run post-response-hook in gptel buffer
* 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.
2023-05-03 13:50:27 -07:00
Karthik Chikmagalur
ac754ceb2a gptel: Handle read-only gptel-buffers
* 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.
2023-05-03 13:50:27 -07:00
Troy Rosenberg
075609544a
README: Update instructions for setting key (#46)
* README.org Update the instructions for getting =gptel-api-key= to
include using the .authinfo file after support was added in 6f951ed.
2023-04-23 19:55:34 -07:00
Karthik Chikmagalur
a5be53d5e3 gptel: Update version
* gptel.el: Version updated to 0.3.5.
2023-04-12 23:02:13 -07:00
Karthik Chikmagalur
444a43134f gptel-curl: Fix current-buffer for Curl requests
* 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.
2023-04-12 22:10:54 -07:00
Karthik Chikmagalur
f218388d4d gptel-transient: Fix bug when sending in existing session
* 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.
2023-04-10 22:49:41 -07:00
Karthik Chikmagalur
00abbf7597 gptel-transient: More visual feedback
* 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.
2023-04-09 22:57:51 -07:00
Karthik Chikmagalur
6202474a6e README: Update with changes to gptel-menu
* README.org (Usage): Add images for new options
2023-04-09 13:02:56 -07:00
Karthik Chikmagalur
c29e1cd673 gptel-transient: Minor formatting changes.
* gptel-transient.el (gptel-system-prompt): Formatting changes.
2023-04-09 13:02:56 -07:00
Karthik Chikmagalur
c11e53061c gptel-transient: New gptel-menu transient options
* 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.
2023-04-09 13:02:56 -07:00
Karthik Chikmagalur
23332a9bc5 gptel-transient: Add outline-minor-mode support
* gptel-transient.el: Add section headers and an `outline-regexp'.
2023-04-09 13:01:46 -07:00
Karthik Chikmagalur
937c754e57 gptel-transient: Add refactor transient
* 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.
2023-04-09 13:01:40 -07:00
Karthik Chikmagalur
c6abda6f0f gptel-transient: Rename gptel-send-menu -> gptel-menu
* 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).
2023-04-09 04:14:37 -07:00
Karthik Chikmagalur
8a9ae56e77 gptel: Add streaming, in-place options to gptel-request
* 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.
2023-04-09 03:29:48 -07:00
Karthik Chikmagalur
acf12ee6e3 gptel: return the gptel buffer
* gptel.el (gptel): `gptel' returns the buffer after creating or
switching to it.  This is useful for other commands that call
`gptel'.
2023-04-08 20:17:06 -07:00
Karthik Chikmagalur
44045be327 gptel: gptel-mode is local by default
* gptel.el (gptel-mode): Don't specify `:global nil`.
2023-04-08 20:17:06 -07:00
Karthik Chikmagalur
1b47235e25 README: Add section on gptel-request
* README.org (** Using it your way): New section describing
gptel-request.
2023-04-08 20:17:06 -07:00
Karthik Chikmagalur
18222818dc gptel: Add gptel-request
* gptel.el (gptel-request): `gptel-request' is a lower level API
than `gptel-send' for defining custom commands that use ChatGPT's
responses.
2023-04-08 20:17:06 -07:00
Karthik Chikmagalur
f0953d569e gptel: Simplify response API
* 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.
2023-04-08 16:57:38 -07:00
Karthik Chikmagalur
36051b15d5 gptel: Unify error descriptions
* 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.
2023-04-08 12:22:36 -07:00
Karthik Chikmagalur
1cd0f58552 gptel-curl: Better error handling when streaming
* 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.
2023-04-08 09:57:38 -07:00
Karthik Chikmagalur
6c47c0a483 README: Add videos with streaming
* README.org (In a dedicated chat buffer): Move the any-buffer
interaction description up.
2023-04-06 17:32:35 -07:00
Karthik Chikmagalur
5a0deda7fc gptel: Turn on streaming replies by default
* gptel.el (gptel-stream): When Curl is available, stream ChatGPT
responses by default.
2023-04-06 17:14:40 -07:00
Karthik Chikmagalur
a43f5ac5fa gptel: Rename stream-related vars and defuns
* gptel.el (gptel--convert-playback-markdown->org, gptel--request-data,
gptel-playback):
- `gptel-playback' is now obsolete, use `gptel-stream' instead.
- `gptel--convert-playback-markdown->org': rename to
  `gptel--stream-convert-markdown->org'

* gptel-curl.el (gptel-curl--filter, gptel-curl-get-response):
- `gptel--insert-response-stream': rename to `gptel-curl--stream-insert-response'
- `gptel-curl--cleanup-stream': rename to `gptel-curl--stream-cleanup'
- `gptel-curl--filter': rename to `gptel-curl--stream-filter'
2023-04-06 17:14:40 -07:00
Karthik Chikmagalur
ba133267ec gptel: Run post-response-hook after inserting response
* gptel.el (gptel--playback, gptel--insert-response):
`gptel--insert-response' no longer handles stream playback. Run
`gptel-post-response-hook' after inserting the response from
ChatGPT. Delete the `gptel--playback' function since it never did
anything -- it was a placebo.
2023-04-06 17:14:40 -07:00
Karthik Chikmagalur
2e34981aa0 gptel: Rename :insert-marker
* gptel.el (gptel--url-get-response, gptel--insert-response,
gptel-send): Rename the :insert-marker keyword in the async info
plist to :start-marker.

* gptel-curl.el (gptel--insert-response-stream,
gptel-curl--cleanup-stream, gptel-curl-get-response): Ditto.
2023-04-06 17:14:40 -07:00
Karthik Chikmagalur
c22c59d20a gptel: Add post-response hook and fix org converter
* gptel.el (gptel--convert-playback-markdown->org,
gptel-post-response-hook): Add a hook that runs after the response
is received.  This will allow for custom actions like moving the
cursor to the next prompt. The markdown->org stream converter now
cleans up after itself using this hook.
2023-04-06 17:14:40 -07:00
Karthik Chikmagalur
c9795fe9e8 gptel: org support for streaming WIP
* gptel.el (gptel--convert-playback-markdown->org): New converter
for markdown->org that works on text chunks while maintaining the
parse state until the text stream is finished.

* gptel-curl.el (gptel--insert-response-stream,
gptel-curl-get-response): When using `gptel-playback' and
requesting ChatGPT's responses in org-mode, run the above
converter on the received response. This works by storing the
converter and associated state as a closure in the async info
plist that is supplied along with the response, and running it
repeatedly on each chunk of text in the response stream before it
is inserted into the buffer.

FIXME: Note that `gptel-response-filter-functions' is currently
ignored if using `gptel-stream'.
2023-04-06 17:14:40 -07:00
Karthik Chikmagalur
d5ad620555 gptel-curl: process filter for streaming support
* gptel.el (gptel--request-data): Request a streaming message if
`gptel-stream' is non-nil.

* gptel-curl.el (gptel-curl-get-response,
gptel-curl--cleanup-stream, gptel-curl--filter): Add a process
filter and sentinel for Curl to stream ChatGPT's response into
Emacs in real-time.
2023-04-06 17:14:40 -07:00
Karthik Chikmagalur
936c27e28b gptel: Fix header-line-format update
* gptel.el (gptel--update-header-line): Only fix the
`header-line-format' when in gptel-mode.
2023-04-06 17:13:45 -07:00
Karthik Chikmagalur
d77c8f37c5 gptel: Improve header-line-format
* gptel.el (gptel-mode): Show the model and context in the header
line.
2023-04-03 14:08:03 -07:00
AlessandroW
1f03655e2d
Add Doom Emacs installation instructions (#28)
README: Add Doom Emacs installation instructions
2023-04-01 14:25:47 -07:00
Karthik Chikmagalur
f7ba368c38 gptel: More flexible callbacks
* gptel.el (gptel--url-get-response,
gptel-api-key-from-auth-source): `gptel--url-get-response' accepts
a callback argument that can be used to do something besides
inserting the response into the current buffer.

* gptel-curl.el (gptel-curl--sentinel, gptel-curl-get-response):
`gptel-curl--sentinel' now accepts a callback argument that can be
used to do something besides inserting the response into the
current buffer.

These changes are in preparation for more specific functionality,
like showing the response as a message, or replacing the prompt
with the response etc.
2023-03-31 19:37:25 -07:00