Fix Push dialogs into model context

This commit is contained in:
Haiping Chen 2025-03-15 09:29:46 -05:00
parent 292da2aee7
commit a1c73d045a
3 changed files with 13 additions and 9 deletions

View file

@ -99,13 +99,7 @@ public class RealtimeHub : IRealtimeHub
onModelReady: async () =>
{
// Not TriggerModelInference, waiting for user utter.
await _completer.UpdateSession(_conn);
// Push dialogs into model context
foreach (var message in dialogs)
{
await _completer.InsertConversationItem(message);
}
var instruction = await _completer.UpdateSession(_conn);
// Trigger model inference if there is no audio file in the conversation
if (!states.ContainsState("init_audio_file"))
@ -119,6 +113,16 @@ public class RealtimeHub : IRealtimeHub
await _completer.TriggerModelInference("Reply based on the conversation context.");
}
}
else
{
// Push dialogs into model context
foreach (var message in dialogs)
{
await _completer.InsertConversationItem(message);
}
await _completer.TriggerModelInference($"{instruction}\r\n\r\nAssist user without repeating your previous statement.");
}
},
onModelAudioDeltaReceived: async (audioDeltaData, itemId) =>
{

View file

@ -55,7 +55,7 @@ public class TwilioStreamController : TwilioController
if (request.InitAudioFile != null)
{
instruction.SpeechPaths.Add($"twilio/voice/speeches/{request.ConversationId}/{request.InitAudioFile}");
instruction.SpeechPaths.Add(request.InitAudioFile);
}
await HookEmitter.Emit<ITwilioSessionHook>(_services, async hook =>

View file

@ -208,7 +208,7 @@ public class TwilioService
}
else
{
response.Play(new Uri($"{_settings.CallbackHost}/{speechPath}"));
response.Play(new Uri($"{_settings.CallbackHost}/twilio/voice/speeches/{conversationalVoiceResponse.ConversationId}/{speechPath}"));
}
}
}