Skip to content

Commit 440f4b0

Browse files
committed
Add formatting to the project
1 parent 73fc56b commit 440f4b0

File tree

17 files changed

+456
-458
lines changed

17 files changed

+456
-458
lines changed

bb.edn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@
99
jar {:doc "Build jar with latest version"
1010
:task (clojure "-T:build jar")}
1111
deploy {:doc "Deploy the latest release"
12-
:task (clojure "-X:deploy")}}}
12+
:task (clojure "-X:deploy")}
13+
format:check {:doc "Check code formatting with standard-clj"
14+
:task (shell "standard-clj" "check" "src" "test" "examples/src")}
15+
format:project {:doc "Run standard-clojure formatting on the entire codebase"
16+
:task (shell "standard-clj" "fix" "src" "test" "examples/src")}}}

examples/src/simulflow_examples/twilio_websocket.clj

Lines changed: 114 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333

3434
(def wrap-exception
3535
(exception/create-exception-middleware
36-
(merge
37-
exception/default-handlers
38-
{;; print stack-traces for all exceptions
39-
::exception/wrap (fn [handler e request]
40-
(t/log! :error e)
41-
(handler e request))})))
36+
(merge
37+
exception/default-handlers
38+
{;; print stack-traces for all exceptions
39+
::exception/wrap (fn [handler e request]
40+
(t/log! :error e)
41+
(handler e request))})))
4242

4343
(defn emit-xml-str
4444
"Emit the string for this xml declaration"
@@ -67,9 +67,9 @@
6767
ws-url (str "wss://" h "/ws")]
6868
;; https://www.twilio.com/docs/voice/twiml/connect
6969
(xml-response
70-
(emit-xml-str [:Response
71-
[:Connect
72-
[:Stream {:url ws-url}]]]))))
70+
(emit-xml-str [:Response
71+
[:Connect
72+
[:Stream {:url ws-url}]]]))))
7373

7474
(def dbg-flow (atom nil))
7575

@@ -93,85 +93,85 @@
9393
chunk-duration-ms 20]
9494
{:procs
9595
(u/deep-merge
96-
{:transport-in {:proc transport/twilio-transport-in
97-
:args {:transport/in-ch in}}
98-
:transcriptor {:proc asr/deepgram-processor
99-
:args {:transcription/api-key (secret [:deepgram :api-key])
100-
:transcription/interim-results? true
101-
:transcription/punctuate? false
102-
:transcription/vad-events? true
103-
:transcription/smart-format? true
104-
:transcription/model :nova-2
105-
:transcription/utterance-end-ms 1000
106-
:transcription/language language
107-
:transcription/encoding :ulaw
108-
:transcription/sample-rate sample-rate}}
109-
:context-aggregator {:proc context/context-aggregator
110-
:args {:llm/context llm-context
111-
:aggregator/debug? false}}
96+
{:transport-in {:proc transport/twilio-transport-in
97+
:args {:transport/in-ch in}}
98+
:transcriptor {:proc asr/deepgram-processor
99+
:args {:transcription/api-key (secret [:deepgram :api-key])
100+
:transcription/interim-results? true
101+
:transcription/punctuate? false
102+
:transcription/vad-events? true
103+
:transcription/smart-format? true
104+
:transcription/model :nova-2
105+
:transcription/utterance-end-ms 1000
106+
:transcription/language language
107+
:transcription/encoding :ulaw
108+
:transcription/sample-rate sample-rate}}
109+
:context-aggregator {:proc context/context-aggregator
110+
:args {:llm/context llm-context
111+
:aggregator/debug? false}}
112112

113-
:llm {:proc llm/openai-llm-process
114-
:args {:openai/api-key (secret [:openai :new-api-sk])
115-
:llm/model "gpt-4o-mini"}}
113+
:llm {:proc llm/openai-llm-process
114+
:args {:openai/api-key (secret [:openai :new-api-sk])
115+
:llm/model "gpt-4o-mini"}}
116116

117-
:assistant-context-assembler {:proc context/assistant-context-assembler
118-
:args {:debug? false}}
117+
:assistant-context-assembler {:proc context/assistant-context-assembler
118+
:args {:debug? false}}
119119

120-
:llm-sentence-assembler {:proc context/llm-sentence-assembler}
121-
:tts {:proc tts/elevenlabs-tts-process
122-
:args {:elevenlabs/api-key (secret [:elevenlabs :api-key])
123-
:elevenlabs/model-id "eleven_flash_v2_5"
124-
:elevenlabs/voice-id (secret [:elevenlabs :voice-id])
125-
:voice/stability 0.5
126-
:voice/similarity-boost 0.8
127-
:voice/use-speaker-boost? true
128-
:flow/language language
129-
:audio.out/encoding encoding
130-
:audio.out/sample-rate sample-rate}}
131-
:audio-splitter {:proc transport/audio-splitter
132-
:args {:audio.out/sample-rate sample-rate
133-
:audio.out/sample-size-bits sample-size-bits
134-
:audio.out/channels channels
135-
:audio.out/duration-ms chunk-duration-ms}}
136-
:realtime-out {:proc transport-out/realtime-out-processor
137-
:args {:audio.out/chan out
138-
:audio.out/sending-interval 20}}
139-
:activity-monitor {:proc activity-monitor/process
140-
:args {::activity-monitor/timeout-ms 5000}}
120+
:llm-sentence-assembler {:proc context/llm-sentence-assembler}
121+
:tts {:proc tts/elevenlabs-tts-process
122+
:args {:elevenlabs/api-key (secret [:elevenlabs :api-key])
123+
:elevenlabs/model-id "eleven_flash_v2_5"
124+
:elevenlabs/voice-id (secret [:elevenlabs :voice-id])
125+
:voice/stability 0.5
126+
:voice/similarity-boost 0.8
127+
:voice/use-speaker-boost? true
128+
:flow/language language
129+
:audio.out/encoding encoding
130+
:audio.out/sample-rate sample-rate}}
131+
:audio-splitter {:proc transport/audio-splitter
132+
:args {:audio.out/sample-rate sample-rate
133+
:audio.out/sample-size-bits sample-size-bits
134+
:audio.out/channels channels
135+
:audio.out/duration-ms chunk-duration-ms}}
136+
:realtime-out {:proc transport-out/realtime-out-processor
137+
:args {:audio.out/chan out
138+
:audio.out/sending-interval 20}}
139+
:activity-monitor {:proc activity-monitor/process
140+
:args {::activity-monitor/timeout-ms 5000}}
141141

142-
:prn-sink {:proc (flow/process (fn
143-
([] {:ins {:in "gimme stuff to print!"}})
144-
([_] nil)
145-
([_ _] nil)
146-
([_ _ v] (t/log! {:id :prn-sink :data v}))))}}
147-
extra-procs)
142+
:prn-sink {:proc (flow/process (fn
143+
([] {:ins {:in "gimme stuff to print!"}})
144+
([_] nil)
145+
([_ _] nil)
146+
([_ _ v] (t/log! {:id :prn-sink :data v}))))}}
147+
extra-procs)
148148

