This is docDPUmuR.info, produced by makeinfo version 6.8 from
plz-event-source.texi.

INFO-DIR-SECTION Emacs
START-INFO-DIR-ENTRY
* Plz Event Source: (plz-event-source). Event Source extension for plz.el.
END-INFO-DIR-ENTRY


File: docDPUmuR.info,  Node: Top,  Next: Installation,  Up: (dir)

plz-event-source
****************

‘plz-event-source’ provides a plz-media-type
(https://github.com/r0man/plz-media-type), a parser and an event source
implementation for the Server Sent Event (SSE)
(https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events)
protocol.  It is used in the LLM (https://github.com/ahyatt/llm) library
to handle server sent events.

* Menu:

* Installation::
* Usage::
* Credits::
* License::

— The Detailed Node Listing —

Installation

* GNU ELPA::

Usage

* Examples::

Credits

* Copyright assignment::



File: docDPUmuR.info,  Node: Installation,  Next: Usage,  Prev: Top,  Up: Top

1 Installation
**************

* Menu:

* GNU ELPA::


File: docDPUmuR.info,  Node: GNU ELPA,  Up: Installation

1.1 GNU ELPA
============

‘plz-event-source’ is available in GNU ELPA
(http://elpa.gnu.org/packages/plz-event-source.html).  It may be
installed in Emacs using the ‘package-install’ command.


File: docDPUmuR.info,  Node: Usage,  Next: Credits,  Prev: Installation,  Up: Top

2 Usage
*******

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
(https://github.com/r0man/plz-media-type#usage) function of the
plz-media-type (https://github.com/r0man/plz-media-type) library.

* Menu:

* Examples::


File: docDPUmuR.info,  Node: Examples,  Up: Usage

2.1 Examples
============

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")))


File: docDPUmuR.info,  Node: Credits,  Next: License,  Prev: Usage,  Up: Top

3 Credits
*********

   • Thanks to ahyatt (https://github.com/ahyatt) and alphapapa
     (https://github.com/alphapapa) for their help and advice.

* Menu:

* Copyright assignment::


File: docDPUmuR.info,  Node: Copyright assignment,  Up: Credits

3.1 Copyright assignment
========================

This package is part of GNU Emacs (https://www.gnu.org/software/emacs/),
being distributed in GNU ELPA (https://elpa.gnu.org/).  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 <emacs-devel@gnu.org>
to request the assignment form.


File: docDPUmuR.info,  Node: License,  Prev: Credits,  Up: Top

4 License
*********

GPLv3



Tag Table:
Node: Top225
Node: Installation866
Node: GNU ELPA1001
Node: Usage1262
Node: Examples1704
Node: Credits3198
Node: Copyright assignment3464
Node: License4051

End Tag Table


Local Variables:
coding: utf-8
End:
