Next: Installation [Contents]
plz-event-source
provides a plz-media-type, a parser and an event
source implementation for the Server Sent Event (SSE) protocol. It is
used in the LLM library to handle server sent events.
Next: Usage, Previous: plz-event-source, Up: plz-event-source [Contents]
Up: Installation [Contents]
plz-event-source
is available in GNU ELPA. It may be installed in
Emacs using the package-install
command.
Next: Credits, Previous: Installation, Up: plz-event-source [Contents]
This library provides the plz-event-source:text/event-stream
class,
which is a media type implementation for server sent events. It should
be used with the plz-media-type-request function of the plz-media-type
library.
The following example shows how to request chat completions from a large language model.
(plz-media-type-request 'post "https://api.openai.com/v1/chat/completions" :as `(media-types ((text/event-stream . ,(plz-event-source:text/event-stream :events `((open . (lambda (event) (message "open: %s" event))) (message . (lambda (event) (message "message: %s" event))) (close . (lambda (event) (message "close: %s" event)))))))) :body (json-encode '(("model" . "gpt-3.5-turbo") ("messages" . [(("role" . "system") ("content" . "You are an assistant.")) (("role" . "user") ("content" . "Hello"))]) ("stream" . t))) :headers `(("Authorization" . ,(format "Bearer %s" (auth-source-pick-first-password :host "api.openai.com" :user "plz-event-source"))) ("Content-Type" . "application/json")))
Next: License, Previous: Usage, Up: plz-event-source [Contents]
This package is part of GNU Emacs, being distributed in GNU ELPA. Contributions to this project must follow GNU guidelines, which means that, as with other parts of Emacs, patches of more than a few lines must be accompanied by having assigned copyright for the contribution to the FSF. Contributors who wish to do so may contact emacs-devel@gnu.org to request the assignment form.