|
1 | 1 | (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]] |
3 | 3 | [cljs.core.async :refer [chan go <! >! put! close!]] |
4 | 4 | [applied-science.js-interop :as j])) |
5 | 5 |
|
|
52 | 52 | </example>") |
53 | 53 |
|
54 | 54 |
|
55 | | -(defn get-dg-node-types [nodes-info] |
| 55 | +(defn get-dg-node-types [nodes-info loading-message-uid] |
56 | 56 | (go |
| 57 | + |
57 | 58 | (let [summary-prompt (str |
58 | 59 | general-dg-system-prompt |
59 | 60 | "I want you to create summary of all the |
|
75 | 76 |
|
76 | 77 | (println "discourse nodes" nodes-info) |
77 | 78 | (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)) |
78 | 83 | {:summary llm-generated-summary |
79 | 84 | :with-definitions ""}))) |
80 | 85 |
|
81 | 86 |
|
82 | | - |
83 | | - |
84 | | - |
85 | 87 | (defn extract-example [] |
86 | 88 | (let [node-regex (re-pattern (str "^\\[\\[QUE\\]\\] - (.*?)$")) |
87 | 89 | some-question (:title (ffirst (q '[:find (pull ?e [:node/title :block/uid]) |
|
95 | 97 | "\" 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."))) |
96 | 98 |
|
97 | 99 |
|
98 | | - |
99 | | -(defn extract-lab-ontology [nodes-info] |
| 100 | +(defn extract-lab-ontology [nodes-info loading-message-uid] |
100 | 101 | (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 |
104 | 105 | <format> |
105 | 106 | (Chronological node number) (Short-form-used-in-format) Description-extracted-from-the-data |
106 | 107 | - sub-description if provided |
107 | 108 | (Next Chronological node number) (Short-form-used-in-format) Description-extracted-from-the-data |
108 | 109 | - sub-description if provided |
109 | 110 | </format> |
110 | 111 | " |
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): |
113 | 114 | ``` |
114 | 115 | <exactly-follow-our-lab-ontology> |
115 | 116 | 1. Result (RES) - is a research observation |
|
121 | 122 | Following is the actual data |
122 | 123 | <node-info> |
123 | 124 | ") |
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))) |
130 | 135 |
|
131 | 136 | (defn dg-nodes-format [nodes-info] |
132 | 137 | (reduce |
|
141 | 146 | (extract-node-info all-nodes) |
142 | 147 | (dg-nodes-format all-nodes))) |
143 | 148 |
|
144 | | -(defn manual-prompt-guide [action-button-uid] |
| 149 | +(defn manual-prompt-guide [action-button-uid loading-message-uid] |
145 | 150 | (js/Promise. |
146 | 151 | (fn [resolve _] |
147 | 152 | (go |
148 | 153 | (let [get-all-discourse-nodes (-> (j/call-in js/window [:roamjs :extension :queryBuilder :getDiscourseNodes]) |
149 | 154 | (js->clj :keywordize-keys true)) |
150 | 155 | 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)) |
152 | 161 | summary (:summary dg-node-types) |
153 | 162 | entry-point "Our lab uses Roam Research to organize our collaboration and knowledge sharing." |
154 | 163 | dg-nodes (str "We capture " |
|
158 | 167 | example (str "\n <example> \n " |
159 | 168 | (extract-example) |
160 | 169 | "\n </example> \n") |
| 170 | + _ (update-block-string |
| 171 | + loading-message-uid |
| 172 | + "Extracted the example of a question from the graph.") |
161 | 173 | your-job (str "<your-job> |
162 | 174 | \n Based on the text and images provided, propose some new discourse nodes. |
163 | 175 | \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.") |
164 | 179 | lab-ontology (str "\n <instructions> \n |
165 | 180 | \n <lab-ontology> \n" |
166 | | - (<! (extract-lab-ontology nodes-info)) |
| 181 | + (<! (extract-lab-ontology nodes-info loading-message-uid)) |
167 | 182 | "\n </lab-ontology> \n") |
168 | 183 | 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." |
170 | 185 | (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" |
173 | 188 | "\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.") |
186 | 204 | (let [prompt-uid (gen-new-uid) |
| 205 | + pprompt-uid (gen-new-uid) |
187 | 206 | struct {:s "Prompt" |
188 | 207 | :c [{:s "Pre-prompt" |
| 208 | + :u prompt-uid |
189 | 209 | :c [{:s combined-prompt |
190 | | - :u prompt-uid}]}]}] |
| 210 | + :u pprompt-uid}]}]}] |
191 | 211 | (create-struct |
192 | 212 | struct |
193 | 213 | 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) |
197 | 218 | (resolve combined-prompt))))))) |
198 | 219 |
|
199 | 220 |
|
|
0 commit comments