karthink / gptel

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

Wrong language in the source block header #303

Open jagrg opened 1 month ago

jagrg commented 1 month ago

Gptel returns #+begin_src javascript when it should be #+begin_src js. Any suggestion on how to fix this?

karthink commented 1 month ago

The LLM is sending this string:

```javascript
some code

So gptel shows `#+begin_src javascript`.  This is working as intended.

If you anticipate this problem, you can use gptel's post-response hook to replace it afterwards.  Untested:
```emacs-lisp
(defun gptel-fix-src-header (beg end)
  (save-excursion
    (goto-char beg)
    (while (re-search-forward "^#\\+begin_src javascript" end t)
      (replace-match "#+begin_src js"))))

(add-hook 'gptel-post-response-functions #'gptel-fix-src-header)
jagrg commented 1 month ago

It works, but since javascript is not a valid babel language (as opposed to js), perhaps the problem should be addressed internally, WDYT?

karthink commented 1 month ago

I need to make the markdown -> org pipeline user-customizable first. Then gptel can provide some utility functions for mini-fixes like this without having to resort to the post-response hook, which is a bit of a bludgeon. This is a low priority for now.

Do you know where I can find the list of babel names for languages?

jagrg commented 1 month ago

Should be all the ob-*.el files in https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp