diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/ChatStreamMiddleware.cs b/src/Plugins/BotSharp.Plugin.ChatHub/ChatStreamMiddleware.cs index cba35a15..171bf0f2 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/ChatStreamMiddleware.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/ChatStreamMiddleware.cs @@ -62,6 +62,7 @@ public class ChatStreamMiddleware var hub = services.GetRequiredService(); var conn = hub.SetHubConnection(conversationId); conn.CurrentAgentId = agentId; + InitEvents(conn); // load conversation and state var convService = services.GetRequiredService(); @@ -128,6 +129,11 @@ public class ChatStreamMiddleware break; } + return (response.Event, data); + } + + private void InitEvents(RealtimeHubConnection conn) + { conn.OnModelMessageReceived = message => JsonSerializer.Serialize(new { @@ -147,7 +153,5 @@ public class ChatStreamMiddleware { @event = "clear" }); - - return (response.Event, data); } } diff --git a/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Realtime/RealTimeCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Realtime/RealTimeCompletionProvider.cs index 2e95cfa2..6838c284 100644 --- a/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Realtime/RealTimeCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Realtime/RealTimeCompletionProvider.cs @@ -329,17 +329,13 @@ public class GoogleRealTimeProvider : IRealTimeCompletion var words = new List(); HookEmitter.Emit(_services, hook => words.AddRange(hook.OnModelTranscriptPrompt(agent)), agent.Id); - var functions = request.Tools?.SelectMany(s => s.FunctionDeclarations).Select(x => + var functions = request.Tools?.SelectMany(s => s.FunctionDeclarations).Select(x => new FunctionDef { - var fn = new FunctionDef - { - Name = x.Name ?? string.Empty, - Description = x.Description ?? string.Empty, - Parameters = x.Parameters != null + Name = x.Name ?? string.Empty, + Description = x.Description ?? string.Empty, + Parameters = x.Parameters != null ? JsonSerializer.Deserialize(JsonSerializer.Serialize(x.Parameters)) : null - }; - return fn; }).ToArray(); await HookEmitter.Emit(_services, diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs index 92fa6f84..3a0902d6 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs @@ -326,15 +326,11 @@ public class RealTimeCompletionProvider : IRealTimeCompletion var (prompt, messages, options) = PrepareOptions(agent, []); var instruction = messages.FirstOrDefault()?.Content.FirstOrDefault()?.Text ?? agent?.Description ?? string.Empty; - var functions = options.Tools.Select(x => + var functions = options.Tools.Select(x => new FunctionDef { - var fn = new FunctionDef - { - Name = x.FunctionName, - Description = x.FunctionDescription - }; - fn.Parameters = JsonSerializer.Deserialize(x.FunctionParameters); - return fn; + Name = x.FunctionName, + Description = x.FunctionDescription, + Parameters = JsonSerializer.Deserialize(x.FunctionParameters) }).ToArray(); var realtimeModelSettings = _services.GetRequiredService();