Compare commits
1 commit
3f31258e48
...
bf02ee68a4
Author | SHA1 | Date | |
---|---|---|---|
|
bf02ee68a4 |
2 changed files with 82 additions and 11 deletions
49
README.org
49
README.org
|
@ -560,16 +560,16 @@ The above code makes the backend available to select. If you want it to be the
|
||||||
|
|
||||||
(This is also a [[https://www.youtube.com/watch?v=bsRnh_brggM][video demo]] showing various uses of gptel.)
|
(This is also a [[https://www.youtube.com/watch?v=bsRnh_brggM][video demo]] showing various uses of gptel.)
|
||||||
|
|
||||||
|-------------------+-------------------------------------------------------------------------|
|
|--------------------+----------------------------------------------------------------------------------------|
|
||||||
| *Command* | Description |
|
| *Command* | Description |
|
||||||
|-------------------+-------------------------------------------------------------------------|
|
|--------------------+----------------------------------------------------------------------------------------|
|
||||||
| =gptel-send= | Send conversation up to =(point)=, or selection if region is active. Works anywhere in Emacs. |
|
| =gptel-send= | Send conversation up to =(point)=, or selection if region is active. Works anywhere in Emacs. |
|
||||||
| =gptel= | Create a new dedicated chat buffer. Not required to use gptel. |
|
| =gptel= | Create a new dedicated chat buffer. Not required to use gptel. |
|
||||||
| =C-u= =gptel-send= | Transient menu for preferences, input/output redirection etc. |
|
| =C-u= =gptel-send= | Transient menu for preferences, input/output redirection etc. |
|
||||||
| =gptel-menu= | /(Same)/ |
|
| =gptel-menu= | /(Same)/ |
|
||||||
|-------------------+-------------------------------------------------------------------------|
|
|--------------------+----------------------------------------------------------------------------------------|
|
||||||
| =gptel-set-topic= | /(Org-mode only)/ Limit conversation context to an Org heading |
|
| =gptel-set-topic= | /(Org-mode only)/ Limit conversation context to an Org heading |
|
||||||
|-------------------+-------------------------------------------------------------------------|
|
|--------------------+----------------------------------------------------------------------------------------|
|
||||||
|
|
||||||
*** In any buffer:
|
*** In any buffer:
|
||||||
|
|
||||||
|
@ -612,6 +612,35 @@ The default mode is =markdown-mode= if available, else =text-mode=. You can set
|
||||||
|
|
||||||
Saving the file will save the state of the conversation as well. To resume the chat, open the file and turn on =gptel-mode= before editing the buffer.
|
Saving the file will save the state of the conversation as well. To resume the chat, open the file and turn on =gptel-mode= before editing the buffer.
|
||||||
|
|
||||||
|
*** Optional: Add more context to your query
|
||||||
|
|
||||||
|
You can add contextual information from any Emacs buffer by utilizing
|
||||||
|
=gptel-add-context=. Each call will add another snippet including
|
||||||
|
metadata like buffer-name, LOC and major mode.
|
||||||
|
|
||||||
|
1. Select the text you want to add as context. If no text is selected,
|
||||||
|
the entire content of the current buffer will be used.
|
||||||
|
|
||||||
|
2. =gptel-add-context= adds the selected text or the whole buffer
|
||||||
|
content to the "*gptel-context*" buffer.
|
||||||
|
|
||||||
|
3. Proceed with LLM interactions using =gptel= as usual. The added
|
||||||
|
context will influence the LLM's responses, making them more
|
||||||
|
relevant and contextualized.
|
||||||
|
|
||||||
|
4. At any point, you can manually edit the "*gptel-context*" buffer to
|
||||||
|
remove stale information.
|
||||||
|
|
||||||
|
**** Practical Applications
|
||||||
|
|
||||||
|
- Enhancing code development sessions with relevant documentation or
|
||||||
|
code snippets as a reference.
|
||||||
|
- Accumulating research notes or sources while writing papers or
|
||||||
|
articles to ensure consistency in the narrative or arguments.
|
||||||
|
- Providing detailed error logs or system information during debugging
|
||||||
|
sessions to assist in generating more accurate solutions or
|
||||||
|
suggestions from the LLM.
|
||||||
|
|
||||||
** FAQ
|
** FAQ
|
||||||
#+html: <details><summary>
|
#+html: <details><summary>
|
||||||
**** I want the window to scroll automatically as the response is inserted
|
**** I want the window to scroll automatically as the response is inserted
|
||||||
|
|
44
gptel.el
44
gptel.el
|
@ -152,6 +152,15 @@
|
||||||
"Use `gptel-make-openai' instead."
|
"Use `gptel-make-openai' instead."
|
||||||
"0.5.0")
|
"0.5.0")
|
||||||
|
|
||||||
|
(defcustom gptel-context-prompt-preamble
|
||||||
|
"Here, you find more context for the following user prompts. Key aspects are:
|
||||||
|
- User inputs are encapsulated within Emacs Org mode src blocks.
|
||||||
|
- Naming Convention: Each src block is identified using a structured name format '{{name-of-original-buffer}}:{{beginning-line-number}}-{{ending-line-number}}'. This scheme offers insight into the origin and scope of the code or text snippet.
|
||||||
|
- Mode Indication: The mode of the original file is included within each src block. This detail informs you about the programming language or markup format of the snippet, aiding in accurate interpretation and response."
|
||||||
|
"Instruct the llm about how to treat the additional context from *gptel-context*."
|
||||||
|
:group 'gptel
|
||||||
|
:type 'string)
|
||||||
|
|
||||||
(defcustom gptel-proxy ""
|
(defcustom gptel-proxy ""
|
||||||
"Path to a proxy to use for gptel interactions.
|
"Path to a proxy to use for gptel interactions.
|
||||||
Passed to curl via --proxy arg, for example \"proxy.yourorg.com:80\"
|
Passed to curl via --proxy arg, for example \"proxy.yourorg.com:80\"
|
||||||
|
@ -865,7 +874,7 @@ Model parameters can be let-bound around calls to this function."
|
||||||
((markerp position) position)
|
((markerp position) position)
|
||||||
((integerp position)
|
((integerp position)
|
||||||
(set-marker (make-marker) position buffer))))
|
(set-marker (make-marker) position buffer))))
|
||||||
(full-prompt
|
(full-prompt-draft
|
||||||
(cond
|
(cond
|
||||||
((null prompt) (gptel--create-prompt start-marker))
|
((null prompt) (gptel--create-prompt start-marker))
|
||||||
((stringp prompt)
|
((stringp prompt)
|
||||||
|
@ -876,6 +885,17 @@ Model parameters can be let-bound around calls to this function."
|
||||||
(insert prompt)
|
(insert prompt)
|
||||||
(gptel--create-prompt))))
|
(gptel--create-prompt))))
|
||||||
((consp prompt) prompt)))
|
((consp prompt) prompt)))
|
||||||
|
(context-prompt
|
||||||
|
(when (get-buffer "*gptel-context*")
|
||||||
|
(list :role "user"
|
||||||
|
:content (format "%s\n\n%s"
|
||||||
|
gptel-context-prompt-preamble
|
||||||
|
(with-current-buffer "*gptel-context*"
|
||||||
|
(save-excursion
|
||||||
|
(buffer-substring-no-properties (point-min) (point-max))))))))
|
||||||
|
(full-prompt (if context-prompt
|
||||||
|
(append (list context-prompt) full-prompt-draft)
|
||||||
|
full-prompt-draft))
|
||||||
(request-data (gptel--request-data gptel-backend full-prompt))
|
(request-data (gptel--request-data gptel-backend full-prompt))
|
||||||
(info (list :data request-data
|
(info (list :data request-data
|
||||||
:buffer buffer
|
:buffer buffer
|
||||||
|
@ -1338,6 +1358,28 @@ context for the ediff session."
|
||||||
(goto-char (+ beg offset))
|
(goto-char (+ beg offset))
|
||||||
(pulse-momentary-highlight-region beg (+ beg (length alt-response)))))
|
(pulse-momentary-highlight-region beg (+ beg (length alt-response)))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun gptel-add-context ()
|
||||||
|
"Add selected region (or whole buffer) to *gptel-context*."
|
||||||
|
(interactive)
|
||||||
|
(let* ((context (if (use-region-p)
|
||||||
|
(buffer-substring-no-properties (region-beginning) (region-end))
|
||||||
|
(buffer-substring-no-properties (point-min) (point-max))))
|
||||||
|
(src-name (buffer-name))
|
||||||
|
(start (line-number-at-pos (region-beginning)))
|
||||||
|
(end (line-number-at-pos (region-end)))
|
||||||
|
(region-major-mode (symbol-name major-mode))
|
||||||
|
(loc (format "%s:%d-%d" src-name start end)))
|
||||||
|
(with-current-buffer (get-buffer-create "*gptel-context*")
|
||||||
|
(org-mode)
|
||||||
|
(goto-char (point-max))
|
||||||
|
(unless (bolp) (insert "\n"))
|
||||||
|
(insert (format "#+NAME: %s\n" loc))
|
||||||
|
(insert (format "#+BEGIN_SRC %s\n" region-major-mode))
|
||||||
|
(insert (format "%s\n" context))
|
||||||
|
(insert "#+END_SRC\n\n"))
|
||||||
|
(message "Context has been added to *gptel-context*.")))
|
||||||
|
|
||||||
(defun gptel--next-variant (&optional arg)
|
(defun gptel--next-variant (&optional arg)
|
||||||
"Switch to next gptel-response at this point, if it exists."
|
"Switch to next gptel-response at this point, if it exists."
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
|
|
Loading…
Add table
Reference in a new issue