Skip to content

Commit 257e806

Browse files
committed
qol, messages to show state, show new prompt in sidebar
1 parent 8ddffb6 commit 257e806

File tree

6 files changed

+139
-89
lines changed

6 files changed

+139
-89
lines changed

src/main/ui/actions/dg_this_page.cljs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,30 @@
1717
(swap! res str (str child-str "\n"))))
1818
res))
1919

20-
(defn create-bare-struct [open-page-uid suggestion-uid]
20+
(defn create-bare-struct [open-page-uid suggestion-uid loading-messages-uid default-msg]
2121
(go
2222
(let [already-suggested? (block-has-child-with-str? open-page-uid "AI: Discourse node suggestions")
2323
suggestion-comp-uid (gen-new-uid)
2424
struct (if (nil? already-suggested?)
2525
{:s "AI: Discourse node suggestions"
26+
:op false
2627
:c [{:s "{{llm-dg-suggestions}}"
2728
:u suggestion-comp-uid
2829
:op false
2930
:c [{:s "Suggestions"
30-
:u suggestion-uid}]}]}
31+
:u suggestion-uid}
32+
{:s "Loading messages"
33+
:c [{:s default-msg
34+
:u loading-messages-uid}]}]}]}
3135
{:s "{{llm-dg-suggestions}}"
3236
:op false
3337
:u suggestion-comp-uid
3438
:c [{:s "Suggestions"
35-
:u suggestion-uid}]})
39+
:u suggestion-uid}
40+
{:s "Loading messages"
41+
:c [{:s default-msg
42+
:u loading-messages-uid}]}]})
43+
3644
top-parent (if (nil? already-suggested?)
3745
open-page-uid
3846
already-suggested?)]

src/main/ui/components/chat.cljs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@
164164
(fn [n]
165165
(not= "{{llm-dg-suggestions}}" (:string n)))
166166
(sort-by :order (:children (get-child-with-str block-uid "Messages"))))
167-
168167
settings (merge
169168
{:model (get model-mappings model)
170169
:temperature temp

src/main/ui/components/discourse_graph_this_page.cljs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[ui.components.chat :refer [chat-context]]
77
[ui.components.chin :refer [chin]]
88
[ui.actions.dg-this-page :refer [create-bare-struct ask-llm]]
9-
[ui.utils :refer [button-popover button-with-tooltip watch-string model-mappings get-safety-settings update-block-string-for-block-with-child settings-button-popover image-to-text-for p get-child-of-child-with-str title->uid q block-has-child-with-str? call-llm-api update-block-string uid->title log get-child-with-str get-child-of-child-with-str-on-page get-open-page-uid get-block-parent-with-order get-focused-block create-struct gen-new-uid default-chat-struct get-todays-uid]]
9+
[ui.utils :refer [button-popover create-new-block button-with-tooltip watch-string model-mappings get-safety-settings update-block-string-for-block-with-child settings-button-popover image-to-text-for p get-child-of-child-with-str title->uid q block-has-child-with-str? call-llm-api update-block-string uid->title log get-child-with-str get-child-of-child-with-str-on-page get-open-page-uid get-block-parent-with-order get-focused-block create-struct gen-new-uid default-chat-struct get-todays-uid]]
1010
[ui.extract-data.create-prompts :refer [manual-prompt-guide]]
1111
["@blueprintjs/core" :as bp :refer [ControlGroup Checkbox Tooltip HTMLSelect Button ButtonGroup Card Slider Divider Menu MenuItem Popover MenuDivider]]))
1212

