diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-ellama-transient.el | 23 | ||||
| -rw-r--r-- | tests/test-ellama.el | 42 |
2 files changed, 63 insertions, 2 deletions
diff --git a/tests/test-ellama-transient.el b/tests/test-ellama-transient.el index 96eb88a..81950a6 100644 --- a/tests/test-ellama-transient.el +++ b/tests/test-ellama-transient.el @@ -99,17 +99,36 @@ (ert-deftest test-ellama-transient-reset-model-fields-and-descriptions () (let ((ellama-transient-model-name "model") (ellama-transient-temperature 0.4) - (ellama-transient-context-length 8192)) + (ellama-transient-context-length 8192) + (ellama-max-tokens 256)) (ellama-transient-reset-model-fields) (should-not ellama-transient-model-name) (should-not ellama-transient-temperature) (should-not ellama-transient-context-length) + (should-not ellama-max-tokens) (should (equal (ellama-transient-model-description) "Model (default)")) (should (equal (ellama-transient-temperature-description) "Temperature (default)")) (should (equal (ellama-transient-context-length-description) - "Context Length (default)")))) + "Context Length (default)")) + (should (equal (ellama-transient-max-tokens-description) + "Max Tokens (default)")))) + +(ert-deftest test-ellama-transient-set-max-tokens () + (let ((ellama-max-tokens nil)) + (cl-letf (((symbol-function 'read-string) + (lambda (&rest _args) + "42"))) + (ellama-transient-set-max-tokens) + (should (= ellama-max-tokens 42)) + (should (equal (ellama-transient-max-tokens-description) + "Max Tokens (42)"))) + (cl-letf (((symbol-function 'read-string) + (lambda (&rest _args) + ""))) + (ellama-transient-set-max-tokens) + (should-not ellama-max-tokens)))) (ert-deftest test-ellama-transient-set-model-keeps-reset-temperature () (let ((ellama-transient-provider :provider) diff --git a/tests/test-ellama.el b/tests/test-ellama.el index e6f9c72..583ec90 100644 --- a/tests/test-ellama.el +++ b/tests/test-ellama.el @@ -831,6 +831,48 @@ detailed comparison to help you decide: (when buf (kill-buffer buf)))))) +(ert-deftest test-ellama-stream-uses-max-tokens () + (let* ((provider (make-llm-fake)) + (ellama-provider provider) + (ellama-max-tokens 7) + (ellama-response-process-method 'streaming) + (ellama-spinner-enabled nil) + (ellama-fill-paragraphs nil) + captured-prompt + done-text) + (cl-letf (((symbol-function 'llm-chat-streaming) + (lambda (_provider prompt _partial-callback response-callback + _error-callback &optional _multi-output) + (setq captured-prompt prompt) + (funcall response-callback '(:text "ok")) + nil))) + (with-temp-buffer + (ellama-stream "test prompt" + :provider provider + :on-done (lambda (text) (setq done-text text))))) + (should (equal done-text "ok")) + (should (= (llm-chat-prompt-max-tokens captured-prompt) 7)))) + +(ert-deftest test-ellama-stream-max-tokens-argument-overrides-default () + (let* ((provider (make-llm-fake)) + (ellama-provider provider) + (ellama-max-tokens 7) + (ellama-response-process-method 'streaming) + (ellama-spinner-enabled nil) + (ellama-fill-paragraphs nil) + captured-prompt) + (cl-letf (((symbol-function 'llm-chat-streaming) + (lambda (_provider prompt _partial-callback response-callback + _error-callback &optional _multi-output) + (setq captured-prompt prompt) + (funcall response-callback '(:text "ok")) + nil))) + (with-temp-buffer + (ellama-stream "test prompt" + :provider provider + :max-tokens 2))) + (should (= (llm-chat-prompt-max-tokens captured-prompt) 2)))) + (ert-deftest test-ellama-stream-defaults-to-current-buffer-with-active-session () (let* ((ellama-provider (make-llm-fake |
