Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new flag introduced: it forces prompt context that is sent to backend, be more explicit #329

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions gptel-org.el
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ value of `gptel-org-branching-context', which see."
(let ((max-entries (and gptel--num-messages-to-send
(* 2 gptel--num-messages-to-send)))
(topic-start (gptel-org--get-topic-start)))
(when topic-start
;; narrow to GPTEL_TOPIC property scope
(narrow-to-region topic-start prompt-end))
(if topic-start
;; narrow to GPTEL_TOPIC property scope
(narrow-to-region topic-start prompt-end)
(when (and gptel-force-prompt-context-be-explicit (buffer-file-name))
(error "explicit prompt context forced but org's topic not present
along hierarchical lineage of the current Org heading")))
(if gptel-org-branching-context
;; Create prompt from direct ancestors of point
(if (fboundp 'org-element-lineage-map)
Expand Down Expand Up @@ -203,6 +206,8 @@ value of `gptel-org-branching-context', which see."
'(gptel org)
"Using `gptel-org-branching-context' requires Org version 9.6.7 or higher, it will be ignored.")
(gptel--parse-buffer gptel-backend max-entries))
(when (and gptel-force-prompt-context-be-explicit (buffer-file-name))
(error "explicit prompt context forced but org's branching context is not set"))
;; Create prompt the usual way
(gptel--parse-buffer gptel-backend max-entries))))

Expand Down
20 changes: 18 additions & 2 deletions gptel.el
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,19 @@ with `gptel-mode' enabled), where user prompts and responses are
always handled separately."
:type 'boolean)

(defcustom gptel-force-prompt-context-be-explicit nil
"Force the context that is sent along the prompt be explicitly bound.

If non-nil, then:
For Org mode's FILE buffers: `gptel-org-branching-context' must be non-nil
and conversation topic needs to be present
in hierarchical lineage of the current Org
heading.
For other buffers: region must be marked."
:local t
:type 'boolean
:group 'gptel)

(defvar-local gptel--old-header-line nil)


Expand Down Expand Up @@ -1050,8 +1063,11 @@ there."
((derived-mode-p 'org-mode)
(require 'gptel-org)
(gptel-org--create-prompt (or prompt-end (point-max))))
(t (goto-char (or prompt-end (point-max)))
(gptel--parse-buffer gptel-backend max-entries)))))))
(t
(when gptel-force-prompt-context-be-explicit
(error "explicit prompt context forced but region is NOT marked"))
(goto-char (or prompt-end (point-max)))
(gptel--parse-buffer gptel-backend max-entries)))))))

(cl-defgeneric gptel--parse-buffer (backend max-entries)
"Parse current buffer backwards from point and return a list of prompts.
Expand Down