Update IRealtimeHook
This commit is contained in:
parent
87124c4a21
commit
df0423d917
|
|
@ -6,8 +6,15 @@ namespace BotSharp.Abstraction.Realtime;
|
|||
|
||||
public interface IRealtimeHook : IHookBase
|
||||
{
|
||||
Task OnModelReady(Agent agent, IRealTimeCompletion completer);
|
||||
string[] OnModelTranscriptPrompt(Agent agent);
|
||||
Task OnTranscribeCompleted(RoleDialogModel message, TranscriptionData data);
|
||||
Task<bool> ShouldReconnect(RealtimeHubConnection conn) => Task.FromResult(false);
|
||||
Task OnModelReady(Agent agent, IRealTimeCompletion completer)
|
||||
=> Task.CompletedTask;
|
||||
|
||||
string[] OnModelTranscriptPrompt(Agent agent)
|
||||
=> [];
|
||||
|
||||
Task OnTranscribeCompleted(RoleDialogModel message, TranscriptionData data)
|
||||
=> Task.CompletedTask;
|
||||
|
||||
Task<bool> ShouldReconnect(RealtimeHubConnection conn, RoleDialogModel message)
|
||||
=> Task.FromResult(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,6 +100,17 @@ public class RealtimeHub : IRealtimeHub
|
|||
}
|
||||
|
||||
await routing.InvokeFunction(message.FunctionName, message, options: new() { From = InvokeSource.Llm });
|
||||
|
||||
var hooks = _services.GetHooks<IRealtimeHook>(_conn.CurrentAgentId);
|
||||
foreach (var hook in hooks)
|
||||
{
|
||||
if (await hook.ShouldReconnect(_conn, message))
|
||||
{
|
||||
await _completer.Reconnect(_conn);
|
||||
_logger.LogWarning("Reconnecting to model due to function call: {FunctionName}", message.FunctionName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -117,19 +128,6 @@ public class RealtimeHub : IRealtimeHub
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
var isReconnect = false;
|
||||
var realtimeHooks = _services.GetHooks<IRealtimeHook>(_conn.CurrentAgentId);
|
||||
foreach (var hook in realtimeHooks)
|
||||
{
|
||||
isReconnect = await hook.ShouldReconnect(_conn);
|
||||
if (isReconnect) break;
|
||||
}
|
||||
|
||||
if (isReconnect)
|
||||
{
|
||||
await _completer.Reconnect(_conn);
|
||||
}
|
||||
},
|
||||
onConversationItemCreated: async response =>
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue