branch: externals/llm
commit a16338f31a44ea6154ed0260d299a9b0ba66ab89
Author: Andrew Hyatt <[email protected]>
Commit: Andrew Hyatt <[email protected]>
Add streaming to llm-fake
---
llm-fake.el | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/llm-fake.el b/llm-fake.el
index 9ffdcdd936..5b3901bd38 100644
--- a/llm-fake.el
+++ b/llm-fake.el
@@ -66,6 +66,26 @@ message cons. If nil, the response will be a simple vector."
(_ (error "Incorrect type found in `chat-action-func': %s"
(type-of result)))))
"Sample response from `llm-chat-async'"))
+(cl-defmethod llm-chat-streaming ((provider llm-fake) prompt partial-callback
response-callback _error-callback)
+ (when (llm-fake-output-to-buffer provider)
+ (with-current-buffer (get-buffer-create (llm-fake-output-to-buffer
provider))
+ (goto-char (point-max))
+ (insert "\nCall to llm-chat-streaming\n" (llm-chat-prompt-to-text
prompt) "\n")))
+ (let ((text "Sample response from `llm-chat-streaming'"))
+ (when (llm-fake-chat-action-func provider)
+ (let* ((f (llm-fake-chat-action-func provider))
+ (result (funcall f)))
+ (pcase (type-of result)
+ ('string (setq text result))
+ ('cons (signal (car result) (cdr result)))
+ (_ (error "Incorrect type found in `chat-action-func': %s" (type-of
result))))))
+ (let ((accum ""))
+ (mapc (lambda (word)
+ (setq accum (concat accum word " "))
+ (funcall partial-callback accum))
+ (string-split text))
+ (funcall response-callback text))))
+
(cl-defmethod llm-embedding ((provider llm-fake) string)
(when (llm-fake-output-to-buffer provider)
(with-current-buffer (get-buffer-create (llm-fake-output-to-buffer
provider))