Skip to content

Commit a8ae9e7

Browse files
committed
Improve tools and fix tool call output for openai
1 parent 641a98f commit a8ae9e7

5 files changed

Lines changed: 10 additions & 23 deletions

File tree

src/eca/features/chat.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050

5151
(defn ^:private behavior->behavior-str [behavior]
5252
(case behavior
53-
"chat" "Help with code changes when applicable, answer questions, and provide explanations."
54-
"agent" "Help with code changes when applicable but suggest you do the changes itself, answer questions, and provide explanations."))
53+
"chat" "Help with code changes only if user requested/agreed, ask first before do changes, answer questions, and provide explanations."
54+
"agent" "Help with code changes when applicable, suggesting you do the changes itself, answer questions, and provide explanations."))
5555

5656
(defn default-model [db]
5757
(if-let [ollama-model (first (filter #(string/starts-with? % config/ollama-model-prefix) (vals (:models db))))]

src/eca/features/tools/filesystem.clj

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,13 @@
6060
(or (invalid-arguments arguments (concat (path-validations db)
6161
[["pattern" #(not (string/blank? %)) "Invalid glob pattern '$pattern'"]]))
6262
(let [pattern (get arguments "pattern")
63-
;; Normalize pattern - if it doesn't contain wildcards, wrap with wildcards
64-
normalized-pattern (if (string/includes? pattern "*")
65-
pattern
66-
(format "*%s*" pattern))
67-
;; Convert glob pattern to regex for case-insensitive matching
68-
pattern-regex (-> normalized-pattern
69-
(string/replace "*" ".*")
70-
(string/replace "?" ".")
71-
(str "(?i)") ; Case-insensitive flag
72-
re-pattern)
63+
pattern (if (string/includes? pattern "*")
64+
pattern
65+
(format "**/*%s*/**" pattern))
7366
paths (reduce
7467
(fn [paths {:keys [uri]}]
75-
(let [root-path (shared/uri->filename uri)]
76-
(concat paths
77-
(filter (fn [path]
78-
(let [filename (fs/file-name path)]
79-
(re-matches pattern-regex filename)))
80-
(fs/glob root-path "**/*")))))
68+
(concat paths (fs/glob (shared/uri->filename uri)
69+
pattern)))
8170
[]
8271
(:workspace-folders db))]
8372
(single-text-content (if (seq paths)

src/eca/llm_providers/openai.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@
5353
"tool_call" {:type "function_call"
5454
:name (:name content)
5555
:call_id (:id content)
56-
:arguments (:arguments content)}
56+
:arguments (json/generate-string (:arguments content))}
5757
"tool_call_output"
5858
{:type "function_call_output"
59-
:name (:name content)
6059
:call_id (:id content)
6160
:output (llm-util/stringfy-tool-result content)}
6261
msg))

test/eca/features/tools/filesystem_test.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@
148148
(h/file-path "/project/foo/qux.txt"))}]}
149149
(with-redefs [fs/exists? (constantly true)
150150
fs/glob (constantly [(fs/path (h/file-path "/project/foo/bar/baz.txt"))
151-
(fs/path (h/file-path "/project/foo/qux.txt"))
152-
(fs/path (h/file-path "/project/foo/bar/baz.clj"))])]
151+
(fs/path (h/file-path "/project/foo/qux.txt"))])]
153152
((get-in f.tools.filesystem/definitions ["search_files" :handler])
154153
{"path" (h/file-path "/project/foo")
155154
"pattern" ".txt"}

test/eca/llm_providers/openai_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
{:type "function_call"
2626
:call_id "call-1"
2727
:name "list_allowed_directories"
28-
:arguments {}}
28+
:arguments "{}"}
2929
{:type "function_call_output"
3030
:call_id "call-1"
3131
:output "Allowed directories: /foo/bar\n"}

0 commit comments

Comments
 (0)