branch: externals/llm
commit cdfe8c6255e119d86dd842ee1543bc347866fa2f
Author: Andrew Hyatt <ahy...@gmail.com>
Commit: Andrew Hyatt <ahy...@gmail.com>

    Add Claude & Gemini nonfree warnings, and refactor nonfree method
---
 NEWS.org      |  3 +++
 llm-claude.el |  3 +++
 llm-gemini.el |  3 +++
 llm-openai.el |  9 ++++-----
 llm-vertex.el |  5 ++---
 llm.el        | 13 ++++++-------
 6 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index 7c9ba3d5b4..51fe77d2ca 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,3 +1,6 @@
+* Verson 0.12.4
+- Refactor of warn-non-nonfree methods.
+- Add non-free warnings for Gemini and Claude.
 * Version 0.12.3
 - Enable customization of error message handling for Open AI compatible 
providers, via =llm-openai--error-message=.
 * Version 0.12.2
diff --git a/llm-claude.el b/llm-claude.el
index 15a50484de..47ecee046b 100644
--- a/llm-claude.el
+++ b/llm-claude.el
@@ -35,6 +35,9 @@
   (key nil :read-only t)
   (chat-model "claude-3-opus-20240229" :read-only t))
 
+(cl-defmethod llm-nonfree-message-info ((_ llm-claude))
+  "https://www.anthropic.com/legal/consumer-terms";)
+
 (defun llm-claude-check-key (provider)
   "Check if the API key is valid, error if not."
   (unless (llm-claude-key provider)
diff --git a/llm-gemini.el b/llm-gemini.el
index 444528159e..248976d753 100644
--- a/llm-gemini.el
+++ b/llm-gemini.el
@@ -40,6 +40,9 @@ KEY is the API key for the client.
 You can get this at https://makersuite.google.com/app/apikey.";
   key (embedding-model "embedding-001") (chat-model "gemini-pro"))
 
+(cl-defmethod llm-nonfree-message-info ((_ llm-gemini))
+  "https://policies.google.com/terms/generative-ai";)
+
 (defun llm-gemini--embedding-url (provider)
   "Return the URL for the EMBEDDING request for STRING from PROVIDER."
   (format 
"https://generativelanguage.googleapis.com/v1beta/models/%s:embedContent?key=%s";
diff --git a/llm-openai.el b/llm-openai.el
index 62ea5e2dcd..1dda155a01 100644
--- a/llm-openai.el
+++ b/llm-openai.el
@@ -61,9 +61,8 @@ https://api.example.com/v1/chat, then URL should be
 \"https://api.example.com/v1/\".";
   url)
 
-(cl-defmethod llm-nonfree-message-info ((provider llm-openai))
-  (ignore provider)
-  (cons "Open AI" "https://openai.com/policies/terms-of-use";))
+(cl-defmethod llm-nonfree-message-info ((_ llm-openai))
+  "https://openai.com/policies/terms-of-use";)
 
 (defun llm-openai--embedding-request (model string)
   "Return the request to the server for the embedding of STRING.
@@ -133,7 +132,7 @@ If ERR-RESPONSE is not an error, return nil.")
                        :on-error (lambda (_ data) 
                                    (llm-request-callback-in-buffer
                                     buf error-callback 'error
-                                    (llm-openai--error-message data))))))
+                                    (llm-openai--error-message provider 
data))))))
 
 (cl-defmethod llm-embedding ((provider llm-openai) string)
   (llm-openai--check-key provider)
@@ -219,7 +218,7 @@ This function adds the response to the prompt, executes any
 functions, and returns the value that the client should get back.
 
 PROMPT is the prompt that needs to be updated with the response."
-  (if-let ((err-msg (llm-openai--error-message response)))
+  (if-let ((err-msg (llm-openai--error-message provider response)))
       (progn
         (when error-callback
           (funcall error-callback 'error err-msg))
diff --git a/llm-vertex.el b/llm-vertex.el
index 8c9d6c0575..74e08c9a4f 100644
--- a/llm-vertex.el
+++ b/llm-vertex.el
@@ -94,9 +94,8 @@ KEY-GENTIME keeps track of when the key was generated, 
because the key must be r
       (setf (llm-vertex-key provider) (encode-coding-string result 'utf-8)))
     (setf (llm-vertex-key-gentime provider) (current-time))))
 
-(cl-defmethod llm-nonfree-message-info ((provider llm-vertex))
-  (ignore provider)
-  (cons "Google Cloud Vertex" 
"https://policies.google.com/terms/generative-ai";))
+(cl-defmethod llm-nonfree-message-info ((_ llm-vertex))
+  "https://policies.google.com/terms/generative-ai";)
 
 (defun llm-vertex--embedding-url (provider)
   "From the PROVIDER, return the URL to use for embeddings"
diff --git a/llm.el b/llm.el
index 722de36b58..b91457b9e5 100644
--- a/llm.el
+++ b/llm.el
@@ -207,8 +207,7 @@ ROLE default to `user', which should almost always be what 
is needed."
 
 (cl-defgeneric llm-nonfree-message-info (provider)
   "If PROVIDER is non-free, return info for a warning.
-This should be a cons of the name of the LLM, and the URL of the
-terms of service.
+This should be the string URL of the terms of service.
 
 If the LLM is free and has no restrictions on use, this should
 return nil.  Since this function already returns nil, there is no
@@ -237,7 +236,7 @@ conversation so far."
 (cl-defmethod llm-chat :before (provider _)
   "Issue a warning if the LLM is non-free."
   (when-let (info (llm-nonfree-message-info provider))
-    (llm--warn-on-nonfree (car info) (cdr info))))
+    (llm--warn-on-nonfree (llm-name provider) info)))
 
 (cl-defmethod llm-chat :around (provider prompt)
   "Log the input to llm-chat."
@@ -342,7 +341,7 @@ be passed to `llm-cancel-request'."
 (cl-defmethod llm-chat-streaming :before (provider _ _ _ _)
   "Issue a warning if the LLM is non-free."
   (when-let (info (llm-nonfree-message-info provider))
-    (llm--warn-on-nonfree (car info) (cdr info))))
+    (llm--warn-on-nonfree (llm-name provider) info)))
 
 (cl-defmethod llm-chat-streaming :around (provider prompt partial-callback 
response-callback error-callback)
   "Log the input to llm-chat-async."
@@ -402,7 +401,7 @@ be passed to `llm-cancel-request'."
 (cl-defmethod llm-chat-async :before (provider _ _ _)
   "Issue a warning if the LLM is non-free."
   (when-let (info (llm-nonfree-message-info provider))
-    (llm--warn-on-nonfree (car info) (cdr info))))
+    (llm--warn-on-nonfree (llm-name provider) info)))
 
 (cl-defgeneric llm-capabilities (provider)
   "Return a list of the capabilities of PROVIDER.
@@ -443,7 +442,7 @@ value that should be a reasonable lower bound."
 (cl-defmethod llm-embedding :before (provider _)
   "Issue a warning if the LLM is non-free."
   (when-let (info (llm-nonfree-message-info provider))
-    (llm--warn-on-nonfree (car info) (cdr info))))
+    (llm--warn-on-nonfree (llm-name provider) info)))
 
 (cl-defgeneric llm-embedding-async (provider string vector-callback 
error-callback)
   "Calculate a vector embedding of STRING from PROVIDER.
@@ -463,7 +462,7 @@ be passed to `llm-cancel-request'."
 (cl-defmethod llm-embedding-async :before (provider _ _ _)
   "Issue a warning if the LLM is non-free."
   (when-let (info (llm-nonfree-message-info provider))
-    (llm--warn-on-nonfree (car info) (cdr info))))
+    (llm--warn-on-nonfree (llm-name provider) info)))
 
 (cl-defgeneric llm-count-tokens (provider string)
   "Return the number of tokens in STRING from PROVIDER.

Reply via email to