@@ -729,32 +729,39 @@ private async Task SendToWebSocketAsync(WebSocket socket, object message)
729
729
730
730
private async Task SendSessionUpdateAsync ( WebSocket openAiWebSocket , Domain . AISpeechAssistant . AiSpeechAssistant assistant , string prompt )
731
731
{
732
- var tools = await InitialSessionToolsAsync ( assistant ) . ConfigureAwait ( false ) ;
732
+ var configs = await InitialSessionConfigAsync ( assistant ) . ConfigureAwait ( false ) ;
733
733
734
734
var sessionUpdate = new
735
735
{
736
736
type = "session.update" ,
737
737
session = new
738
738
{
739
- turn_detection = new { type = "server_vad" } ,
739
+ turn_detection = InitialSessionTurnDirection ( configs ) ,
740
740
input_audio_format = "g711_ulaw" ,
741
741
output_audio_format = "g711_ulaw" ,
742
742
voice = string . IsNullOrEmpty ( assistant . Voice ) ? "alloy" : assistant . Voice ,
743
743
instructions = prompt ,
744
744
modalities = new [ ] { "text" , "audio" } ,
745
745
temperature = 0.8 ,
746
746
input_audio_transcription = new { model = "whisper-1" } ,
747
- tools = tools
747
+ tools = configs . Where ( x => x . Type == AiSpeechAssistantSessionConfigType . Tool ) . Select ( x => x . Config )
748
748
}
749
749
} ;
750
750
751
751
await SendToWebSocketAsync ( openAiWebSocket , sessionUpdate ) ;
752
752
}
753
753
754
- private async Task < IEnumerable < OpenAiRealtimeToolDto > > InitialSessionToolsAsync ( Domain . AISpeechAssistant . AiSpeechAssistant assistant , CancellationToken cancellationToken = default )
754
+ private async Task < List < ( AiSpeechAssistantSessionConfigType Type , object Config ) > > InitialSessionConfigAsync ( Domain . AISpeechAssistant . AiSpeechAssistant assistant , CancellationToken cancellationToken = default )
755
755
{
756
756
var functions = await _aiSpeechAssistantDataProvider . GetAiSpeechAssistantFunctionCallByAssistantIdAsync ( assistant . Id , cancellationToken ) . ConfigureAwait ( false ) ;
757
757
758
- return functions . Count == 0 ? [ ] : functions . Where ( x => ! string . IsNullOrWhiteSpace ( x . Content ) ) . Select ( x => JsonConvert . DeserializeObject < OpenAiRealtimeToolDto > ( x . Content ) ) ;
758
+ return functions . Count == 0 ? [ ] : functions . Where ( x => ! string . IsNullOrWhiteSpace ( x . Content ) ) . Select ( x => ( x . Type , JsonConvert . DeserializeObject < object > ( x . Content ) ) ) . ToList ( ) ;
759
759
}
760
+
761
+ private object InitialSessionTurnDirection ( List < ( AiSpeechAssistantSessionConfigType Type , object Config ) > configs )
762
+ {
763
+ var turnDetection = configs . FirstOrDefault ( x => x . Type == AiSpeechAssistantSessionConfigType . TurnDirection ) ;
764
+
765
+ return turnDetection . Config ?? new { type = "server_vad" } ;
766
+ }
760
767
}
0 commit comments