|
5 | 5 | [clojure.set :as set] |
6 | 6 | [clojure.string :as string] |
7 | 7 | [eca.features.index :as f.index] |
| 8 | + [eca.features.prompt :as f.prompt] |
8 | 9 | [eca.features.rules :as f.rules] |
9 | 10 | [eca.features.tools :as f.tools] |
10 | 11 | [eca.llm-api :as llm-api] |
|
32 | 33 | "repoMap" [{:type :repoMap}])) |
33 | 34 | contexts)) |
34 | 35 |
|
35 | | -(defn ^:private build-context-str [refined-contexts rules repo-map*] |
36 | | - (str |
37 | | - "<rules>\n" |
38 | | - (reduce |
39 | | - (fn [rule-str {:keys [name content]}] |
40 | | - (str rule-str (format "<rule name=\"%s\">%s</rule>\n" name content))) |
41 | | - "" |
42 | | - rules) |
43 | | - "</rules>\n" |
44 | | - "<contexts>\n" |
45 | | - (reduce |
46 | | - (fn [context-str {:keys [type path content]}] |
47 | | - (str context-str (case type |
48 | | - :file (format "<file path=\"%s\">%s</file>\n" path content) |
49 | | - :repoMap (format "<repoMap description=\"Workspaces structure in a tree view, spaces represent file hierarchy\" >%s</repoMap>" @repo-map*) |
50 | | - ""))) |
51 | | - "" |
52 | | - refined-contexts) |
53 | | - "</contexts>")) |
54 | | - |
55 | | -(defn ^:private behavior->behavior-str [behavior] |
56 | | - (case behavior |
57 | | - "chat" "Help with code changes only if user requested/agreed, ask first before do changes, answer questions, and provide explanations." |
58 | | - "agent" "Help with code changes when applicable, suggesting you do the changes itself, answer questions, and provide explanations.")) |
59 | | - |
60 | 36 | (defn default-model [db config] |
61 | 37 | (llm-api/default-model db config)) |
62 | 38 |
|
|
115 | 91 | :state :running |
116 | 92 | :text "Parsing given context"})) |
117 | 93 | db @db* |
118 | | - rules (f.rules/all config |
119 | | - (:workspace-folders db) |
120 | | - {:behavior (behavior->behavior-str (or behavior (:chat-default-behavior db)))}) |
| 94 | + rules (f.rules/all config (:workspace-folders db)) |
121 | 95 | refined-contexts (raw-contexts->refined contexts) |
122 | 96 | manual-approval? (get-in config [:toolCall :manualApproval] false) |
123 | 97 | repo-map* (delay (f.index/repo-map db {:as-string? true})) |
124 | | - context-str (build-context-str refined-contexts rules repo-map*) |
| 98 | + instructions (f.prompt/build-instructions refined-contexts rules repo-map* (or behavior (:chat-default-behavior db))) |
125 | 99 | chosen-model (or model (default-model db config)) |
126 | 100 | past-messages (get-in db [:chats chat-id :messages] []) |
127 | 101 | user-prompt message |
|
140 | 114 | {:model chosen-model |
141 | 115 | :model-config (get-in db [:models chosen-model]) |
142 | 116 | :user-prompt user-prompt |
143 | | - :context context-str |
| 117 | + :instructions instructions |
144 | 118 | :past-messages past-messages |
145 | 119 | :config config |
146 | 120 | :tools all-tools |
|
0 commit comments