Skip to content

Commit

Permalink
Chore: Prefer kwargs for complex constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
motform committed Oct 5, 2024
1 parent 30fdd65 commit cc9a6bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/org/motform/multiverse/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
(let [story-id (nano-id 10)
sentence-id (nano-id 10)]
{:db (-> db
(assoc-in [:db/stories story-id] (story/->story story-id sentence-id prompt))
(assoc-in [:db/stories story-id]
(story/->story prompt :id story-id :sentence-id sentence-id))
(assoc-in [:db/state :story/active] story-id)
(assoc-in [:db/state :sentence/active] sentence-id)
(assoc-in [:db/state :sentence/highlight] {:id sentence-id :source :page/new-story})
Expand Down Expand Up @@ -134,9 +135,9 @@
(let [parent-path (get-in db [:db/stories story-id :story/sentences parent-id :sentence/path])
child-ids (repeatedly 3 #(nano-id 10))
children (story/->children
parent-path
child-ids
(open-ai/completion-texts completions))]
(open-ai/completion-texts completions)
:child-ids child-ids
:parent-path parent-path)]
{:db (-> db
(update-in [:db/stories story-id :story/sentences] merge children)
(assoc-in [:db/stories story-id :story/sentences parent-id :sentence/children] child-ids)
Expand Down
23 changes: 16 additions & 7 deletions src/org/motform/multiverse/story.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
(:require
[org.motform.multiverse.util :as util]))

(defn ->sentence [id text path children]
(defn ->sentence [text & {:keys [id path children]}]
#:sentence{:id id :text text :path path :children children})

(defn ->story [story-id sentence-id prompt]
{:story/meta {:story/id story-id
(defn ->story [prompt & {:keys [id sentence-id model version]}]
{:story/meta {:story/id id
:story/title ""
:story/updated (js/Date.)
:sentence/active sentence-id}
:story/sentences {sentence-id (->sentence sentence-id prompt [sentence-id] [])}})
:sentence/active sentence-id
:open-ai/model model
:story/prompt-version version}
:story/sentences {sentence-id (->sentence prompt
:id sentence-id
:path [sentence-id]
:children [])}})

(def prompt-templates
#:template
Expand All @@ -22,8 +27,12 @@

(defn ->children
"Make children map to be merged into sentences."
[parent-path child-ids texts]
[texts & {:keys [child-ids parent-path]}]
(let [child-pairs (util/pairs child-ids texts)]
(reduce (fn [children [id text]]
(assoc children id (->sentence id text (conj parent-path id) [])))
(assoc children id
(->sentence text
:id id
:path (conj parent-path id)
:children [])))
{} child-pairs)))

0 comments on commit cc9a6bc

Please sign in to comment.