@@ -105,13 +105,17 @@ public protocol ChatGPTServiceType {
105105
106106public class ChatGPTService : ChatGPTServiceType {
107107 public var configuration : ChatGPTConfiguration
108+ public var utilityConfiguration : ChatGPTConfiguration
108109 public var functionProvider : ChatGPTFunctionProvider
109110
110111 public init (
111112 configuration: ChatGPTConfiguration = UserPreferenceChatGPTConfiguration ( ) ,
113+ utilityConfiguration: ChatGPTConfiguration =
114+ UserPreferenceChatGPTConfiguration ( chatModelKey: \. preferredChatModelIdForUtilities) ,
112115 functionProvider: ChatGPTFunctionProvider = NoChatGPTFunctionProvider ( )
113116 ) {
114117 self . configuration = configuration
118+ self . utilityConfiguration = utilityConfiguration
115119 self . functionProvider = functionProvider
116120 }
117121
@@ -141,7 +145,15 @@ public class ChatGPTService: ChatGPTServiceType {
141145
142146 if !pendingToolCalls. isEmpty {
143147 if configuration. runFunctionsAutomatically {
144- var toolCallStatuses = [ String: String] ( )
148+ var toolCallStatuses = [ String: String] ( ) {
149+ didSet {
150+ if toolCallStatuses != oldValue {
151+ continuation. yield ( . status(
152+ Array ( toolCallStatuses. values) . sorted ( )
153+ ) )
154+ }
155+ }
156+ }
145157 for toolCall in pendingToolCalls {
146158 let id = toolCall. id
147159 for await response in await runFunctionCall (
@@ -158,15 +170,11 @@ public class ChatGPTService: ChatGPTServiceType {
158170 ) )
159171 case let . status( status) :
160172 toolCallStatuses [ id] = status
161- continuation
162- . yield ( . status( Array ( toolCallStatuses. values) ) )
163173 }
164174 }
165175 toolCallStatuses [ id] = nil
166- continuation
167- . yield ( . status( Array ( toolCallStatuses. values) ) )
168176 }
169- continuation . yield ( . status ( [ ] ) )
177+ toolCallStatuses = [ : ]
170178 } else {
171179 if !configuration. runFunctionsAutomatically {
172180 continuation. yield ( . toolCalls( pendingToolCalls) )
@@ -190,7 +198,15 @@ public class ChatGPTService: ChatGPTServiceType {
190198
191199 case let . partialToolCalls( toolCalls) :
192200 guard configuration. runFunctionsAutomatically else { break }
193- var toolCallStatuses = [ String: String] ( )
201+ var toolCallStatuses = [ String: String] ( ) {
202+ didSet {
203+ if toolCallStatuses != oldValue {
204+ continuation. yield ( . status(
205+ Array ( toolCallStatuses. values) . sorted ( )
206+ ) )
207+ }
208+ }
209+ }
194210 for toolCall in toolCalls. keys. sorted ( ) {
195211 if let toolCallValue = toolCalls [ toolCall] {
196212 for await status in await prepareFunctionCall (
@@ -199,8 +215,6 @@ public class ChatGPTService: ChatGPTServiceType {
199215 sourceMessageId: sourceMessageId
200216 ) {
201217 toolCallStatuses [ toolCallValue. id] = status
202- continuation
203- . yield ( . status( Array ( toolCallStatuses. values) ) )
204218 }
205219 }
206220 }
@@ -489,9 +503,7 @@ extension ChatGPTService {
489503
490504 let service = ChatGPTService (
491505 configuration: OverridingChatGPTConfiguration (
492- overriding: UserPreferenceChatGPTConfiguration (
493- chatModelKey: \. preferredChatModelIdForUtilities
494- ) ,
506+ overriding: utilityConfiguration,
495507 with: . init( temperature: 0 )
496508 ) ,
497509 functionProvider: NoChatGPTFunctionProvider ( )
0 commit comments