branch: externals/llm commit 7b2c89f087d50468c181449b483e6f31a3025fdf Author: Roman Scherer <ro...@burningswell.com> Commit: Roman Scherer <ro...@burningswell.com>
Remove invalid media type usage and on-success-raw callback --- llm-gemini.el | 2 -- llm-ollama.el | 2 -- llm-openai.el | 2 -- llm-request-plz.el | 36 +++++++++++------------------------- llm-vertex.el | 2 -- 5 files changed, 11 insertions(+), 33 deletions(-) diff --git a/llm-gemini.el b/llm-gemini.el index 436d4454b9..7e86b3b112 100644 --- a/llm-gemini.el +++ b/llm-gemini.el @@ -65,7 +65,6 @@ You can get this at https://makersuite.google.com/app/apikey." (let ((buf (current-buffer))) (llm-request-plz-async (llm-gemini--embedding-url provider) :data (llm-gemini--embedding-request provider string) - :media-type '(application/json) :on-success (lambda (data) (llm-request-callback-in-buffer buf vector-callback (llm-gemini--embedding-response-handler data))) @@ -112,7 +111,6 @@ If STREAMING-P is non-nil, use the streaming endpoint." (let ((buf (current-buffer))) (llm-request-plz-async (llm-gemini--chat-url provider nil) :data (llm-gemini--chat-request prompt) - :media-type '(application/json) :on-success (lambda (data) (llm-request-callback-in-buffer buf response-callback diff --git a/llm-ollama.el b/llm-ollama.el index e36701ff25..b8409f5632 100644 --- a/llm-ollama.el +++ b/llm-ollama.el @@ -86,7 +86,6 @@ PROVIDER is the llm-ollama provider." (let ((buf (current-buffer))) (llm-request-plz-async (llm-ollama--url provider "embeddings") :data (llm-ollama--embedding-request provider string) - :media-type '(application/json) :on-success (lambda (data) (llm-request-callback-in-buffer buf vector-callback (llm-ollama--embedding-extract-response data))) @@ -148,7 +147,6 @@ STREAMING is a boolean to control whether to stream the response." (llm-request-plz-async (llm-ollama--url provider "chat") :data (llm-ollama--chat-request provider prompt nil) - :media-type '(application/json) :timeout llm-ollama-chat-timeout :on-success (lambda (data) (let ((output (llm-ollama--get-response data))) diff --git a/llm-openai.el b/llm-openai.el index 28396ce045..e444824262 100644 --- a/llm-openai.el +++ b/llm-openai.el @@ -116,7 +116,6 @@ This is just the key, if it exists." (llm-openai--check-key provider) (let ((buf (current-buffer))) (llm-request-plz-async (llm-openai--url provider "embeddings") - :media-type '(application/json) :headers (llm-openai--headers provider) :data (llm-openai--embedding-request (llm-openai-embedding-model provider) string) :on-success (lambda (data) @@ -229,7 +228,6 @@ PROMPT is the prompt that needs to be updated with the response." (let ((buf (current-buffer))) (llm-request-plz-async (llm-openai--url provider "chat/completions") - :media-type '(application/json) :headers (llm-openai--headers provider) :data (llm-openai--chat-request (llm-openai-chat-model provider) prompt) :on-success (lambda (data) diff --git a/llm-request-plz.el b/llm-request-plz.el index a9cf9f63e9..f5566a037e 100644 --- a/llm-request-plz.el +++ b/llm-request-plz.el @@ -113,7 +113,7 @@ the curl process and an error message." (cdr curl-error)))) (t (user-error "Unexpected error: %s" error)))) -(cl-defun llm-request-plz-async (url &key headers data on-success on-success-raw media-type +(cl-defun llm-request-plz-async (url &key headers data on-success media-type on-error timeout) "Make a request to URL. Nothing will be returned. @@ -131,30 +131,21 @@ and required otherwise. ON-ERROR will be called with the error code and a response-body. This is required. -MEDIA-TYPE is a required argument that sets a media type, useful -for streaming formats. It is expected that this is only used by -other methods in this file. - -ON-SUCCESS-RAW, if set, will be called in the buffer with the -response body, and expect the response content. This is an -optional argument, and mostly useful for streaming. If not set, -the buffer is turned into JSON and passed to ON-SUCCESS." - (unless media-type - (error "MEDIA-TYPE is required in llm-request-plz-async")) +MEDIA-TYPE is an optional argument that adds or overrides a media +type, useful for streaming formats. It is expected that this is +only used by other methods in this file." (plz-media-type-request 'post url - :as `(media-types ,(cons media-type plz-media-types)) + :as `(media-types ,(if media-type + (cons media-type plz-media-types) + plz-media-types)) :body (when data (encode-coding-string (json-encode data) 'utf-8)) :headers (append headers '(("Content-Type" . "application/json"))) :then (lambda (response) - (let ((response (plz-response-body response))) - (when on-success-raw - (funcall on-success-raw response)) - (when on-success - (funcall on-success (when (and response (> (length response) 0)) - (json-read-from-string response)))))) + (when on-success + (funcall on-success (plz-response-body response)))) :else (lambda (error) (when on-error (llm-request-plz--handle-error error on-error))) @@ -184,9 +175,7 @@ This is required. :headers headers :data data :on-error on-error - ;; Have to use :on-success-raw because :on-success will try to - ;; convert to JSON, and this already should be JSON. - :on-success-raw on-success + :on-success on-success :timeout timeout :media-type (cons 'application/json @@ -216,10 +205,7 @@ This is required. :headers headers :data data :on-error on-error - ;; Have to use :on-success-raw because :on-success will try to - ;; convert to JSON, and this already should be JSON. - :on-success-raw (lambda (resp) - (funcall on-success (plz-response-body resp))) + :on-success on-success :timeout timeout :media-type (cons 'application/x-ndjson diff --git a/llm-vertex.el b/llm-vertex.el index dbe33a9c66..3ee7083f0e 100644 --- a/llm-vertex.el +++ b/llm-vertex.el @@ -130,7 +130,6 @@ KEY-GENTIME keeps track of when the key was generated, because the key must be r (llm-vertex--embedding-url provider) :headers `(("Authorization" . ,(format "Bearer %s" (llm-vertex-key provider)))) :data `(("instances" . [(("content" . ,string))])) - :media-type '(application/json) :on-success (lambda (data) (llm-request-callback-in-buffer buf vector-callback (llm-vertex--embedding-extract-response data))) @@ -302,7 +301,6 @@ If STREAMING is non-nil, use the URL for the streaming API." (llm-vertex--chat-url provider) :headers `(("Authorization" . ,(format "Bearer %s" (llm-vertex-key provider)))) :data (llm-vertex--chat-request prompt) - :media-type '(application/json) :on-success (lambda (data) (llm-request-callback-in-buffer buf response-callback