Commit graph

255 commits

Author SHA1 Message Date
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
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
d5b10c3d6d gptel: gptel-model can be an arbitrary string
* gptel.el (gptel-model): Allow gptel-model to be an arbitrary
string in the customize interface so it can be set with setopt
etc. (See #152.)
2024-01-02 14:47:19 -08:00
Karthik Chikmagalur
3ac5963080 README: Add instructions for Llamafile
* README.org (* Llama.cpp): As it turns out, text-generation
Llamafile models (currently Mistral Instruct and Llava) offer an
OpenAI-compatible API, so we can use them easily from gptel.  Add
instructions for Llamafiles to the Llama section of the README.
2023-12-31 14:37:26 -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
1e31f550de gptel: Declare compat as explicit dependency
* gptel.el (gptel--always, gptel--button-buttonize): Currently
gptel depends on the Compat library transitively via transient.el.
Declare it as an explicit dependency so we can get rid of special
case definitions and simplify.  This also enables us to use Emacs
28 and 29 conveniences freely in the code.
2023-12-29 13:06:25 -08:00
Karthik Chikmagalur
85bd47cb4c README: Add support for llama.cpp
* README.org: The llama.cpp server supports OpenAI's API, so we
can reuse it.  Closes #121.
2023-12-28 22:27:53 -08:00
Karthik Chikmagalur
f571323174 gptel-gemini: Simulate system-message for gemini
* gptel-gemini.el (gptel--parse-buffer): The Gemini API does not
provide an explicit system message parameter.  In the interest of
providing a uniform interface, simulate this in gptel by
prepending the first user message with `gptel--system-message`.
2023-12-27 22:35:41 -08:00
Karthik Chikmagalur
60cb406567 gptel: Improve documentation of gptel-send
* gptel.el (gptel-send): Update the docstring to describe the
behavior accurately.
2023-12-27 12:34:47 -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
32dd463bd6 README: Mention YouTube demo
* gptel.el: Change blurb

* README.org: Mention YouTube demo
2023-12-27 08:35:06 -08:00
Karthik Chikmagalur
9126bed43f gptel: Set window when doing auto-scrolling
* gptel.el (gptel-auto-scroll):  After calling `gptel-send`, the
window focus could have changed as the response is received.  Set
the window correctly when running `gptel-auto-scroll` to ensure
the correct buffer is scrolled.
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
8d3e08faa8 gptel: Don't use called-interactively-p
* gptel.el (gptel): Switch from the fragile
`called-interactively-p` to using the interactive form to check if
`gptel` is called interactively.
2023-12-22 16:49:04 -08:00
Karthik Chikmagalur
2e92c0303c gptel: gptel-backend-url can accept functions
* gptel.el (gptel--url-get-response): If the backend-url is a
function, call it to find the full url to query.

* gptel-gemini.el: Gemini uses different urls for
streaming/oneshot responses.  Set the backend-url to a function to
account for the value of gptel-stream.  This is also safer than
before as the API key is not stored as part of a static url string
in memory. Fix #153.

* gptel-curl.el (gptel-curl--get-args): If the backend-url is a
function, call it to find the full url to query.
2023-12-22 16:25:32 -08:00