Commit graph

249 commits

Author SHA1 Message Date
Karthik Chikmagalur
26326c302e gptel-anthropic: Parsing fix
gptel-anthropic.el (gptel-curl--parse-stream): When parsing
responses from Anthropic, wait for more input when the
corresponding data chunk for the event hasn't arrived yet. (#261)
2024-03-29 14:08:32 -07:00
Karthik Chikmagalur
9a5a4a60d5 README: Mention wiki entry on saving transient flags
* README.org (FAQ): Mention wiki entry on saving transient flags.
2024-03-21 11:30:30 -07:00
Karthik Chikmagalur
12e00cbd09 gptel-transient: No pre-fill when reading from minibuffer
* gptel-transient.el (gptel--suffix-send): Don't pre-fill the
minibuffer prompt with the current line when reading the query
from the minibuffer.  (If the region is active, it is used as the
initial contents -- this behavior is unchanged.)
2024-03-21 10:40:31 -07:00
Karthik Chikmagalur
34a52aa047 gptel-anthropic: Remove debug code
* gptel-anthropic.el (gptel--parse-response): Remove left over
debugging code.
2024-03-21 10:23:16 -07:00
Karthik Chikmagalur
9eea4be5ed gptel-transient: Fix gptel-menu definition bug (#265)
gptel-transient.el (gptel-menu): Fix error in definition syntax.
Fix provided by @wrn.
2024-03-20 19:46:41 -07:00
Fredrik Bergroth
9bc54bed9c
gptel-transient: Remove "-ts" suffix from major mode (#259)
gptel-transient (gptel--rewrite-message): Remove "-ts" suffix from
major mode.
2024-03-19 18:06:48 -07:00
Karthik Chikmagalur
5d069cfca8 gptel-anthropic: Simplify stream parser
* gptel-anthropic.el (gptel-curl--parse-stream): Remove extraneous
statements and simplify the stream parser.  Addresses #261, but
the main problem is still elusive.
2024-03-19 18:01:55 -07:00
Karthik Chikmagalur
22f7043c32 gptel: Fix gptel-end-of-response
* gptel.el (gptel-end-of-response): Handle non-interactive case
where one of the function arguments can be nil.  Fix #262.
2024-03-19 17:39:13 -07:00
Karthik Chikmagalur
5dcbf40066 gptel: Make model parameters global
* gptel.el (gptel-backend, gptel-model, gptel-temperature,
gptel-max-tokens, gptel--num-messages-to-send,
gptel--system-message): Make all model/request paramters global
variables, i.e. not buffer-local by default.  This is following
the discussion in #249.

* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--suffix-system-message,
gptel--infix-provider, gptel--infix-temperature, gptel--switches,
gptel--set-buffer-locally, gptel--set-with-scope): and associated
transient methods: add a toggle `gptel--set-buffer-locally` to
allow model parameters to be set buffer-locally.  The function
`gptel--set-with-scope` can be used to reset a variable or set it
buffer-locally.

Reorder gptel-transient so all the custom classes, methods and
utility functions are at the top.

* README.org (all backend sections): Replace `setq-default` with
setq in the recommended configuration.
2024-03-16 20:59:48 -07:00
Karthik Chikmagalur
e3b3591d73 README: Add support for Groq (#257)
* README.org: Mention details for configuring Groq.
2024-03-16 20:27:54 -07:00
Karthik Chikmagalur
94b13e78ec gptel-transient: enable additional directive by default
* gptel-transient.el (gptel-menu, gptel--infix-add-directive,
gptel--suffix-system-message):  Enable the additional directive
option in `gptel-menu` by default, and change the wording of
documentation strings for transient options.
2024-03-16 20:17:52 -07:00
Karthik Chikmagalur
b31c9be5e0 gptel-ollama: Adjust Ollama stream parser for libjansson
* gptel-ollama.el (gptel-curl--parse-stream): libjansson and
json.el behave differently w.r.t moving point when there is a
parsing error.  Fix by explicitly handling point when there is an
error. (#255)
2024-03-16 20:17:52 -07:00
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
f529457bbe gptel: Use visual-line-mode when ediff-ing
* gptel.el (gptel--ediff): Use `visual-line-mode` when ediff-ing.
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
260be9d8d4 gptel: Consolidate HTTP request process
* gptel.el (gptel-request, gptel-send, gptel--url-get-response):
Consolidate the HTTP query construction into `gptel-request`,
and use it as the single point for sending gptel queries.  This
simplifies the code, makes it easier to debug and (later) advise
or otherwise modify.  To this end, `gptel-send` reuses
`gptel-request` and no longer does its own thing.  Adjust other
HTTP request-related functions accordingly.

* gptel-curl.el (gptel-curl--get-args, gptel-curl--get-response):
Receive the full request data instead of constructing it partly in
`gptel-curl--get-args`.
2024-03-14 20:28:21 -07:00
Karthik Chikmagalur
e5f54d1d09 gptel-anthropic: Modify order of request items
* gptel-anthropic.el (gptel--request-data): Move the messages to
the end of the request data object for easier inspection.
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
Karthik Chikmagalur
07992f79cc gptel-anthropic: Support for the Claude haiku model
* gptel-anthropic.el (gptel-make-anthropic): Add Claude-3-haiku to
the list of supported Anthropic models.
2024-03-14 20:28:21 -07:00
Karthik Chikmagalur
e18ceb1f84 gptel: Improve logging
* gptel.el (gptel--url-get-response): Log request headers as JSON objects.

* gptel-curl.el (gptel-curl--get-args, gptel-curl--get-response):
Log request headers as JSON objects, Curl command as a shell
command you can copy and paste into the terminal.
2024-03-14 20:28:21 -07:00
Karthik Chikmagalur
f58ad9435c gptel: Use libjansson support if available
Using the libjansson JSON parser gives us a modest boost in speed.
It's not as significant a speedup as it is for LSP clients since
our jSON payloads are smaller and less frequent -- but we might as
well use it.

* gptel.el (gptel--json-read, gptel--json-encode,
gptel--url-get-response, gptel--parse-response): Define macros to
use the libjansson-supported `json-parse-buffer` and
`json-serialize`.  Replace use of `json-encode` and `json-read`
appropriately.

* gptel-openai.el: (gptel-curl--parse-stream) : Use
`gptel--json-read` instead of `json-read`.

* gptel-ollama.el (gptel-curl--parse-stream): Use
`gptel--json-read` instead of `json-read`.

* gptel-gemini.el (gptel-curl--parse-stream): Use
`gptel--json-read` instead of `json-read`.

* gptel-curl.el (gptel-curl--get-args, gptel-curl--get-response,
gptel-curl--log-response, gptel-curl--stream-cleanup,
gptel-curl--parse-response): Use `gptel--json-read` and
`gptel--json-encode` in place of the json.el versions.

* gptel-anthropic.el (gptel-curl--parse-stream): Use
`gptel--json-read` instead of `json-read`.

* test/gptel-org-test.el: Use `gptel--json-read`.
2024-03-14 20:28:21 -07:00
Karthik Chikmagalur
fbb0ee29c4 gptel-org-test: Add mores tests for org conversion
* test/gptel-org-test.el: Rename file from test-gptel-org.el, and
add more tests.
2024-03-13 00:52:56 -07:00
Karthik Chikmagalur
9925dc91b4 gptel: Improve markdown converter
* gptel.el (gptel--stream-convert-markdown->org,
gptel--replace-source-marker): Handle backquote conversion much
better during stream-based conversion.  One-shot conversions still
require fixing.
2024-03-13 00:48:22 -07:00
Karthik Chikmagalur
d502ad8ecb test-gptel-org: Add markdown conversion tests
* test/test-gptel-org.el (test--gptel-convert-markdown->org,
test--gptel--stream-convert-markdown->org): Add tests

Also remove out-of-date demo image.
2024-03-11 00:49:05 -07:00
Cash Prokop-Weaver
3935a6dcf8
♻️: Untangle Gemini model and endpoint #212 (#213)
gptel-gemini.el (gptel-make-gemini): Decouple the Gemini model
from the API endpoint.  This is to support additional model
options in the future.
2024-03-10 21:02:42 -07:00
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