149149
:conns (concat
150-
[[[:transport-in :sys-out] [:transcriptor :sys-in]]
151-
[[:transport-in :out] [:transcriptor :in]]
150+
[[[:transport-in :sys-out] [:transcriptor :sys-in]]
151+
[[:transport-in :out] [:transcriptor :in]]
152152

153-
[[:transcriptor :out] [:context-aggregator :in]]
154-
[[:context-aggregator :out] [:llm :in]]
153+
[[:transcriptor :out] [:context-aggregator :in]]
154+
[[:context-aggregator :out] [:llm :in]]
155155

156-
;; Aggregate full context
157-
[[:llm :out] [:assistant-context-assembler :in]]
158-
[[:assistant-context-assembler :out] [:context-aggregator :in]]
156+
;; Aggregate full context
157+
[[:llm :out] [:assistant-context-assembler :in]]
158+
[[:assistant-context-assembler :out] [:context-aggregator :in]]
159159

160-
;; Assemble sentence by sentence for fast speech
161-
[[:llm :out] [:llm-sentence-assembler :in]]
162-
[[:llm-sentence-assembler :out] [:tts :in]]
160+
;; Assemble sentence by sentence for fast speech
161+
[[:llm :out] [:llm-sentence-assembler :in]]
162+
[[:llm-sentence-assembler :out] [:tts :in]]
163163

164-
[[:tts :out] [:audio-splitter :in]]
165-
[[:transport-in :sys-out] [:realtime-out :sys-in]]
166-
[[:audio-splitter :out] [:realtime-out :in]]
164+
[[:tts :out] [:audio-splitter :in]]
165+
[[:transport-in :sys-out] [:realtime-out :sys-in]]
166+
[[:audio-splitter :out] [:realtime-out :in]]
167167

168-
;; Activity monitor connections - basically check if there is
169-
;; activity on the pipeline
170-
[[:realtime-out :out] [:activity-monitor :in]]
171-
[[:transcriptor :out] [:activity-monitor :in]]
172-
[[:activity-monitor :out] [:context-aggregator :in]]
173-
[[:activity-monitor :out] [:tts :in]]]
174-
extra-conns)}))
168+
;; Activity monitor connections - basically check if there is
169+
;; activity on the pipeline
170+
[[:realtime-out :out] [:activity-monitor :in]]
171+
[[:transcriptor :out] [:activity-monitor :in]]
172+
[[:activity-monitor :out] [:context-aggregator :in]]
173+
[[:activity-monitor :out] [:tts :in]]]
174+
extra-conns)}))
175175

