Commit graph

220 commits

Author SHA1 Message Date
Karthik Chikmagalur
3d6147830e gptel: Fix model/backend mismatch (#242)
* gptel.el (gptel--sanitize-model, gptel): Check for mismatches
between the default values of gptel-backend and gptel-model when
starting a new gptel chat.  Previously the default value of
gptel-backend was compared against the buffer-local value of
gptel-model.
2024-03-09 14:26:45 -08:00
Karthik Chikmagalur
5e9e36d854 gptel: rear-nonsticky text-property by default
* gptel.el (gptel--insert-response, gptel--restore-state): Don't
set the rear-nonsticky property on the gptel response text.
Instead, the gptel text-property is globally declared to be
nonsticky via `text-property-default-nonsticky`.

This change is since markdown-mode makes rear-nonsticky a
font-lock-managed property and we can't set it manually.  Setting
this property explicitly also makes all text properties in the
range nonsticky, which can have unintended side effects.

* gptel-curl.el (gptel-curl--stream-insert-response): Ditto.
2024-03-08 19:09:48 -08:00
Karthik Chikmagalur
b634f05fe5 gptel: Tweak markdown to org conversion
gptel.el (gptel--convert-markdown->org,
gptel--stream-convert-markdown->org): Handle the case of Markdown
bullet lists that begin with a "*", which the Gemini LLMs produce
often.  Address #238.
2024-03-07 18:24:31 -08:00
Karthik Chikmagalur
2487ada4d6 gptel-anthropic: Handle missing response chunks (trial)
gptel-anthropic.el (gptel-curl--parse-stream): Reset point
explicitly when parsing streaming responses returned by the
Anthropic API.  Try to address #233.
2024-03-07 17:03:21 -08:00
Karthik Chikmagalur
199595b0c8 gptel: Handle status HTTP 100
gptel.el (gptel--url-parse-response): Handle HTTP 100 followed by
200.  Note: this fix is brittle, it will break if 100 is followed
by an error code.

gptel-curl.el (gptel-curl--stream-filter,
gptel-curl--parse-stream): Ditto.  Address #194.
2024-03-07 10:46:30 -08:00
Karthik Chikmagalur
a32f4effe5 gptel-curl: Handle empty responses correctly
gptel-curl.el (gptel-curl--stream-cleanup): The LLM response can
be empty with HTTP status 200, for example when the API responds
with an error description instead.  Handle this case gracefully.
When `gptel-mode` is enabled, also inform the user that the
response was empty.  Fix #234.

gptel.el (gptel-post-response-functions): Documentation.  Explain
the arguments passed to each hook function in this hook when the
response fails or is empty.
2024-03-07 10:23:59 -08:00
Karthik Chikmagalur
0d6264f268 gptel-curl: Adjust response beginning position
gptel-curl.el (gptel-curl--stream-cleanup,
gptel-curl--stream-insert-response): Don't consider
`gptel-response-prefix-string` part of the response for the
purpose of running `gptel-post-response-functions`.
2024-03-05 22:51:14 -08:00
Karthik Chikmagalur
eb088f2f21 gptel-anthropic: support Anthropic AI's Claude 3 (#229)
* gptel.el: Mention Anthropic in the package description.

* gptel-anthropic.el (gptel-anthropic, gptel-make-anthropic,
gptel--parse-response, gptel--request-data, gptel--parse-buffer,
gptel-curl--parse-stream): Add support for Anthropic AI's Claude 3
models.

* README.org: Add instructions for using Anthropic AI's Claude 3
models.
2024-03-04 11:28:57 -08:00
Karthik Chikmagalur
87c190076e README: Clarify example configuration code
README.org (all custom backends): Clarify how to set a backend as
the gptel default.  This has been confusing users.
2024-02-28 18:28:36 -08: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
8ba07d042c gptel: Bump version
* gptel.el: Bump version
2024-02-21 00:11:03 -08:00
r0man
43f625ecb9
gptel-openai: curl-args slot in gptel-backend (#221)
gptel-openai.el (gptel-backend, gptel-make-openai,
gptel-make-azure): Add a curl-args slot to the backend struct for
additional Curl arguments.

Usage example: This can be used to set the `--cert` and `--key`
options in a custom backend that uses mutal TLS to communicate
with an OpenAI proxy/gateway.

gptel-curl.el (gptel-curl--get-args): Add backend-specific
curl-args when creating HTTP requests.

gptel-gemini.el (gptel-make-gemini): Add a curl-args slot to the
constructor.
gptel-kagi.el (gptel-make-kagi): Ditto.
gptel-ollama.el (gptel-make-ollama): Ditto.
2024-02-20 15:21:46 -08:00
Karthik Chikmagalur
226f8f0d90 gptel: Add customizable display-action (#216)
* gptel.el (gptel-display-buffer-action, gptel): Add
`gptel-display-buffer-action` to customize the display of the
gptel buffer.

* README: Mention new option.
2024-02-10 12:04:03 -08:00
Karthik Chikmagalur
5465271541 gptel: Add gpt-4-0125-preview to model list (Fix #215)
* gptel.el (gptel--openai): Add "gpt-4-0125-preview" to the list
of ChatGPT models.  Also address byte-compiler warnings.
2024-02-09 12:15:03 -08:00
Karthik Chikmagalur
ef8b9093d2 gptel-gemini: Use permissive API safety settings
* gptel-gemini.el (gptel-make-gemini, gptel--request-data): The
Gemini API misclassifies harmless questions (like "What's 2+2",
see #208) as harmful.  Use the most permissive safety settings the
API offers.

Also respect the value of `:stream` used when defining Gemini
backends.
2024-02-07 19:03:45 -08:00
Karthik Chikmagalur
e2eccd8b08 gptel: Remove references to gptel--debug (fix #205)
* gptel.el (gptel--url-parse-response): Remove reference to
`gptel--debug`.

* gptel-curl.el (gptel-curl--sentinel): Remove reference to
`gptel--debug`.
2024-02-04 22:23:45 -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
Dave Berton
d8c604b53b
README: Update with instructions for perplexity.ai (#204)
README.org: perplexity.ai provides an OpenAI-style API.  Also remove 
some extra whitespace.
2024-02-03 16:36:24 -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
Karthik Chikmagalur
2c87acddd5 gptel: Add request logging (Fix #165)
* gptel.el (gptel--debug, gptel-log-level, gptel--log-buffer-name,
gptel--url-get-response, gptel--parse-response): Optionally log
all request and response data to `gptel--log-buffer-name`, with
the log level governed by `gptel-log-level`.  Obsolete
`gptel--debug`.

* gptel-curl.el (gptel-curl--log-response, gptel-curl--get-args,
gptel-curl--get-response, gptel-curl--stream-cleanup,
gptel-curl--sentinel): Add support for logging.
2024-02-03 13:46:26 -08:00
Karthik Chikmagalur
6a385ffc2f README: Add FAQ entry for OpenAI quota error (#93) 2024-02-03 09:43:16 -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
f0e4889c36 gptel: Update OpenAI model list
* gptel.el (gptel--openai, gptel-model): Update available OpenAI
models, fix #197.
2024-01-30 20:45:37 -08:00
Karthik Chikmagalur
10f57605ce gptel: Improve Org stream conversion
* gptel.el (gptel--convert-markdown->org,
gptel--stream-convert-markdown->org): Don't touch underscores in
the source markdown.  This will turn some emphasis blocks into
underlines in Org, but we can live with that.  Fix #40.
2024-01-28 14:34:55 -08:00
Karthik Chikmagalur
c41a53f526 gptel: save/restore multi-line directives (#180)
* gptel.el (gptel--restore-state, gptel--save-state): Try to
support writing/reading multi-line directives in Org and other
modes correctly when saving the buffer.  The support is
preliminary and works as follows:
- org-mode: Replace newlines with "\n" before writing the relevant
  org property.
- other modes: escape newlines with print-escape-newlines when
updating local vars.

Neither of these is a good fix, but brings support for multi-line
directives up from completely broken to works-via-hack.  They are
subject to change in the future and might break some chat files. :(
2024-01-26 17:52:43 -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
89decb4201 README: Mention transient menu option saving
* README.org (FAQ): Mention the option to save transient menu
options (see #94, #192).
2024-01-21 18:48:41 -08:00
Karthik Chikmagalur
e79e386964 README: Move gptel-request to FAQ
* README.org (FAQ): Move the gptel-request description to the
FAQ (for issues like #191.)
2024-01-20 13:19:52 -08:00
Karthik Chikmagalur
8a25058eed gptel-openai: default :header key to simplify config
* gptel.el (gptel--openai): Don't specify header.

* gptel-openai.el (gptel-make-openai): Use a key-aware lambda for
the header argument.  This should make it easier to define new
OpenAI-style API backends (see #177, #184)

* README.org: Update with instructions for together.ai and
Anyscale, both of which provide OpenAI-style APIs.  Clean up the
config blocks for the other backends.
2024-01-19 14:45:36 -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
João Távora
b3d028d074 Add .gitignore 2024-01-18 17:33:13 -08:00
João Távora
1fcb4606a2 Fix compilation warning in gptel-openai.el
* gptel-openai.el (cl-lib): Require it.

* gptel.el (compat): Leniently require compat so gptel.el can be
compiled standalone.  This will expose other compiler errors that
are easily visible with M-x flymake.
2024-01-18 17:32:08 -08:00
Karthik Chikmagalur
92a8c0bdac gptel: letrec expansion error in Emacs 27.2
* gptel.el (gptel--stream-convert-markdown->org): (Bug #183) Set
variables to nil explicitly in the bindings section of letrec.
Implicit nil letrec-bindings appears to cause an issue with Emacs
27.2.
2024-01-17 09:45:59 -08:00
Karthik Chikmagalur
b34e217bbf README: Mention gptel-request
* README.org:
- Mention gptel-request near the top.
- Reformat FAQ
- Add solution to #75 and #182 (Doom Emacs keybinding conflict) to
  the FAQ
2024-01-16 20:26:03 -08:00
Karthik Chikmagalur
3fb064a763 gptel: Better handling of read-only bufs
* gptel.el (gptel--insert-response): Turn on visual-line-mode in
the response buffer that is created when the gptel buffer is
read-only.

* gptel-curl.el (gptel-curl--stream-insert-response): Ditto.
2024-01-15 17:29:42 -08:00
Karthik Chikmagalur
1752f1d589 gptel-kagi: Add support for the Kagi summarizer
* gptel-kagi.el (gptel--request-data, gptel--parse-buffer,
gptel-make-kagi): Add support for the Kagi summarizer.  If there
is a url at point (or at the end of the provided prompt), it is
used as the summarizer input.  Otherwise the behavior is
unchanged.

* README (Kagi): Mention summarizer support.

* gptel.el: Mention summarizer support.
2024-01-15 17:29:42 -08:00
Karthik Chikmagalur
c6a07043af gptel-kagi: Add support for Kagi FastGPT
* gptel.el: Bump version and update package description.

* gptel-kagi.el (gptel--parse-response, gptel--request-data,
gptel--parse-buffer, gptel-make-kagi): Add new file and support
for the Kagi FastGPT LLM API.  Streaming and setting model
parameters (temperature, max tokesn) are not supported by the API.
A Kagi backend can be added with `gptel-make-kagi`.

* README.org: Update with instructions for Kagi.
2024-01-12 23:17:21 -08:00
Karthik Chikmagalur
612aea3456 gptel: Make gptel-post-response-* easier to use
* gptel.el (gptel-end-of-response, gptel-post-response-hook,
gptel-post-response-functions, gptel--insert-response,
gptel-response-filter-functions):
Rename gptel-post-response-hook -> gptel-post-response-functions
The new abnormal hook now calls its functions with the start and
end positions of the response, to make it easier to act on the
response.

* gptel-curl.el (gptel-curl--stream-cleanup): Corresponding changes.

* README.org: Mention breaking change.
2024-01-12 23:04:40 -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
bea31e33e2 gptel-ollama: Use default host in gptel-make-ollama 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
e67ed41e31 README: Specify: no key needed for llama backend
* README.org: Specify that no key is needed when defining a
Llama.cpp backend.  Fix #170.
2024-01-05 20:55:52 -08:00
Karthik Chikmagalur
febeada960 gptel: Make gptel-backend customizable
* gptel.el (gptel-backend): Turn `gptel-backend` into a defcustom
so it can be used with setopt.  Fix #167.

* gptel-openai.el (gptel-make-openai): Improve docstring.
2024-01-05 20:55:52 -08:00
Bruno Bigras
0fce1d86d1
README: fix typo (#168) 2024-01-03 18:58:29 -08:00