Commit graph

60 commits

Author SHA1 Message Date
Karthik Chikmagalur
73a0cc25ba gptel-transient: Simplify model selection
* gptel-transient.el (gptel--infix-provider, gptel--infix-model):
Simplify model and backend selection into a single step.  Remove
unused and obsolete option `gptel--infix-provider`.
2024-03-16 20:17:52 -07:00
Karthik Chikmagalur
6d3e4a99f5 gptel-transient: Rename additional-directive functions
* gptel-transient.el (gptel--get-directive,
gptel--infix-add-directive, gptel-menu): Rename the
directive-related functions to be shorter/more consistent with the
rest of the code.

gptel--additional-directive     -> gptel--infix-add-directive
gptel--additional-directive-get -> gptel--get-directive
2024-03-16 20:17:52 -07:00
Karthik Chikmagalur
161c77ad7f gptel-transient: Adjust several menu options
* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--infix-temperature,
transient-format-value, gptel--additional-directive,
gptel--suffix-system-message): Tweak to the "additional directive"
overlay display.  `gptel-menu` changes based on feedback
from #249 (thanks to @jwr):

- Keys to set the system message are remapped from "h" to
"s" (mnemonic)
- `gptel--infix-temperature` is now hidden by default and requires
enabling `gptel-expert-commands`
- Keys to prompt from minibuf and respond in echo area are changed
to "m" and "e" respectively.
2024-03-16 20:17:51 -07:00
Karthik Chikmagalur
376fb4b423 gptel-transient: Additional directives option (#249)
* gptel.el (gptel-end-of-response, gptel-beginning-of-response,
gptel-expert-commands): Add `gptel-expert-commands` to selectively
enable experimental options in `gptel-menu`.  This should keep the
interface from overwhelming new users.  Add a command to move to
the beginning of a response.

* gptel-transient.el (gptel-menu, gptel-system-prompt,
gptel--instructions-make-overlay, gptel-option-overlaid,
transient-format-value, gptel--additional-directive,
gptel--additional-directive-get): Add a transient option to
include a (short) additional instruction/directive along with the
system message.  This makes it convenient to have an extensive
system message and specify additional, per-response tasks (such as
refactoring) on top.  Ensure that the dry run options handle this
correctly.  This option is made available when
`gptel-expert-commands` is turned on.

NOTE: WIP design.  The nomenclature for `gptel-expert-commands`
and "additional directive" is subject to change.
2024-03-16 20:17:35 -07:00
Karthik Chikmagalur
7e6b106516 gptel-transient: Change menu display
* gptel-transient.el (gptel-menu, gptel-lisp-variable,
gptel--infix-num-messages-to-send, gptel--infix-max-tokens,
gptel--infix-provider): Improve the wording and the display of the
default settings.  Define a new class `gptel-lisp-variable` to
faciliate this.
2024-03-14 20:28:21 -07:00
Karthik Chikmagalur
dade9ec8e1 gptel: Add introspection commands
* gptel.el (gptel--inspect-query): Add a function to inspect the
query that will be sent.  This is useful to ensure that (only and
all of) what you expect to be sent is being sent.

* gptel-transient.el (gptel-menu): Allow the query in progress to
be inspected from `gptel-menu` as an elisp or JSON object.
2024-03-14 20:28:21 -07:00
Karthik Chikmagalur
12340eda46 gptel-transient: Truncate system prompt when messaging
* gptel-transient.el (gptel-system-prompt--setup): Truncate the
chosen system prompt when displaying it as a message. (#249)
2024-03-14 20:28:21 -07:00
Marten Lienen
149261ee79
gptel-transient: Avoid clashes with the custom directive key (#219)
gptel-transient (gptel--system-prompt-setup): When assigning keys
to directives, avoid clashes with the system-message edit key
(`h`), and use an arbitrary unused key if no mnemonic key
assignments are possible.
2024-02-27 22:36:06 -08:00
Karthik Chikmagalur
bf994c0765 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 22:17:14 -08:00
Karthik Chikmagalur
49cfc78378 gptel: Add page boundaries, restructure files
* gptel.el: Add page boundaries and reorder file.

* gptel-transient.el: Add page boundaries.
2024-02-04 21:06:14 -08:00
Karthik Chikmagalur
af5444a2ea 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:29:12 -08:00
Ihor Radchenko
95925f3571
Automatically create parent directories for gptel-crowdsourced-prompts-file (#203)
* gptel-transient.el (gptel--crowdsourced-prompts): Create containing
directory for `gptel-crowdsourced-prompts-file' if necessary.

Fixes #202.
2024-02-02 16:24:13 -08:00
Karthik Chikmagalur
a61fda4661 gptel-transient: better multi-line directive editing
* gptel-transient.el (gptel--suffix-system-message): Mark the
whole directive when editing it in the `*gptel-system*` buffer.
Previously only the first line of the directive was being marked.
2024-01-30 21:06:03 -08:00
Karthik Chikmagalur
d2f56c62a0 gptel-transient: Allow redirection to any buffer
* gptel.el (gptel-request): Update docstring to clarify what
BUFFER and POSITION do.  Addresses #191.

* gptel-transient.el (gptel-menu, gptel--suffix-send): Replace
"new session" and "existing session" redirection options with
"gptel session" and "any buffer", allowing for more flexibility
when redirecting.  "gptel session" can be an existing or new
session.  Fix bug where the prompt was generated from the contents
of the destination buffer instead of the current buffer when
redirecting to a gptel session.  Add comments demarcating blocks
in `gptel--suffix-send`.
2024-01-22 17:17:57 -08:00
Karthik Chikmagalur
d0c685e501 gptel: checkdoc linting and indentation rules
* gptel.el (gptel-use-header-line, gptel--parse-buffer):
Docstrings.

* gptel-transient.el (gptel--transient-read-variable): Docstring.

* gptel-openai.el (gptel-make-openai, gptel-make-azure): Add
indent declaration.

* gptel-ollama.el (gptel-make-ollama): Add indent declaration.

* gptel-kagi.el (gptel-make-kagi): Add indent declaration.

* gptel-gemini.el (gptel-make-gemini): Add indent declaration.
2024-01-19 14:19:22 -08:00
João Távora
7b19cdf117 Sanitize gpt-model value just in time
* gptel-transient.el (gptel-menu): Sanitize model if it's not in
the backend.

* gptel.el (gptel--sanitize-model): New helper.

* gptel.el (gptel-send): Also sanitize model in non-prefixed gptel-send.
2024-01-18 17:42:12 -08:00
João Távora
50fb34ab7c Fix compilation warnings
* gptel-transient.el (gptel--suffix-send): Give a bit of feedback
when copying to kill ring.
2024-01-18 17:33:13 -08:00
João Távora
235134a176 Bit of feedback when copying reponse to kill ring
* gptel-transient.el (gptel--suffix-send): Tweak
2024-01-18 17:33:13 -08:00
Karthik Chikmagalur
d6ef79f621 gptel-transient: Show descriptions of directives
* gptel-transient.el (gptel-system-prompt--setup): (Tentative
change) Show descriptions of directives next to the keys when
picking a directive from the system-prompt menu.
2024-01-12 23:04:40 -08:00
Karthik Chikmagalur
7c2e342f35 gptel-transient: Add prompting from kill-ring
* gptel-transient.el (gptel-menu, gptel--suffix-send):  Add a
transient menu option to select the prompt from the kill-ring.
By default the latest kill is selected.  Sending with a prefix-arg
allows for choosing the kill ring element.

TODO: This latter behavior needs to be made discoverable somehow.
2024-01-12 22:27:20 -08:00
Karthik Chikmagalur
8ec233d79c gptel: Name gptel buffer according to backend
* gptel.el (gptel-default-session, gptel): Name the gptel buffer
according to the default backend.  Delete the variable
`gptel-default-session`.  Fix #174.

* gptel-openai.el (gptel-make-openai): Don't specify a key by
default. Fix #170.
2024-01-12 22:27:20 -08:00
Karthik Chikmagalur
3af2650342 gptel-transient: save window state when ediff
* gptel-transient.el (gptel--suffix-rewrite-and-ediff): Save
window configuration and restore it after rewriting+ediff.
2024-01-02 19:37:55 -08:00
Karthik Chikmagalur
48047c0600 gptel-transient: Improve system-message edit buffer
* gptel-transient.el (gptel--suffix-system-message):  Use a header
line for better messaging when editing the system prompt.
2023-12-29 15:28:37 -08:00
Karthik Chikmagalur
e5357383ce gptel: Appease byte-compiler and linter
* gptel-transient.el:

* gptel-openai.el:

* gptel-gemini.el:
2023-12-29 13:19:23 -08:00
Karthik Chikmagalur
0690c8b6a9 gptel-transient: Exit transient when writing directive
* gptel-transient.el (gptel--suffix-system-message): Explicitly
set the :transient slot of the system-message editor commands to
`transient--do-exit` (#157).
2023-12-27 08:35:06 -08:00
Karthik Chikmagalur
c3ca4fd0a0 gptel-transient: Set suffix-state explicitly for directives
* gptel-transient.el (gptel-system-prompt--setup): In Transient
v0.5 and up, some suffixes defined dynamically using
`gptel-system-prompt--setup' are being treated as infix commands,
see #140.  Set the `:transient' key of these suffixes to
`transient--do-return' explicitly to avoid this problem.  TODO:
This fix will work but it's not clear why this is needed, this
needs some investigation.
2023-12-25 14:03:43 -08:00
Karthik Chikmagalur
c9d362a3e9 gptel-transient: Set model when redirecting to new buffer
* gptel-transient.el (gptel--suffix-send): When creating a new
session to redirect the response to, ensure that gptel-model is
set correctly in that buffer.
2023-12-21 21:25:05 -08:00
Mark Stuart
4775ade6e0 gptel: add custom gptel-update-destination
README: Mention `gptel-update-destination` in README.

gptel.el (gptel-update-destination, gptel--update-status,
gptel-send, gptel--insert-response): New option
`gptel-update-destination` to control how gptel's status messages
are shown.  `gptel--update-status` replaces
`gptel--update-header-line`.  Replace calls to this function
elsewhere in gptel.el.

gptel-curl.el (gptel-abort, gptel-curl--stream-cleanup,
gptel-curl--stream-insert-response): Use `gptel--update-status` in
place of `gptel--update-header-line`.

gptel-transient.el (gptel--suffix-send): Use
`gptel--update-status` in place of `gptel--update-header-line`.
2023-12-21 17:48:36 -08:00
Karthik Chikmagalur
0ea3c7fb15 gptel-transient: Improve suffix message editor
* gptel-transient.el (gptel--suffix-system-message):  Improve the
editing prompt for custom suffixes.  Unset the "C-c C-c" and "C-c
C-k" keys from text-mode.  FIXME: This is fragile, instead add the
keymap with these keys as a sticky text-property over the text.
2023-12-16 16:00:09 -08:00
Moritz
3e361323d5
Update available OpenAI GPT models to match API (#146)
gptel-transient.el (gptel--infix-model):
gptel.el (gptel-model, gptel--openai): Update gpt-4 models.
2023-12-07 18:21:01 -08:00
Karthik Chikmagalur
de6d8089cd gptel-transient: Fix system-message setting function
gptel-transient.el (gptel--suffix-system-message): Removing the
`(setf (buffer-local-value ...))` construct (as instructed to by
the byte compiler) introduced a bug where custom system message
were set from the wrong buffer.  Handle this correctly to fix #138
and possibly #140.
2023-11-20 11:25:12 -08:00
Karthik Chikmagalur
57a70c23cb gptel: Skip to end of word before sending
* gptel.el (gptel--at-word-end, gptel-send, gptel-request):
Include the word the cursor is on in the prompt, and don't break
it when inserting the response.  This is primarily useful for
evil-mode users who frequenty end up one char before the end of a
word when they switch to normal-mode.

* gptel-transient.el (gptel-send): Same.  Also fix bug with
selecting an existing buffer to send the response to.
2023-11-07 21:19:25 -08:00
Karthik Chikmagalur
3c01477c37 gptel: api-key shenanigans
gptel.el (gptel--get-api-key, gptel, gptel-mode,
gptel-make-openai, gptel-api-key-from-auth-source): Handle models
that don't require an API key.

gptel-transient.el (gptel--suffix-system-message): Set backend
from buffer-local value when invoking, and handle API key
requirement better.
2023-11-07 20:36:37 -08:00
Karthik Chikmagalur
c97778d5a8 gptel: address byte-compile and checkdoc warnings
* gptel.el, gptel-transient.el, gptel-openai.el, gptel-ollama.el
2023-11-07 20:36:37 -08:00
Karthik Chikmagalur
6419e8f021 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-28 23:57:47 -07:00
Karthik Chikmagalur
644fc1de2f gptel-transient: Handle empty input when setting temperature 2023-10-24 16:26:07 -07:00
Tianshu Wang
f0b18c5f8b
gptel-transient: Exit gptel-system-prompt after selection (#96)
gptel-transient.el (gptel-menu, gptel-system-prompt--setup): Exit
the system prompt interface when picking a prompt. This saves the
user a `C-g`.
2023-08-13 11:08:47 -07:00
Tianshu Wang
a660e13a8b
gptel, gptel-transient: Fix read temperature from minibuffer (#85)
gptel-transient.el (gtel--transient-read-variable): Use a custom transient infix reader.

gptel.el (gptel--request-data): Don't use `gptel--numberize'.
2023-07-20 21:33:00 -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
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
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
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
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
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
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