176176
(defn tool-use-example
177177
"Tools are specified in the :llm/context :tools vector.
@@ -184,28 +184,28 @@
184184
[in out]
185185
{:flow
186186
(flow/create-flow
187-
(phone-flow
188-
{:in in
189-
:out out
190-
:llm/context {:messages
191-
[{:role "system"
192-
:content "You are a voice agent operating via phone. Be
187+
(phone-flow
188+
{:in in
189+
:out out
190+
:llm/context {:messages
191+
[{:role "system"
192+
:content "You are a voice agent operating via phone. Be
193193
concise. The input you receive comes from a
194194
speech-to-text (transcription) system that isn't always
195195
efficient and may send unclear text. Ask for
196196
clarification when you're unsure what the person said."}]
197-
:tools
198-
[{:type :function
199-
:function
200-
{:name "get_weather"
201-
:handler (fn [{:keys [town]}] (str "The weather in " town " is 17 degrees celsius"))
202-
:description "Get the current weather of a location"
203-
:parameters {:type :object
204-
:required [:town]
205-
:properties {:town {:type :string
206-
:description "Town for which to retrieve the current weather"}}
207-
:additionalProperties false}
208-
:strict true}}]}}))})
197+
:tools
198+
[{:type :function
199+
:function
200+
{:name "get_weather"
201+
:handler (fn [{:keys [town]}] (str "The weather in " town " is 17 degrees celsius"))
202+
:description "Get the current weather of a location"
203+
:parameters {:type :object
204+
:required [:town]
205+
:properties {:town {:type :string
206+
:description "Town for which to retrieve the current weather"}}
207+
:additionalProperties false}
208+
:strict true}}]}}))})
209209

210210
(defn make-twilio-ws-handler
211211
[make-flow]
@@ -259,25 +259,25 @@
259259

260260
(def app
261261
(ring/ring-handler
262-
(ring/router
263-
routes
264-
{:exception pretty/exception
265-
:data {:muuntaja mtj/instance
266-
:middleware [;; query-params & form-params
267-
parameters/parameters-middleware
268-
;; content-negotiation
269-
muuntaja/format-negotiate-middleware
270-
;; encoding response body
271-
muuntaja/format-response-middleware
272-
;; exception handling
273-
wrap-exception
274-
;; decoding request body
275-
muuntaja/format-request-middleware
276-
;; coercing response bodys
277-
coercion/coerce-response-middleware
278-
;; coercing request parameters
279-
coercion/coerce-request-middleware]}})
280-
(ring/create-default-handler)))
262+
(ring/router
263+
routes
264+
{:exception pretty/exception
265+
:data {:muuntaja mtj/instance
266+
:middleware [;; query-params & form-params
267+
parameters/parameters-middleware
268+
;; content-negotiation
269+
muuntaja/format-negotiate-middleware
270+
;; encoding response body
271+
muuntaja/format-response-middleware
272+
;; exception handling
273+
wrap-exception
274+
;; decoding request body
275+
muuntaja/format-request-middleware
276+
;; coercing response bodys
277+
coercion/coerce-response-middleware
278+
;; coercing request parameters
279+
coercion/coerce-request-middleware]}})
280+
(ring/create-default-handler)))
281281

282282
(defn start [& {:keys [port] :or {port 3000}}]
283283
(println (str "server running in port " port))

src/simulflow/async.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
[bindings & body]
5050
`(vthread (loop ~bindings ~@body)))
5151

52-
5352
(defn drain-channel!
5453
"Drains all pending messages from a channel without blocking.
5554
Returns the number of messages drained."

src/simulflow/command.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
:buffer-size buffer-size})
3333
id)))
3434

35-
3635
(defn http-request-command
3736
"Create an HTTP request command for regular API calls"
3837
[url method body & {:keys [headers timeout-ms id]}]

src/simulflow/processors/activity_monitor.clj

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
(ns simulflow.processors.activity-monitor
22
"Process to monitor activity on the call. Used to ping user when no activity is detected."
3-
(:require [clojure.core.async :as a]
4-
[clojure.core.async.flow :as flow]
5-
[simulflow.async :refer [vthread-loop]]
6-
[simulflow.frame :as frame]
7-
[simulflow.schema :as schema]
8-
[taoensso.telemere :as t]))
3+
(:require
4+
[clojure.core.async :as a]
5+
[clojure.core.async.flow :as flow]
6+
[simulflow.async :refer [vthread-loop]]
7+
[simulflow.frame :as frame]
8+
[simulflow.schema :as schema]
9+
[taoensso.telemere :as t]))
910

1011
(def ActivityMonitorConfigSchema
1112
[:map

src/simulflow/processors/audio_resampler.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
(defn audio-frame?
5858
[frame]
5959
(or
60-
(frame/audio-input-raw? frame)
61-
(frame/audio-output-raw? frame)))
60+
(frame/audio-input-raw? frame)
61+
(frame/audio-output-raw? frame)))
6262

6363
(defn transform
6464
"Transform function that resamples audio-input-raw frames"

0 commit comments

Comments
 (0)