@@ -169,7 +169,7 @@ public class ChatGPTService: ChatGPTServiceType {
169169 role: . user,
170170 content: content,
171171 name: nil ,
172- toolCallContext : nil ,
172+ toolCalls : nil ,
173173 summary: summary,
174174 references: [ ]
175175 )
@@ -222,7 +222,7 @@ public class ChatGPTService: ChatGPTServiceType {
222222
223223 pendingToolCalls = await memory. history
224224 . last { $0. id == sourceMessageId } ?
225- . toolCallContext ? . toolCalls ?? [ ]
225+ . toolCalls ?? [ ]
226226
227227 #if DEBUG
228228 Debugger . didReceiveResponse ( content: reply)
@@ -261,7 +261,7 @@ public class ChatGPTService: ChatGPTServiceType {
261261 return try await Debugger . $id. withValue ( . init( ) ) {
262262 let message = try await sendMemoryAndWait ( )
263263 var finalResult = message? . content
264- var toolCalls = message? . toolCallContext ? . toolCalls
264+ var toolCalls = message? . toolCalls
265265 while let sourceMessageId = message? . id, let calls = toolCalls, !calls. isEmpty {
266266 try Task . checkCancellation ( )
267267 if !configuration. runFunctionsAutomatically {
@@ -273,7 +273,7 @@ public class ChatGPTService: ChatGPTServiceType {
273273 }
274274 guard let nextMessage = try await sendMemoryAndWait ( ) else { break }
275275 finalResult = nextMessage. content
276- toolCalls = nextMessage. toolCallContext ? . toolCalls
276+ toolCalls = nextMessage. toolCalls
277277 }
278278
279279 #if DEBUG
@@ -438,13 +438,11 @@ extension ChatGPTService {
438438 } ( ) ,
439439 content: choice. content,
440440 name: choice. name,
441- toolCallContext: choice. toolCalls. map {
442- . init( toolCalls: $0. map {
443- ChatMessage . ToolCall ( id: $0. id, type: $0. type, function: . init(
444- name: $0. function. name,
445- arguments: $0. function. arguments ?? " "
446- ) )
447- } , responses: [ ] )
441+ toolCalls: choice. toolCalls? . map {
442+ ChatMessage . ToolCall ( id: $0. id, type: $0. type, function: . init(
443+ name: $0. function. name,
444+ arguments: $0. function. arguments ?? " "
445+ ) )
448446 } ,
449447 references: prompt. references
450448 )
@@ -589,7 +587,7 @@ extension ChatGPTService {
589587 } ( ) ,
590588 content: chatMessage. content ?? " " ,
591589 name: chatMessage. name,
592- toolCalls: chatMessage. toolCallContext ? . toolCalls. map {
590+ toolCalls: chatMessage. toolCalls? . map {
593591 . init(
594592 id: $0. id,
595593 type: $0. type,
@@ -601,14 +599,12 @@ extension ChatGPTService {
601599 }
602600 ) )
603601
604- if let responses = chatMessage. toolCallContext? . responses {
605- for response in responses {
606- all. append ( ChatCompletionsRequestBody . Message (
607- role: . tool,
608- content: response. content,
609- toolCallId: response. id
610- ) )
611- }
602+ for call in chatMessage. toolCalls ?? [ ] {
603+ all. append ( ChatCompletionsRequestBody . Message (
604+ role: . tool,
605+ content: call. response. content,
606+ toolCallId: call. response. id
607+ ) )
612608 }
613609
614610 return all
0 commit comments