Merge pull request #947 from hchen2020/master

Fix Push dialogs into model context
This commit is contained in:
Haiping 2025-03-15 09:31:54 -05:00 committed by GitHub
commit 72df520c8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 9 deletions

View file

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

View file

@ -55,7 +55,7 @@ public class TwilioStreamController : TwilioController
if (request.InitAudioFile != null) 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 => await HookEmitter.Emit<ITwilioSessionHook>(_services, async hook =>

View file

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