Skip to content

gptel--rewrite-directive-default invoked twice #1153

@sp1ff

Description

@sp1ff

Please update gptel first -- errors are often fixed by the time they're reported.

  • I have updated gptel to the latest commit and tested that the issue still exists

Bug Description

During the execution of gptel-rewrite, gptel--rewrite-directive-default is invoked twice. The first time is in the source buffer (i.e. the buffer from which gptel-rewrite is invoked) and the second from some sort of transient buffer, always named "gptel-prompt-nnnnn". The assumption, I guess, is that both invocations will return the same value, but that is not always true (see the example, below). When the two invocations return different values, it is misleading to the user (since a different system prompt is being silently sent).

Backend

None

Steps to Reproduce

Write a little advice to customize the system prompt when working in a particular project:

(defun sp1ff//gptel/first-rewrite-directive (orig-fun &rest args)
  (message "My advice is being invoked in %s, bfn returns %s, and major-mode is %s." (buffer-name) (buffer-file-name) major-mode)
  (let ((bfn (buffer-file-name)))
    (if (and (eq 'rust-mode major-mode) bfn (string-match "mpdpopm" bfn 0 t))
        ;; "Overall, our findings suggest that while adding a persona may lead to
        ;; performance gains in certain settings, the effect of each persona can
        ;; be largely random." --https://arxiv.org/abs/2311.10054
        (concat "Follow the user instructions in refactoring the provided Rust source code.\n"
                "- Generate ONLY Rust code as output, without any explanation or markdown code fences.\n"
                "- Generate code in full, do not abbreviate or omit code.")
      (message "I am deferring to the default implementation #'gptel--rewrite-directive-default'")
      (apply orig-fun args))))

then advise:

(advice-add 'gptel--rewrite-directive-default' :around #'sp1ff//gptel/first-rewrite-directive)

Additional Context

Emacs compiled from source, Arch Linux.

Backtrace

Log Information

My advice is being invoked in messages.rs, bfn returns /home/mgh/code/projects/mpdpopm/mpdpopm/src/messages.rs, and major-mode is rust-mode.
...
My advice is being invoked in  *gptel-prompt*-375581, bfn returns nil, and major-mode is rust-mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions