[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/llm 0ed280c208 15/34: Add llm-fake, useful for develope
From: |
Andrew Hyatt |
Subject: |
[elpa] externals/llm 0ed280c208 15/34: Add llm-fake, useful for developer testing using the llm methods |
Date: |
Sat, 16 Sep 2023 01:32:48 -0400 (EDT) |
branch: externals/llm
commit 0ed280c208efee3124eaf022accf47d493036de7
Author: Andrew Hyatt <ahyatt@gmail.com>
Commit: Andrew Hyatt <ahyatt@gmail.com>
Add llm-fake, useful for developer testing using the llm methods
---
llm-fake.el | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/llm-fake.el b/llm-fake.el
new file mode 100644
index 0000000000..f74f868c1f
--- /dev/null
+++ b/llm-fake.el
@@ -0,0 +1,75 @@
+;;; llm-fake.el --- Use for developers looking at llm calls. -*-
lexical-binding: t -*-
+
+;; Copyright (c) 2023 Andrew Hyatt <ahyatt@gmail.com>
+
+;; Author: Andrew Hyatt <ahyatt@gmail.com>
+;; Homepage: https://github.com/ahyatt/llm
+;; SPDX-License-Identifier: GPL-3.0-or-later
+;;
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 3 of the
+;; License, or (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;; This file implements the llm functionality defined in llm.el, for developers
+;; who want to just understand what llm calls are made, and with what data. Or,
+;; to test out various functionality they have. The functions return something,
+;; or throw errors, depending on how the `llm-fake' provider is configured.
+
+(require 'cl-lib)
+(require 'llm)
+
+;;; Code:
+
+(cl-defstruct llm-fake
+ "A provider for the fake LLM provider.
+
+OUTPUT-TO-BUFFER can be nil, in which case, nothing will be
+output. If a string or a buffer, it will append the request as
+text to that buffer.
+
+CHAT-ACTION-FUNC will be called with no arguments to produce
+either a string response for the chat, or a signal symbol and
+message cons. If nil, the response will be a short text string.
+
+EMBEDDING-ACTION-FUNC will be called with no arguments to produce
+either a vector response for the chat, or a signal symbol and
+message cons. If nil, the response will be a simple vector."
+ output-to-buffer chat-action-func embedding-action-func)
+
+(cl-defmethod llm-chat-response-async ((provider llm-fake) prompt
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-response\n" (llm-chat-prompt-to-text
prompt) "\n")))
+ (or (when-let (f (llm-fake-chat-action-func provider))
+ (let ((result (funcall f)))
+ (pcase (type-of result)
+ ('string (funcall response-callback result))
+ ('cons (funcall error-callback (car result) (cdr result)))
+ (_ (error "Incorrect type found in `chat-action-func': %s"
(type-of-result))))))
+ (funcall response-callback "Sample response from
`llm-chat-response-async'")))
+
+(cl-defmethod llm-embedding-async ((provider llm-openai) string
vector-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-embedding with text: " string "\n")))
+ (or (when-let (f (llm-fake-chat-action-func provider))
+ (let ((result (funcall f)))
+ (pcase (type-of result)
+ ('vector (funcall vector-callback result))
+ ('cons (funcall error-callback (car result) (cdr result)))
+ (_ (error "Incorrect type found in `chat-embedding-func': %s"
(type-of-result))))))
+ (funcall response-callback [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9])))
+
+(provide 'llm-fake)
- [elpa] externals/llm 16ee85fd11 05/34: Add async options, and made the sync options just use those and wait, (continued)
- [elpa] externals/llm 16ee85fd11 05/34: Add async options, and made the sync options just use those and wait, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm 3919b77383 06/34: Implement confusion and typos in README.org, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm b52958757a 18/34: Fix docstring wider than 80 characters in llm-vertex, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm abbff2aa9d 23/34: Change method name to llm-chat (without "-response"), update README, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm e94bc937c7 27/34: Fix issue with llm-chat before method having too many arguments, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm 7edd36b2dc 28/34: Fix obsolete or incorrect function calls in llm-fake, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm d4bbe9d84c 29/34: Fix incorrect requires in openai and vertex implementations, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm 723c0b3786 31/34: Minor README whitespace and formatting fixes, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm 8f30feb5c1 32/34: README improvements, including noting the nonfree llm warning, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm 444850a981 24/34: Fix missing word in non-free warning message, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm 0ed280c208 15/34: Add llm-fake, useful for developer testing using the llm methods,
Andrew Hyatt <=
- [elpa] externals/llm c55ccf157a 03/34: Clean up package specifications in elisp files, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm 414d25a625 09/34: Removed various unused things, and format fixes, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm 4e9be8183d 07/34: Merge branch 'async', Andrew Hyatt, 2023/09/16
- [elpa] externals/llm dd20d6353c 21/34: Fix bug on llm-fake's error response to chat-response, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm 40151757de 26/34: Switch to a method of nonfree warnings easier for provider modules, Andrew Hyatt, 2023/09/16
- [elpa] externals/llm ba65755326 30/34: Improve the README with information on providers for end-users, Andrew Hyatt, 2023/09/16