File tree Expand file tree Collapse file tree 2 files changed +8
-0
lines changed
src/backend/src/modules/puterai Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -684,6 +684,10 @@ class AIChatService extends BaseService {
684684 message : e . message ,
685685 } ) + '\n' ) ;
686686 stream . end ( ) ;
687+ } finally {
688+ if ( ret . result . value . finally_fn ) {
689+ await ret . result . value . finally_fn ( ) ;
690+ }
687691 }
688692 } ) ( ) ;
689693
Original file line number Diff line number Diff line change @@ -161,6 +161,7 @@ module.exports = class OpenAIUtil {
161161 deviations,
162162 stream, completion, moderate,
163163 usage_calculator,
164+ finally_fn,
164165 } ) {
165166 deviations = Object . assign ( {
166167 // affected by: Mistral
@@ -181,6 +182,7 @@ module.exports = class OpenAIUtil {
181182 return new TypedValue ( { $ : 'ai-chat-intermediate' } , {
182183 stream : true ,
183184 init_chat_stream,
185+ finally_fn,
184186 usage_promise : usage_promise . then ( usage => {
185187 return usage_calculator ? usage_calculator ( { usage } ) : {
186188 input_tokens : usage . prompt_tokens ,
@@ -190,6 +192,8 @@ module.exports = class OpenAIUtil {
190192 } ) ;
191193 }
192194
195+ if ( finally_fn ) await finally_fn ( ) ;
196+
193197 const is_empty = completion . choices ?. [ 0 ] ?. message ?. content ?. trim ( ) === '' ;
194198 if ( is_empty && ! completion . choices ?. [ 0 ] ?. message ?. tool_calls ) {
195199 // GPT refuses to generate an empty response if you ask it to,
You can’t perform that action at this time.
0 commit comments