Commit graph

278 commits

Author SHA1 Message Date
Nick Anderson
ec0e461b35 gptel-curl: Increased curl timeout (#127)
gptel-curl.arg (gptel-curl--get-args): Increase curl timeout.

Often local LLMs will offload a query to CPU if there is not enough VRAM or in
the case of an unsupported GPU. When a query is offloaded to the CPU responses
can be significantly slower. If curl times out early the user will not get the
response from the LLM back in Emacs.

This change increases the timeout for curl from 60s to 300s to make gptel usable
in slower environments.

Closes #125
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
50a2498259 README: Tweak instructions for local LLMs, mention #120 2023-11-07 20:36:37 -08:00
Karthik Chikmagalur
63027083cd README: Update additional customization section 2023-10-29 14:24:39 -07:00
Karthik Chikmagalur
6af89254b7 README: Document breaking changes (mainly gptel-host deprecation) 2023-10-29 09:51:17 -07:00
Karthik Chikmagalur
aa50cbab70 gptel: Bump version 2023-10-29 00:34:39 -07:00
Karthik Chikmagalur
1434bbac7b gptel-ollama, gptel-openai: Add example of backend creation
README: Fix error with Ollama backend instructions
2023-10-29 00:31:56 -07:00
Karthik Chikmagalur
190d1d20e2 gptel: Update header line and package info description 2023-10-29 00:25:44 -07: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
61c0df5e19 gptel, gptel-curl: Make the gptel text-property non-sticky
gptel.el (gptel--insert-response):
gptel-curl.el (gptel-curl--stream-insert-response): Make the `gptel'
text-property rear-nonsticky so typing after it is recognized as part of the
user prompt.
2023-10-28 19:34:54 -07:00
Karthik Chikmagalur
644fc1de2f gptel-transient: Handle empty input when setting temperature 2023-10-24 16:26:07 -07:00
Karthik Chikmagalur
62a6020302 gptel, gptel-curl: Allow protocol (https) to be set separately 2023-10-23 10:45:59 -07:00
Karthik Chikmagalur
ed0bfc9ed1 gptel: Offer suggestion when setting gptel-topic
gptel.el (gptel-set-topic): Offer a suggestion when setting a GPTEL_TOPIC
property for an Org heading.

Fix linting in docstring.
2023-10-22 11:50:41 -07:00
Karthik Chikmagalur
648fa228a1 gptel: Fix check for markdown-mode (#109)
* gptel.el (gptel-default-mode): Use `fboundp' instead of `featurep' to check if
markdown-mode is available, since the latter requires `markdown-mode' to be
already loaded.
2023-10-03 14:47:54 -07:00
Karthik Chikmagalur
24add64455 gptel: Adjust how gptel--system-message is set
* gptel.el (gptel--system-message, gptel-directives): Try to make
gptel--system-message read from gptel-directives.  This doesn't yet work how
we need it to -- changing gptel-directives does not update
gptel--system-message.
2023-10-03 09:49:35 -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
Karthik Chikmagalur
6e4d95a70a README: Add drawers to installation instructions 2023-08-12 11:27:10 -07:00
Karthik Chikmagalur
b2a01b8d65 README: Explain saving/restoring sessions better 2023-08-09 17:58:13 -07:00
Karthik Chikmagalur
c0ffce0849 gptel: Fix reading bounds in org files (#98)
* gptel.el (gptel--restore-state): When there is no "GPTEL_BOUNDS"
org property, `read' asks for stdin instead.  Fix by only calling
`read' when this property is non-nil.

Thanks to @Elilif for spotting this bug.
2023-08-05 17:41:35 -07:00
Karthik Chikmagalur
0f161a466b gptel: saving and restoring state for Markdown/Text
* gptel.el (gptel--save-state, gptel--restore-state,
gptel-temperature, gptel-model, gptel-max-tokens,
gptel-directives, gptel--always, gptel--button-buttonize,
gptel--system-message, gptel--bounds): Write gptel parameters as
file-local variables when saving chats in Markdown or text files.
The local variable gptel--bounds stores the locations of the
responses from the LLM. This is not a great solution, but the best
I can think to do without adding more syntax to the document.

Chats can be restored by turning on `gptel-mode'.  One of the
problem with this approach is that if the buffer is modified
before `gptel-mode' is turned on, the state data is out of date.
Another problem is that this metadata block as printed in the
buffer can become quite long.  A better approach is needed.

Define helper functions `gptel--always' and
`gptel--button-buttonize' to work around Emacs 27.1 support.

* README.org: Mention saving and restoring chats where
appropriate.
2023-07-28 16:05:22 -07:00
Karthik Chikmagalur
e0a7898645 gptel: Add pre-response-hook
* gptel.el (gptel--insert-response, gptel-pre-response-hook): New
user option `gptel-pre-response-hook' that runs before the
response is inserted into the buffer.  This can be used to prepare
the buffer in some user-specified way for the response.

* gptel-curl.el (gptel-curl--stream-filter): Run
`gptel-pre-response-hook' before inserting streaming responses.
2023-07-25 16:03:22 -07:00
Karthik Chikmagalur
c20fba8247 gptel-curl: Only convert to Org in Org buffers
* gptel-curl.el (gptel-curl-get-response): Don't convert response
into org-mode unless the buffer from which the request originated
is in org-mode.  This makes `gptel-default-mode' less binding, and
only used when creating a new chat session with `gptel'.  Also,
gptel should now do the right thing depending on whether the
current buffer is in text, Markdown or Org modes.
2023-07-21 13:32:07 -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
b92fc389d7 gptel: Reduce verbosity of gptel--save-state
* gptel.el (gptel--save-state): Only write `gptel-temperature' to
the file if it is different from the default value of the variable.
2023-07-20 14:14:18 -07:00
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