karthink / gptel

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

Feature request: obey "#+INCLUDE" directive #325

Open julian-hoch opened 3 weeks ago

julian-hoch commented 3 weeks ago

The INCLUDE directive in Org Mode is typically used when exporting to other formats. I think it would be only natural to respect this when exporting to an LLM, so I am wondering if this could be implemented (e.g. when including separate files, the content of these files could (optionally?) be sent with the request to the LLM).

karthink commented 3 weeks ago

Sending text to an LLM is not an Org export process, in that ox is not involved in any way. So it doesn't make sense to expand INCLUDE directives.

Adding support for this will mean adding support for all export features, like <noweb> expansions, org macros, Org ToCs and so on, which is going to be very buggy.

If you want LLM interaction to work like this you can export the buffer to Org (with C-c C-e O O, provided by ox-org) and send that instead. This way all the export affordances will be respected. You can write a little function (gptel-export-and-send) to automate this.

julian-hoch commented 2 weeks ago

Thanks, that sounds like a fantastic idea! I will try this. Unfortunately, org-org-export is broken for me, but the plaintext export should work as an OK replacement for now. However, I could not find out how to instruct gptel-send to store the result in the kill ring or the original buffer. Is that not a possibility? Otherwise I would have to copy&paste the result from the created temporary buffer, which seems a bit awkward.

karthink commented 2 weeks ago

However, I could not find out how to instruct gptel-send to store the result in the kill ring or the original buffer. Is that not a possibility?

  1. Export using ox-org or to a plain text buffer
  2. Move point as required, or select a region
  3. Call gptel-send with a prefix arg.
  4. In the transient menu, choose to redirect the result to the kill-ring or (even better) to the original org buffer.
  5. Send the query.
julian-hoch commented 2 weeks ago

Ah yeah, interactively that works of course. But I want to be able to script it so it can work transparently in the background on the press of a button. But perhaps that might be possible then using the gptel-request function.

karthink commented 2 weeks ago

Yes, you can automate steps 1-5 above with a helper command (gptel-export-and-send). This is best done with gptel-request, as you suggest.