@@ -45,6 +45,7 @@
4545
(go
4646
(let [suggestion-uid (gen-new-uid)
4747
open-page-uid (<p! (get-open-page-uid))
48+
loading-message-uid (gen-new-uid)
4849
dgp-block-uid (block-has-child-with-str? (title->uid "LLM chat settings") "Quick action buttons")
4950
dgp-discourse-graph-page-uid (:uid (get-child-with-str dgp-block-uid "Discourse graph this page"))]
5051
(println "suggestion uid" suggestion-uid "dgp-block-uid" dgp-block-uid "dgp-discourse-graph-page-uid" dgp-discourse-graph-page-uid)
@@ -56,11 +57,12 @@
5657
(fn [resolve _]
5758
(do
5859
(println "create bare struct")
59-
(create-bare-struct open-page-uid suggestion-uid)
60+
(create-bare-struct open-page-uid suggestion-uid loading-message-uid
61+
"Setting this up: This graph does not have a pre-prompt yet, setting up the prompt now...")
6062
(resolve :done))))
6163
(.then (fn []
6264
(println "get prompt")
63-
(manual-prompt-guide dgp-discourse-graph-page-uid)))
65+
(manual-prompt-guide dgp-discourse-graph-page-uid loading-message-uid)))
6466
(.then (fn [prompt]
6567
(reset! pre-prompt prompt)
6668
(println "ask llm" @pre-prompt pre-prompt)
@@ -78,7 +80,11 @@
7880
open-page-uid)))))
7981
(do
8082
(println "pre prompt exists")
81-
(create-bare-struct open-page-uid suggestion-uid)
83+
(create-bare-struct
84+
open-page-uid
85+
suggestion-uid
86+
loading-message-uid
87+
"Asking llm please wait...")
8288
(ask-llm
8389
block-uid
8490
default-model

src/main/ui/extract_data/create_prompts.cljs

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns ui.extract-data.create-prompts
2-
(:require [ui.utils :refer [p q model-mappings call-llm-api gen-new-uid extract-data create-struct]]
2+
(:require [ui.utils :refer [p q update-block-string model-mappings call-llm-api gen-new-uid extract-data create-struct]]
33
[cljs.core.async :refer [chan go <! >! put! close!]]
44
[applied-science.js-interop :as j]))
55

@@ -52,8 +52,9 @@
5252
</example>")
5353

5454

55-
(defn get-dg-node-types [nodes-info]
55+
(defn get-dg-node-types [nodes-info loading-message-uid]
5656
(go
57+
5758
(let [summary-prompt (str
5859
general-dg-system-prompt
5960
"I want you to create summary of all the
@@ -75,13 +76,14 @@
7576

7677
(println "discourse nodes" nodes-info)
7778
(println "summary" llm-generated-summary)
79+
(update-block-string
80+
loading-message-uid
81+
(str "LLM extracted summary of the Discourse graph node types are: "
82+
llm-generated-summary))
7883
{:summary llm-generated-summary
7984
:with-definitions ""})))
8085

8186

82-
83-
84-
8587
(defn extract-example []
8688
(let [node-regex (re-pattern (str "^\\[\\[QUE\\]\\] - (.*?)$"))
8789
some-question (:title (ffirst (q '[:find (pull ?e [:node/title :block/uid])
@@ -95,21 +97,20 @@
9597
"\" This could link to a HYP page proposing a molecular binding mechanism as a hypothesis. The HYP page would in turn link to RES pages that either support or oppose the hypothesis.")))
9698

9799

98-
99-
(defn extract-lab-ontology [nodes-info]
100+
(defn extract-lab-ontology [nodes-info loading-message-uid]
100101
(go
101-
(let [ontology-prompt (str
102-
general-dg-system-prompt
103-
"I want you to extract the lab ontology in the
102+
(let [ontology-prompt (str
103+
general-dg-system-prompt
104+
"I want you to extract the lab ontology in the
104105
<format>
105106
(Chronological node number) (Short-form-used-in-format) Description-extracted-from-the-data
106107
- sub-description if provided
107108
(Next Chronological node number) (Short-form-used-in-format) Description-extracted-from-the-data
108109
- sub-description if provided
109110
</format>
110111
"
111-
dg-nodes-example
112-
"Then your output should be (excluding the codeblock):
112+
dg-nodes-example
113+
"Then your output should be (excluding the codeblock):
113114
```
114115
<exactly-follow-our-lab-ontology>
115116
1. Result (RES) - is a research observation
@@ -121,12 +122,16 @@
121122
Following is the actual data
122123
<node-info>
123124
")
124-
combined-prompt (str ontology-prompt
125-
(str nodes-info)
126-
"</node-info>")
127-
llm-generated-prompt (<! (ask-llm-for-context combined-prompt))]
128-
(println "lab ontology" llm-generated-prompt)
129-
llm-generated-prompt)))
125+
combined-prompt (str ontology-prompt
126+
(str nodes-info)
127+
"</node-info>")
128+
llm-generated-prompt (<! (ask-llm-for-context combined-prompt))]
129+
(println "lab ontology" llm-generated-prompt)
130+
(update-block-string
131+
loading-message-uid
132+
(str "LLM extracted the lab ontology as: "
133+
llm-generated-prompt))
134+
llm-generated-prompt)))
130135

131136
(defn dg-nodes-format [nodes-info]
132137
(reduce
@@ -141,14 +146,18 @@
141146
(extract-node-info all-nodes)
142147
(dg-nodes-format all-nodes)))
143148

144-
(defn manual-prompt-guide [action-button-uid]
149+
(defn manual-prompt-guide [action-button-uid loading-message-uid]
145150
(js/Promise.
146151
(fn [resolve _]
147152
(go
148153
(let [get-all-discourse-nodes (-> (j/call-in js/window [:roamjs :extension :queryBuilder :getDiscourseNodes])
149154
(js->clj :keywordize-keys true))
150155
nodes-info (extract-node-info get-all-discourse-nodes)
151-
dg-node-types (<! (get-dg-node-types nodes-info))
156+
157+
_ (update-block-string
158+
loading-message-uid
159+
"Querying for the discourse graph node types defined in the graph, then asking the llm to present it in predefined summary format.")
160+
dg-node-types (<! (get-dg-node-types nodes-info loading-message-uid))
152161
summary (:summary dg-node-types)
153162
entry-point "Our lab uses Roam Research to organize our collaboration and knowledge sharing."
154163
dg-nodes (str "We capture "
@@ -158,42 +167,54 @@
158167
example (str "\n <example> \n "
159168
(extract-example)
160169
"\n </example> \n")
170+
_ (update-block-string
171+
loading-message-uid
172+
"Extracted the example of a question from the graph.")
161173
your-job (str "<your-job>
162174
\n Based on the text and images provided, propose some new discourse nodes.
163175
\n </your-job> \n")
176+
_ (update-block-string
177+
loading-message-uid
178+
"Using the discourse graph node types defined in the graph, then asking the llm to define the ontology used in our lab.")
164179
lab-ontology (str "\n <instructions> \n
165180
\n <lab-ontology> \n"
166-
(<! (extract-lab-ontology nodes-info))
181+
(<! (extract-lab-ontology nodes-info loading-message-uid))
167182
"\n </lab-ontology> \n")
168183
response-format (str "<expected-response-format> \n
169-
- follow the following format, this is format of the following lines `node type - format to follow if the node is of this type`. For each suggestion put it on a new line."
184+
\n - follow the following format, this is format of the following lines `node type - format to follow if the node is of this type`. For each suggestion put it on a new line."
170185
(dg-nodes-format nodes-info)
171-
" <Important-note> replace the `Source` with actual source. </important-note>\n</expected-response-format>")
172-
general-instructions (str "<general-important-instructions>\n1. following the format does not mean degrading your answer quality. We want both follow the format and high quality suggestions. Make sure your {content} draws directly from the text and images provided.\n2. Please only reply with discourse node suggestions, not explanations, keep them high quality. \n</general-important-instructions>\n</instructions>\n"
186+
" \n <Important-note> replace the `Source` with actual source. </important-note>\n \n</expected-response-format>")
187+
general-instructions (str "\n <general-important-instructions> \n 1. following the format does not mean degrading your answer quality. We want both follow the format and high quality suggestions. Make sure your {content} draws directly from the text and images provided.\n2. Please only reply with discourse node suggestions, not explanations, keep them high quality. \n</general-important-instructions>\n</instructions>\n"
173188
"\n Extracted data from pages:
174-
<data-from-pages> \n")
175-
combined-prompt (str
176-
entry-point
177-
dg-nodes
178-
example
179-
your-job
180-
181-
;; can't use as of now
182-
;dg-nodes-description
183-
lab-ontology
184-
response-format
185-
general-instructions)]
189+
\n <data-from-pages> \n")
190+
combined-prompt (str
191+
entry-point
192+
dg-nodes
193+
example
194+
your-job
195+
196+
;; can't use as of now
197+
;dg-nodes-description
198+
lab-ontology
199+
response-format
200+
general-instructions)]
201+
(update-block-string
202+
loading-message-uid
203+
"LLM created a prompt for this action in your graph, you can see it in your left-sidebar, please check and modify the prompt for future use.")
186204
(let [prompt-uid (gen-new-uid)
205+
pprompt-uid (gen-new-uid)
187206
struct {:s "Prompt"
188207
:c [{:s "Pre-prompt"
208+
:u prompt-uid
189209
:c [{:s combined-prompt
190-
:u prompt-uid}]}]}]
210+
:u pprompt-uid}]}]}]
191211
(create-struct
192212
struct
193213
action-button-uid
194-
nil
195-
false
196-
#(p "created new prompt for dg this page"))
214+
prompt-uid
215+
true
216+
#(p "created new prompt for dg this page")
217+
1)
197218
(resolve combined-prompt)))))))
198219

199220

0 commit comments

Comments
 (0)