core-async

Ovi Stoica 2025-02-22T08:01:46.372559Z

Note for core.async.flow users. If you start a new thread in the :init function of a process, if there are any errors or a crash in that thread, they will not be reported on the error-chan returned when starting the flow. This took some debugging time for me. In hindsight, it seems evident as there isn’t a catch mechanism for this, but it still might be good for others to know. Code in the replies πŸ‘‡

Ovi Stoica 2025-02-22T08:02:40.517859Z

(def end-call-judge
  "Process that judges when the AI should end the call."
  (flow/process
    {:describe (fn [] {:ins {:in "Channel for frames containing what the assistant is saying"}
                       :params {:openai/api-key "Api key for llm"
                                :end-phrases "Dictionary of phrases that when the assistant says, the call should be ended"}})

     :init
     (fn [params]
       (let [llm-write (a/chan 100)
             end-time-speech (atom nil)
             end-call-f (atom (:end-call-f params))
             total-assistant-messages (atom "")
             write-to-llm
             #(loop []
                ;; ‼️ IMPORTANT: Errors in this loop are not reported on `flow` `error-chan`
                (when-let [frame (a/ (openai/normal-chat-completion
                                                        {:api-key (:openai/api-key params)
                                                         :messages [{:role :system
                                                                     :content (str "You are a ending call judge. You will oversee the output of an LLM assistant and judge when the call should be ended. When the assistant says any of the end-call phrases you should end the call. Here are the end-call phrases: " (str/join ", " (:end-phrases params)))}
                                                                    {:role :user
                                                                     :content (str "Assistant message:" @total-assistant-messages)}]
                                                         :response-format response-format})
                                                       :body
                                                       u/parse-if-json
                                                       content
                                                       u/parse-if-json)]

                          (t/log! :debug ["SHOULD END " should_end "FOR " @total-assistant-messages])
                          (if should_end
                            (let [now (mono-time)
                                  diff (- @end-time-speech now)]
                              (t/log! :debug ["ENDING CALL IN " diff "FOR " @total-assistant-messages])
                              (a/

Ovi Stoica 2025-02-22T08:03:41.968679Z

Excuse the bad code. I wrote this in a big hurry, but the point remains

Daniel Slutsky 2025-02-22T22:16:38.459699Z

On the beginning of the new scicloj-ai-meetups series today, @ovidiu.stoica1094 and @jpmonettas discussed, among other things, applications built with core.async.flow and the way they an be debugged using a new #flow-storm plugin. https://clojurians.slack.com/archives/C03RZRRMP/p1740262448869799

πŸ‘ 1
1
πŸš€ 1
Ovi Stoica 2025-02-27T14:15:11.995479Z

Thank you, Rich! I'm happy you liked it!

2025-02-26T18:10:59.443019Z

great presentation @ovidiu.stoica1094

πŸ‘ 1
πŸ™ 1
πŸŽ‰ 1