karthink / gptel

A simple LLM client for Emacs
GNU General Public License v3.0
1.04k stars 113 forks source link

formatting issue in org blocks (Mixtral models) #200

Closed akhil3417 closed 5 months ago

akhil3417 commented 5 months ago

renamed the org file to .md since github doesn't support it potential_bug.md #+begin\_src assembly

related to 10f5760

karthink commented 5 months ago

renamed the org file to .md since github doesn't support it bug.md #+begin\_src assembly

Is this with or without streaming responses?

akhil3417 commented 5 months ago

Is this with or without streaming responses?

with streaming responses , also the first source block is always correct.

karthink commented 5 months ago

I was able to reproduce this with the mistralai/Mixtral-8x7B-Instruct-v0.1 model (and only that model). Unfortunately this is a quirk of the LLM and not something I can fix comprehensively.

When it's sent the previous response (in Org-mode), it switches to trying to use Org mode, and does a terrible job of it. The \_ in #+begin\_src (and elsewhere) is returned exactly like this from the model.

I can think of two semi-solutions:

  1. In the system prompt, add that you only want responses in markdown. This worked most of the time when I tested it.
  2. Add a post-response hook to manually fix this issue:
(defun my/gptel-fix-mistral-org-response (beg end)
  "Fix org responses from LLM"
  (when (and (equal gptel-model "mistralai/Mixtral-8x7B-Instruct-v0.1")
             (derived-mode-p 'org-mode))
    (save-excursion
      (goto-char beg)
      (while (search-forward "\\_" end t)
        (replace-match "_")))
    (font-lock-ensure beg end)))

(add-hook 'gptel-post-response-functions #'my/gptel-fix-mistral-org-response)

Modify as appropriate.

akhil3417 commented 5 months ago