Skip to content

Commit 385c067

Browse files
committed
Improve /prompt-show to debug prompts
1 parent 024004c commit 385c067

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/eca/features/chat.clj

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -872,25 +872,26 @@
872872
repo-map*
873873
selected-behavior
874874
config)
875+
image-contents (->> refined-contexts
876+
(filter #(= :image (:type %))))
877+
expanded-prompt-contexts (when-let [contexts-str (-> (f.context/contexts-str-from-prompt message db)
878+
(f.prompt/contexts-str repo-map*))]
879+
[{:type :text :text contexts-str}])
880+
user-messages [{:role "user" :content (concat [{:type :text :text message}]
881+
expanded-prompt-contexts
882+
image-contents)}]
875883
chat-ctx {:chat-id chat-id
876884
:contexts contexts
877885
:behavior selected-behavior
878886
:behavior-config behavior-config
879887
:instructions instructions
888+
:user-messages user-messages
880889
:full-model full-model
881890
:db* db*
882891
:metrics metrics
883892
:config config
884893
:messenger messenger}
885-
decision (message->decision message)
886-
image-contents (->> refined-contexts
887-
(filter #(= :image (:type %))))
888-
expanded-prompt-contexts (when-let [contexts-str (-> (f.context/contexts-str-from-prompt message db)
889-
(f.prompt/contexts-str repo-map*))]
890-
[{:type :text :text contexts-str}])
891-
user-messages [{:role "user" :content (concat [{:type :text :text message}]
892-
expanded-prompt-contexts
893-
image-contents)}]]
894+
decision (message->decision message)]
894895
(swap! db* assoc-in [:chats chat-id :status] :running)
895896
(send-content! chat-ctx :user {:type :text
896897
:text (str message "\n")})

src/eca/features/commands.clj

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
{:name "prompt-show"
114114
:type :native
115115
:description "Prompt sent to LLM as system instructions."
116-
:arguments []}]
116+
:arguments [{:name "optional-prompt"}]}]
117117
custom-cmds (map (fn [custom]
118118
{:name (:name custom)
119119
:type :custom-prompt
@@ -187,7 +187,7 @@
187187
existing-files))
188188
(str "Credential files: None found (GPG available: " (:gpg-available cred-check) ")")))))
189189

190-
(defn handle-command! [command args {:keys [chat-id db* config messenger full-model instructions metrics]}]
190+
(defn handle-command! [command args {:keys [chat-id db* config messenger full-model instructions user-messages metrics]}]
191191
(let [db @db*
192192
custom-cmds (custom-commands config (:workspace-folders db))]
193193
(case command
@@ -254,8 +254,21 @@
254254
:chats {chat-id [{:role "system" :content [{:type :text :text (doctor-msg db config)}]}]}}
255255
"repo-map-show" {:type :chat-messages
256256
:chats {chat-id [{:role "system" :content [{:type :text :text (f.index/repo-map db config {:as-string? true})}]}]}}
257-
"prompt-show" {:type :chat-messages
258-
:chats {chat-id [{:role "system" :content [{:type :text :text instructions}]}]}}
257+
"prompt-show" (let [full-prompt (str "Instructions:\n" instructions "\n"
258+
"Prompt:\n" (reduce
259+
(fn [s {:keys [content]}]
260+
(str
261+
s
262+
(reduce
263+
#(str %1 (string/replace-first (:text %2) "/prompt-show " "") "\n")
264+
""
265+
content)))
266+
""
267+
user-messages))]
268+
{:type :chat-messages
269+
:chats {chat-id [{:role "system"
270+
:content [{:type :text
271+
:text full-prompt}]}]}})
259272

260273
;; else check if a custom command
261274
(if-let [custom-command-prompt (get-custom-command command args custom-cmds)]

0 commit comments

Comments
 (0)