Skip to content

Commit

Permalink
switched to hakiu, cached image
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mor committed Jul 26, 2024
1 parent 11e7c6c commit a74ffa3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 48 deletions.
2 changes: 1 addition & 1 deletion file.edn

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion roots.edn
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(#uuid "c0dfaed4-c0b4-497c-af03-383a74e9cd14")
[#uuid "5bfe1378-672c-420d-b49a-06bb7c0eb476" #uuid "945d50eb-b1e7-45e3-b95e-f7c2e6a0f451" #uuid "1282f1e2-fe07-445d-86f4-b6c8ceac6982" #uuid "0a6698a9-8259-4a1d-917c-720cf22ec7d7" #uuid "8a0b4a64-ee07-4d1e-8189-e68d14f4df2b" #uuid "cc317c7a-0e99-4a5a-a187-5bc969f6bb0a" #uuid "8051e5f2-aa62-475f-bca8-0a0702919fb7" #uuid "b6e0aefc-a3d7-4948-93aa-5f51f846987d" #uuid "d78dc98b-cfa4-4b2d-a3a0-3de581a8bee0"]
2 changes: 1 addition & 1 deletion src/electric_starter_app/llm.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"anthropic-version" "2023-06-01"}
:as :stream
:content-type :json
:form-params {:model "claude-3-5-sonnet-20240620"
:form-params {:model (or "claude-3-haiku-20240307" "claude-3-5-sonnet-20240620")
:messages [{:role "user" :content q} {:role "assistant" :content "---"}]
:max_tokens 4096
:stream true}})
Expand Down
99 changes: 54 additions & 45 deletions src/electric_starter_app/main.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,38 @@
(let [uuid (random-uuid)
embedding (llm/get-embedding title)]
(def title title)
(if (not-empty @graph)


(do (def potential-duplicate (apply min-key (fn [x] (llm/embedding-distance embedding (:embedding x)))
(vals @graph)))

(def is-same (is-same-event title (:title potential-duplicate)))
(let [ret (if (not-empty @graph)
(do (def potential-duplicate (apply min-key (fn [x] (llm/embedding-distance embedding (:embedding x)))
(vals @graph)))
(def is-same (is-same-event title (:title potential-duplicate)))

(if is-same
(do (when parent
(swap! graph assoc-in [parent :causes]
(conj (get-in @graph [parent :causes]) (:id potential-duplicate))))
false)
(do
(swap! graph assoc uuid {:id uuid :title title
:causes [] :effects []
:embedding embedding})
(when parent
(swap! graph assoc-in [parent :causes]
(conj (get-in @graph [parent :causes]) uuid)))
uuid)))

(do
(swap! graph assoc uuid {:id uuid :title title
:causes [] :effects []
:embedding embedding})
(when parent
(swap! graph assoc-in [parent :causes]
(conj (get-in @graph [parent :causes]) uuid)))
uuid)))))
(if is-same
(do (when parent
(swap! graph assoc-in [parent :causes]
(conj (get-in @graph [parent :causes]) (:id potential-duplicate))))
false)
(do
(swap! graph assoc uuid {:id uuid :title title
:causes [] :effects []
:embedding embedding})
(when parent
(swap! graph assoc-in [parent :causes]
(conj (get-in @graph [parent :causes]) uuid)))
uuid)))

(do
(swap! graph assoc uuid {:id uuid :title title
:causes [] :effects []
:embedding embedding})
(when parent
(swap! graph assoc-in [parent :causes]
(conj (get-in @graph [parent :causes]) uuid)))
uuid))]
(render-image)
ret))))

#?(:clj (def roots (duratom/duratom :local-file
:file-path "roots.edn"
Expand All @@ -78,6 +80,22 @@
(reset! graph {})
(reset! roots []))

#?(:clj (def image (atom nil)))

#?(:clj (defn render-image []
(reset! image (llm/encode (dot/render (dot/dot (dot/digraph
{}
(concat
(->> @graph vals (map (fn [node]
[(str (:id node))
{:label (split-words-wrap (:title node))
:shape "box"}])))
(->> @graph vals (map (fn [node]
(for [x (:causes node)]
[(str (:id node)) (str x)]))))
)))
{:format :png})))))

(e/defn HistoryBlock [id seen !displayed]
(e/client
(let [data (e/server (get (e/watch graph) id)) !selectedchild (atom nil) selectedchild (e/watch !selectedchild)]
Expand Down Expand Up @@ -134,8 +152,10 @@
(e/client
(binding [dom/node js/document.body]
(let [!displayed (atom #{}) !admin (atom false) admin (e/watch !admin)]
(dom/text "i am looking for a job: email me at thmorriss at gmail dot com")
(dom/br)
(dom/input
(dom/props {:placeholder "Type a message" :maxlength 100})
(dom/props {:placeholder "create a root node" :maxlength 100})
(dom/on "keydown" (e/fn [e]
(reset! !admin (= (.. e -target -value) "secretadminpowers"))
(when (= "Enter" (.-key e))
Expand All @@ -149,7 +169,8 @@
(dom/on "click"
(e/fn [_] (e/server
(reset! roots (filter #(not= % root) @roots))
(swap! graph dissoc root)))) ) ) )
(swap! graph dissoc root)
(render-image)))) ) ) )
(let [!show (atom false) show (e/watch !show) ]
(if show
(dom/div
Expand All @@ -171,17 +192,5 @@
(dom/img
(dom/props {:src
(str "data:image/png;base64, "
(e/server
(llm/encode (dot/render (dot/dot (dot/digraph
{}
(concat
(->> (e/watch graph) vals (map (fn [node]
[(str (:id node))
{:label (split-words-wrap (:title node))
:shape "box"}])))
(->> (e/watch graph) vals (map (fn [node]
(for [x (:causes node)]
[(str (:id node)) (str x)]))))
)))
{:format :png}))))
:style {:width "100%"}}))))))
(e/server (e/watch image)))
}))))))

0 comments on commit a74ffa3

Please sign in to comment.