rksm / org-ai

Emacs as your personal AI assistant. Use LLMs such as ChatGPT or LLaMA for text generation or DALL-E and Stable Diffusion for image generation. Also supports speech input / output.
GNU General Public License v3.0
660 stars 52 forks source link

The contents-end property appears non-existing when inserting image below ai block #64

Closed okomestudio closed 4 months ago

okomestudio commented 1 year ago

When I try the image generation example in README:

#+begin_ai :image :size 256x256
Hyper realistic sci-fi rendering of super complicated technical machine.
#+end_ai

C-c C-c does generate the image file in local disk.

Contacting host: api.openai.com:443
saved /home/taro/Downloads/org-ai/20230717_256x256_image_4.png
Entering debugger...

However, image rendering below the ai block consistently fails with wrong-type-argument integer-or-marker-p nil which appears to be caused by the contents-end property missing from the output of org-ai-special-block function:

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  goto-char(nil)
  (let ((name (plist-get (car (cdr (org-ai-special-block))) :name)) (contents-end (plist-get (car (cdr (org-ai-special-block))) :contents-end))) (goto-char contents-end) (forward-line) (if name (progn (insert (format "#+NAME: %s%s\n" name (if (> n 0) (format "_%s" i) ""))))) (insert (format "[[file:%s]]\n" file)) (org-display-inline-images))
  ...

Here, goto-char(nil) because :contents-end returns nil.

When I invoke org-ai-special-block within the ai block in the Org file, I confirm that :contents-end is not available:

(special-block (:standard-properties [179 295 211 284 2 179 nil nil nil nil nil planning ...] :type "ai" :parameters ":image :size 256x256"))

I see no similar issue reported prior. What could cause :contents-end to be unavailable?

(The only thing I could think of that could be different from the standard Emacs setting is that I'm running it on Wayland via pgtk. I'm not sure that matters at all.)

rksm commented 1 year ago

Good question but it seems similar to #67 and #69, for some reason org-elements don't have the expected org-element--standard-properties. Can you run M-x org-version and report the result? Thank you!

okomestudio commented 1 year ago

The results of org-version:

Org mode version 9.7-pre (release_9.6.7-606-g63e8ca @ /home/taro/.config/emacs/straight/build/org/)

It's at the head of the main branch. When I created this PR, org-mode was pinned to a commit about a month old (7c6302e2034916ed38f1c61dd0806f48e6f8a21c) from the current head (63e8cac2cadd77896d67890d36f3d59b60b13f74). But I see the same behavior now and then. Emacs version is at 29.1.

rksm commented 1 year ago

Got it, thank you. I'll do some testing.