Skip to content

Commit 141cf68

Browse files
committed
Add assistant aggregator test for tool use with no argument
1 parent d6ac4d3 commit 141cf68

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

test/voice_fn/mock_data.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@
111111
:model "gpt-4o-mini-2024-07-18"}
112112
:done])
113113

114+
(def mock-tool-call-response-single-argument
115+
[{:service_tier "default", :created 1738211745, :choices [{:finish_reason nil, :index 0, :logprobs nil, :delta {:role "assistant", :content nil, :refusal nil, :tool_calls [{:index 0, :type "function", :function {:arguments "", :name "end_call"}, :id "call_J9MSffmnxdPj8r28tNzCO8qj"}]}}], :system_fingerprint "fp_bd83329f63", :id "chatcmpl-AvGZFNfbFY8QqV8JXsIlWn3E9Yp2o", :object "chat.completion.chunk", :model "gpt-4o-mini-2024-07-18"}
116+
{:service_tier "default", :created 1738211745, :choices [{:finish_reason nil, :index 0, :logprobs nil, :delta {:tool_calls [{:index 0, :function {:arguments "{}"}}]}}], :system_fingerprint "fp_bd83329f63", :id "chatcmpl-AvGZFNfbFY8QqV8JXsIlWn3E9Yp2o", :object "chat.completion.chunk", :model "gpt-4o-mini-2024-07-18"}
117+
{:service_tier "default", :created 1738211745, :choices [{:finish_reason "tool_calls", :index 0, :logprobs nil, :delta {}}], :system_fingerprint "fp_bd83329f63", :id "chatcmpl-AvGZFNfbFY8QqV8JXsIlWn3E9Yp2o", :object "chat.completion.chunk", :model "gpt-4o-mini-2024-07-18"}
118+
:done])
119+
114120
(def twilio-start-event
115121
{:sequenceNumber "1"
116122
:streamSid "MZ48f5da1eae19d83dcc3782e4ed89a45d"

test/voice_fn/processors/llm_context_aggregator_test.clj

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,44 @@
278278
:name "retrieve_latest_stock_data"}
279279
:id "call_frPVnoe8ruDicw50T8sLHki7"
280280
:type :function}]}]}))
281+
(fact "Handles tool calls with no arguments"
282+
(let [final-state (reduce (fn [current-state frame]
283+
(let [[next-state] (sut/assistant-aggregator-transform
284+
current-state
285+
nil
286+
frame)]
287+
next-state))
288+
sstate
289+
(map chunk->frame mock/mock-tool-call-response-single-argument))
290+
;; Final state after end frame
291+
[next-state {:keys [out tool-write]}] (sut/assistant-aggregator-transform
292+
final-state
293+
nil
294+
(frame/llm-full-response-end true))
295+
out-frame (first out)
296+
tool-write-frame (first tool-write)]
297+
next-state => {:content-aggregation nil
298+
:function-arguments nil
299+
:function-name nil
300+
:tool-call-id nil
301+
:llm/context {:messages [{:content "You are a helpful assistant"
302+
:role "assistant"}
303+
{:content "Hello there" :role "user"}
304+
{:role :assistant
305+
:tool_calls [{:function {:arguments "{}"
306+
:name "end_call"}
307+
:id "call_J9MSffmnxdPj8r28tNzCO8qj"
308+
:type :function}]}]}}
309+
(= out-frame tool-write-frame) => true
310+
311+
(:frame/type out-frame) => :frame.llm/context
312+
(:frame/data out-frame) => {:messages [{:content "You are a helpful assistant" :role "assistant"}
313+
{:content "Hello there" :role "user"}
314+
{:role :assistant
315+
:tool_calls [{:function {:arguments "{}"
316+
:name "end_call"}
317+
:id "call_J9MSffmnxdPj8r28tNzCO8qj"
318+
:type :function}]}]}))
281319
(fact
282320
"Handles system-config-change frames"
283321
(let [nc {:messages [{:role :system

0 commit comments

Comments
 (0)