[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/llm 03afb1d795 23/71: Use symbols for event types & imp
From: |
ELPA Syncer |
Subject: |
[elpa] externals/llm 03afb1d795 23/71: Use symbols for event types & improve timeout handling |
Date: |
Fri, 17 May 2024 00:58:44 -0400 (EDT) |
branch: externals/llm
commit 03afb1d795d709821fe5e7019d6b3dcae8b39995
Author: Roman Scherer <roman@burningswell.com>
Commit: Roman Scherer <roman@burningswell.com>
Use symbols for event types & improve timeout handling
This changes the event type from a string to a symbol. This is more
aligned wirh the Emacs Lisp way and the way we handle media type and
subtype.
---
llm-claude.el | 14 +++++++-------
llm-openai.el | 4 ++--
plz-event-source.el | 19 +++++++++----------
3 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/llm-claude.el b/llm-claude.el
index 3e85c43b9d..30d3912947 100644
--- a/llm-claude.el
+++ b/llm-claude.el
@@ -119,19 +119,19 @@ STREAM is a boolean indicating whether the response
should be streamed."
;; We ignore many types of messages; these might become important if
Claude
;; sends a few different alternate contents, but for now they don't do
;; that.
- `(("message_start" . ,(lambda (_)))
- ("content_block_start" . ,(lambda (_)))
- ("ping" . ,(lambda (_)))
- ("message_stop" . ,(lambda (_)))
- ("content_block_stop" . ,(lambda (_)))
- ("content_block_delta" .
+ `((message_start . ,(lambda (_)))
+ (content_block_start . ,(lambda (_)))
+ (ping . ,(lambda (_)))
+ (message_stop . ,(lambda (_)))
+ (content_block_stop . ,(lambda (_)))
+ (content_block_delta .
,(lambda (data)
(setq in-flight-message
(concat in-flight-message
(let* ((json (json-parse-string data :object-type
'alist))
(delta (assoc-default 'delta json))
(type (assoc-default 'type delta)))
- (when (equal type "text_delta")
+ (when (eql type 'text_delta)
(assoc-default 'text delta)))))
(llm-request-plz-callback-in-buffer
buf
diff --git a/llm-openai.el b/llm-openai.el
index 17eb3ce448..17ecc30d68 100644
--- a/llm-openai.el
+++ b/llm-openai.el
@@ -303,13 +303,13 @@ RESPONSE can be nil if the response is complete."
:headers (llm-openai--headers provider)
:data (llm-openai--chat-request (llm-openai-chat-model provider) prompt t)
:event-stream-handlers
- `(("message" . ,(lambda (data)
+ `((message . ,(lambda (data)
(when (not (equal data "[DONE]"))
(when-let ((response
(llm-openai--get-partial-chat-response
(json-read-from-string data))))
(when (stringp response)
(llm-request-plz-callback-in-buffer buf
partial-callback response))))))
- ("error" . ,(lambda (data)
+ (error . ,(lambda (data)
(llm-request-plz-callback-in-buffer
buf error-callback 'error data))))
:on-error (lambda (_ data)
diff --git a/plz-event-source.el b/plz-event-source.el
index 0bdb7ebf5e..c6861f7deb 100644
--- a/plz-event-source.el
+++ b/plz-event-source.el
@@ -33,7 +33,6 @@
(require 'cl-lib)
(require 'eieio)
-(require 'pcase)
(require 'plz)
(require 'plz-media-type)
(require 'rx)
@@ -61,9 +60,9 @@
(type
:accessor plz-event-source-event-type
:initarg :type
- :initform "message"
+ :initform 'message
:documentation "The event type."
- :type string))
+ :type symbol))
"The server sent event class.")
;; Parser
@@ -145,8 +144,8 @@
last-event-id)
:origin (buffer-name)
:type (if (string-blank-p event-type-buffer)
- "message"
- event-type-buffer))))
+ 'message
+ (intern event-type-buffer)))))
(setf data-buffer ""
event-type-buffer "")
(setf events (cons event events))
@@ -339,7 +338,7 @@
"Open a connection to the URL of the event SOURCE."
(with-slots (buffer errors options ready-state parser) source
(with-current-buffer (get-buffer-create buffer)
- (let ((event (plz-event-source-event :type "open")))
+ (let ((event (plz-event-source-event :type 'open)))
(setf ready-state 'connecting)
(setf parser (plz-event-source-parser
:buffer buffer
@@ -351,7 +350,7 @@
(cl-defmethod plz-event-source-close ((source plz-buffer-event-source))
"Close the connection of the event SOURCE."
(with-slots (buffer ready-state) source
- (let ((event (plz-event-source-event :type "close")))
+ (let ((event (plz-event-source-event :type 'close)))
(setf ready-state 'closed)
(plz-event-source-dispatch-event source event)
source)))
@@ -414,7 +413,7 @@
(cl-defmethod plz-media-type-else ((_ plz-media-type:text/event-stream) error)
"Transform the ERROR into a format suitable for MEDIA-TYPE."
(let* ((source plz-event-source--current)
- (event (plz-event-source-event :type "error" :data error)))
+ (event (plz-event-source-event :type 'error :data error)))
(plz-event-source-close source)
(plz-event-source-dispatch-event source event)
error))
@@ -433,11 +432,11 @@
(let ((type (car pair))
(handler (cdr pair)))
(cond
- ((equal "open" type)
+ ((equal 'open type)
(cons type (lambda (source event)
(setf (oref event data)
response)
(funcall handler source
event))))
- ((equal "close" type)
+ ((equal 'close type)
(cons type (lambda (source event)
(setf (oref event data)
response)
(funcall handler source
event))))
- [elpa] externals/llm 84678edfae 07/71: Merge pull request #28 from r0man/plz, (continued)
- [elpa] externals/llm 84678edfae 07/71: Merge pull request #28 from r0man/plz, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 9541d34656 08/71: Enable streaming in Open AI with plz modifications, ELPA Syncer, 2024/05/17
- [elpa] externals/llm c9ab8664ce 09/71: Support function streaming with Open AI & plz, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 3988fecb53 11/71: Make separate function for event streaming, w/ client-side handlers, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 9ce3d9e003 13/71: Port claude to llm-request-plz, ELPA Syncer, 2024/05/17
- [elpa] externals/llm f9213b981c 14/71: Use the plz request module for everything in Claude, ELPA Syncer, 2024/05/17
- [elpa] externals/llm cdbb41528c 18/71: Fix issue advancing the process buffer, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 3441784ae2 19/71: Fix error handling., ELPA Syncer, 2024/05/17
- [elpa] externals/llm 6f9c604e58 20/71: Decode body and chunks using a coding system, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 62495de57f 21/71: Don't decode error response twice, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 03afb1d795 23/71: Use symbols for event types & improve timeout handling,
ELPA Syncer <=
- [elpa] externals/llm e07c84b81b 24/71: Improve Curl/HTTP error handling, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 069bd193ef 26/71: Adding Gemini & Vertex streaming using plz, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 99814b533d 28/71: Changes to get at least some of Gemini / Vertex working, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 7919563997 30/71: Merge pull request #31 from r0man/plz, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 40909718cc 31/71: Fix function calling for Gemini & Vertex, and streaming for Gemini, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 9c07e22659 33/71: Kill the response buffer when the request completed, ELPA Syncer, 2024/05/17
- [elpa] externals/llm a61eb88c53 34/71: Merge pull request #33 from r0man/plz, ELPA Syncer, 2024/05/17
- [elpa] externals/llm fa6c445271 35/71: Fix issue with not handline the plz response correctly for streaming, ELPA Syncer, 2024/05/17
- [elpa] externals/llm f42e00265f 38/71: Add more documentation, ELPA Syncer, 2024/05/17
- [elpa] externals/llm 2426f827d7 39/71: Add process filter error handling, ELPA Syncer, 2024/05/17