[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/llm 623bceda67 29/71: Fix issue with JSON array parser
From: |
ELPA Syncer |
Subject: |
[elpa] externals/llm 623bceda67 29/71: Fix issue with JSON array parser nor emitting all objects |
Date: |
Fri, 17 May 2024 00:58:46 -0400 (EDT) |
branch: externals/llm
commit 623bceda67c67f3d2e9af09f5f15e2058faaeb27
Author: Roman Scherer <roman@burningswell.com>
Commit: Roman Scherer <roman@burningswell.com>
Fix issue with JSON array parser nor emitting all objects
---
plz-media-type.el | 55 ++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 36 insertions(+), 19 deletions(-)
diff --git a/plz-media-type.el b/plz-media-type.el
index f8094c057e..a273097e80 100644
--- a/plz-media-type.el
+++ b/plz-media-type.el
@@ -246,17 +246,33 @@ be `hash-table', `alist' (the default) or `plist'."
(defun plz-media-type:application/json-array--parse-next (media-type)
"Parse a single line of the newline delimited JSON MEDIA-TYPE."
- (cond ((looking-at "\\[")
- (delete-char 1))
- ((looking-at "[ ,\n\r]")
- (delete-char 1))
- ((looking-at "\\]")
- (delete-char 1))
- ((not (eobp))
- (ignore-errors
- (let ((begin (point)))
- (prog1 (plz-media-type--parse-json-object media-type)
- (delete-region begin (point))))))))
+ (let ((begin (point)))
+ (cond ((looking-at "\\[")
+ (forward-char 1)
+ (cons :array-start (buffer-substring begin (point))))
+ ((looking-at ",")
+ (forward-char 1)
+ (cons :comma (buffer-substring begin (point))))
+ ((looking-at "\n")
+ (forward-char 1)
+ (cons :line-feed (buffer-substring begin (point))))
+ ((looking-at "\r")
+ (forward-char 1)
+ (cons :carriage-return (buffer-substring begin (point))))
+ ((looking-at "\\]")
+ (forward-char 1)
+ (cons :array-end (buffer-substring begin (point))))
+ ((not (eobp))
+ (condition-case nil
+ (cons :array-element (plz-media-type--parse-json-object
media-type))
+ (json-error))))))
+
+(defun plz-media-type:application/json-array--consume-next (media-type)
+ "Parse a single line of the newline delimited JSON MEDIA-TYPE."
+ (let ((begin (point)))
+ (prog1 (plz-media-type:application/json-array--parse-next media-type)
+ (delete-region begin (point))
+ (setq-local plz-media-type--position (point)))))
(defun plz-media-type:application/json-array--parse-stream (media-type)
"Parse all lines of the newline delimited JSON MEDIA-TYPE in the PROCESS
buffer."
@@ -264,24 +280,25 @@ be `hash-table', `alist' (the default) or `plist'."
(unless plz-media-type--position
(setq-local plz-media-type--position (point)))
(goto-char plz-media-type--position)
- (let ((object (plz-media-type:application/json-array--parse-next
media-type)))
- (setq-local plz-media-type--position (point))
- (while object
- (setq-local plz-media-type--position (point))
- (when (functionp handler)
- (funcall handler object))
- (setq object (plz-media-type:application/json-array--parse-next
media-type))))))
+ (when-let (result (plz-media-type:application/json-array--consume-next
media-type))
+ (while result
+ (when (and (equal :array-element (car result))
+ (functionp handler))
+ (funcall handler (cdr result)))
+ (setq result (plz-media-type:application/json-array--consume-next
media-type))))))
(cl-defmethod plz-media-type-process ((media-type
plz-media-type:application/json-array) process chunk)
"Process the CHUNK according to MEDIA-TYPE using PROCESS."
(ignore media-type)
(cl-call-next-method media-type process chunk)
- (plz-media-type:application/json-array--parse-stream media-type))
+ (plz-media-type:application/json-array--parse-stream media-type)
+ (set-marker (process-mark process) (point-max)))
(cl-defmethod plz-media-type-then ((media-type
plz-media-type:application/json-array) response)
"Transform the RESPONSE into a format suitable for MEDIA-TYPE."
(ignore media-type)
(plz-media-type:application/json-array--parse-stream media-type)
+ (setf (plz-response-body response) nil)
response)
;; Content Type: application/x-ndjson
- [elpa] externals/llm 8a384aa073 61/71: Run handler code via a timer, (continued)
- [elpa] externals/llm 8a384aa073 61/71: Run handler code via a timer, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 95b9b8b515 68/71: Improve error handling in Vertex and Ollama, ELPA Syncer, 2024/05/17
- [elpa] externals/llm ece9b1fc82 69/71: Remove llm-request and fix requires, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 7f73a59fd1 12/71: Remove media-types from llm-request-plz-async, ELPA Syncer, 2024/05/17
- [elpa] externals/llm f41c55a44e 15/71: Switch Open AI completely to plz, fix async request method, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 83f05280fc 16/71: Strip plz changes and add JSON array stream media type, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 5bb3dadf25 17/71: Handle empty choices, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 2a0651adc2 22/71: Merge pull request #29 from r0man/plz, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 27884dcb32 27/71: Port ollama to plz, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 2ea07f9197 25/71: Merge pull request #30 from r0man/plz-event-type-symbol, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 623bceda67 29/71: Fix issue with JSON array parser nor emitting all objects,
ELPA Syncer <=
- [elpa] externals/llm 385ce9cdac 32/71: Use the streaming endpoint for the Vertex provider, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 1fb8511867 36/71: Use media type only in the llm-request-plz-async call, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 5623482527 37/71: Fix error handling in Gemini and Vertex provider, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 669456cba5 43/71: Fix Ollama error handling and appending to prompt, ELPA Syncer, 2024/05/17
- [elpa] externals/llm c26bf648a8 44/71: Increase llm-request-plz-timeout to 2 minutes, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 9a9b0de0df 52/71: Add llm-request-plz-connect-timeout, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 5145074ba0 57/71: Merge branch 'main' into plz, ELPA Syncer, 2024/05/17
- [elpa] externals/llm dda5d1f2d0 62/71: Call handler functions only with the event object, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 2146ba3803 64/71: Change some function names and make most of them private (#42), ELPA Syncer, 2024/05/17
- [elpa] externals/llm 3a2d6962f3 67/71: Whitespace fixes, ELPA Syncer, 2024/05/17