branch: externals/llm
commit 6d695da83faed84bf4eb34e225d586dd97647b89
Author: Andrew Hyatt <ahy...@gmail.com>
Commit: GitHub <nore...@github.com>

    Test properly for prompt functions, including compiled functions (#58)
    
    * Also consider compiled functions as well as functions
    
    * Just use functionp, which is simpler and correct
    
    * Add NEWS entry
    
    * Lists are also not simple variables
---
 NEWS.org           | 4 +++-
 llm-prompt-test.el | 7 +++++++
 llm-prompt.el      | 8 +++++---
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index 75a5153d06..17d82b533e 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,4 +1,6 @@
-* Verseion 0.17.1
+* Version 0.17.2
+- Fix compiled functions not being evaluated in =llm-prompt=.
+* Version 0.17.1
 - Support Ollama function calling, for models which support it.
 - Make sure every model, even unknown models, return some value for 
~llm-chat-token-limit~.
 - Add token count for llama3.1 model.
diff --git a/llm-prompt-test.el b/llm-prompt-test.el
index b4308118e3..535946e880 100644
--- a/llm-prompt-test.el
+++ b/llm-prompt-test.el
@@ -154,6 +154,13 @@ to converge."
       (should (member 'a var2))
       (should (= 5 (+ (length var1) (length var2)))))))
 
+(ert-deftest llm-prompt-fill-with-compiled-function ()
+  (should (equal
+           (llm-prompt-fill-text "({{var1}})"
+                                 (make-prompt-test-llm)
+                                 :var1 (byte-compile (iter-lambda () 
(iter-yield 'a))))
+           "(a)")))
+
 (ert-deftest llm-prompt-fill-size-limit-after-initial-fill ()
   ;; After filling the intial var1 from a string, we don't have enough tokens 
to
   ;; do any more filling.
diff --git a/llm-prompt.el b/llm-prompt.el
index ced4cbf56e..cd66673022 100644
--- a/llm-prompt.el
+++ b/llm-prompt.el
@@ -120,9 +120,11 @@ Return an alist of variables to their corresponding 
markers."
     (nreverse results)))
 
 (defun llm-prompt--simple-var-p (var)
-  "Return t if VAR is a simple variable, not a possible function."
-  (and (not (eq (type-of var) 'function))
-       (not (eq (type-of var) 'cons))))
+  "Return t if VAR is a simple variable, not a possible function.
+
+Lists will be turned into generators, so they are not simple variables."
+  (and (not (functionp var))
+       (not (listp var))))
 
 (iter-defun llm-prompt--select-tickets (vars)
   "Return generator that select tickets and calls generators in VARS.

Reply via email to