Skip to content

Commit 125b234

Browse files
committed
Fix openai tool calling
1 parent f17e274 commit 125b234

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

core/src/voice_fn/processors/llm_context_aggregator.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ S: Start, E: End, T: Transcription, I: Interim, X: Text
176176
:tool_calls [{:id tool-call-id
177177
:type :function
178178
:function {:name function-name
179-
:arguments (u/parse-if-json function-arguments)}}]}
179+
:arguments function-arguments}}]}
180180
{:role :assistant
181181
:content [{:type :text
182182
:text content-aggregation}]})]
@@ -289,7 +289,7 @@ S: Start, E: End, T: Transcription, I: Interim, X: Text
289289
(let [tool-call (context->tool-call frame)
290290
tool-id (:id tool-call)
291291
fname (get-in tool-call [:function :name])
292-
args (get-in tool-call [:function :arguments])
292+
args (u/parse-if-json (get-in tool-call [:function :arguments]))
293293
rt (get registered-tools fname)
294294
f (:tool rt)
295295
async? (:async? rt)]

core/src/voice_fn/processors/openai.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
[;; GPT-4 Models
5151
"gpt-4"
5252
"gpt-4-32k"
53-
"gpt-4-1106-preview" ;; GPT-4 Turbo
54-
"gpt-4-vision-preview" ;; GPT-4 Vision
53+
"gpt-4-1106-preview" ;; GPT-4 Turbo
54+
"gpt-4-vision-preview" ;; GPT-4 Vision
5555
;; GPT-3.5 Models
5656
"gpt-3.5-turbo"
5757
"gpt-3.5-turbo-16k"

core/test/voice_fn/processors/llm_context_aggregator_test.clj

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
(fact "if new context is tool call result, send it forward"
125125
(let [new-context {:messages [{:role "system", :content "You are a voice agent operating via phone. Be concise. The input you receive comes from a speech-to-text (transcription) system that isn't always efficient and may send unclear text. Ask for clarification when you're unsure what the person said."}
126126
{:role "user", :content "What's the weather in New York?"}
127-
{:role :assistant, :tool_calls [{:id "call_LCEOwyJ6wsqC5rzJRH0uMnR8", :type :function, :function {:name "get_weather", :arguments {:town "New York"}}}]}
127+
{:role :assistant, :tool_calls [{:id "call_LCEOwyJ6wsqC5rzJRH0uMnR8", :type :function, :function {:name "get_weather", :arguments "{\"town\":\"New York\"}"}}]}
128128
{:role :tool, :content [{:type :text, :text "The weather in New York is 17 degrees celsius"}], :tool_call_id "call_LCEOwyJ6wsqC5rzJRH0uMnR8"}]
129129
:tools [{:type :function
130130
:function {:name "get_weather"
@@ -256,10 +256,7 @@
256256
:role "assistant"}
257257
{:content "Hello there" :role "user"}
258258
{:role :assistant
259-
:tool_calls [{:function {:arguments {:date "2023-10-10"
260-
:fields ["price"
261-
"volume"]
262-
:ticker "MSFT"}
259+
:tool_calls [{:function {:arguments "{\"ticker\":\"MSFT\",\"fields\":[\"price\",\"volume\"],\"date\":\"2023-10-10\"}"
263260
:name "retrieve_latest_stock_data"}
264261
:id "call_frPVnoe8ruDicw50T8sLHki7"
265262
:type :function}]}]}}
@@ -269,9 +266,7 @@
269266
(:frame/data out-frame) => {:messages [{:content "You are a helpful assistant" :role "assistant"}
270267
{:content "Hello there" :role "user"}
271268
{:role :assistant
272-
:tool_calls [{:function {:arguments {:date "2023-10-10"
273-
:fields ["price" "volume"]
274-
:ticker "MSFT"}
269+
:tool_calls [{:function {:arguments "{\"ticker\":\"MSFT\",\"fields\":[\"price\",\"volume\"],\"date\":\"2023-10-10\"}"
275270
:name "retrieve_latest_stock_data"}
276271
:id "call_frPVnoe8ruDicw50T8sLHki7"
277272
:type :function}]}]}))))

0 commit comments

Comments
 (0)