A Clojure library for building realtime conversations using OpenAI's Realtime API
reelthyme provides a simple, core.async-driven API for interacting with OpenAI's Realtime API. On the JVM it uses WebSocket, while ClojureScript will leverage WebRTC. Use it to build multimodal, real-time conversational experiences with minimal boilerplate.
Start a REPL and require the namespaces:
(ns my-app.core
(:require [reelthyme.core :as rt]
[reelthyme.schema :as sc]
[clojure.core.async :as a]))
Open a realtime session, with optional event validation:
(def session-ch
(rt/connect! {:xf-in (map sc/validate)}) ;; validate outgoing events
Authentication can be provided as an :api-key option, or the default will attempt to use
the OPENAI_API_KEY environment variable.
The reelthyme.schema namespace is completely optional. The validate function provided by it is a great
addition to the development environment to ensure properly constructed client events are being sent.
Separate audio deltas from other events:
;;; Receive server events as plain Clojure maps
(let [[event-ch stop-audio] (rt/stream! session-ch)]
(a/go-loop []
(when-let [ev (a/<! event-ch)]
(println "Server event:" ev)
(recur))))
Send client events as plain Clojure maps.
;; Send a text message
(a/put! session-ch
{:type "conversation.item.create"
:item {:type "message"
:role "user"
:content [{:type "input_text"
:text "What is the weather today?"}]}})
;; Request both text and audio response
(a/put! session-ch
{:type "response.create"
:response {:modalities ["text" "audio"]}})
(def stop-capture
(rt/capture-audio! session-ch {:interval-ms 500}))
;; Later, stop capturing
(stop-capture)
reelthyme.schema for built-in event validation.:xf-in, :xf-out, :ex-handler, :log-fn options.Can you improve this documentation? These fine people already did:
Brian Scaturro & Brian Scaturro (aider)Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |