From 58590a5f803978cf7cf877607efcd6dce8041253 Mon Sep 17 00:00:00 2001 From: Arkadiusz Malka Date: Mon, 2 Jun 2025 20:39:56 +0200 Subject: [PATCH] Add logging for invalid WebSocket payloads and new properties - Introduced `LogConnectionClosedWithInvalidPyload` method in `MultiModalLiveClientLoggingExtensions` to log errors for WebSocket closures due to invalid payloads. - Updated `MultiModalLiveClient` to log close status descriptions for invalid payloads. - Added `OutputAudioTranscription` and `InputAudioTranscription` properties to `BidiGenerateContentSetup`, initialized with new instances. - Created a new class `OutputAudioTranscription` for handling audio transcription data. --- src/GenerativeAI.Live/Logging/LoggingExtensions.cs | 3 +++ src/GenerativeAI.Live/Models/MultiModalLiveClient.cs | 5 +++++ .../Types/MultimodalLive/BidiGenerateContentSetup.cs | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/GenerativeAI.Live/Logging/LoggingExtensions.cs b/src/GenerativeAI.Live/Logging/LoggingExtensions.cs index aea71703..640053f0 100644 --- a/src/GenerativeAI.Live/Logging/LoggingExtensions.cs +++ b/src/GenerativeAI.Live/Logging/LoggingExtensions.cs @@ -47,4 +47,7 @@ public static partial class MultiModalLiveClientLoggingExtensions [LoggerMessage(EventId = 112, Level = LogLevel.Information, Message = "Calling function: {FunctionName}")] public static partial void LogFunctionCall(this ILogger logger, string functionName); + + [LoggerMessage(EventId = 113, Level = LogLevel.Error, Message = "WebSocket connection closed caused by invalid payload: {CloseStatusDescription}")] + public static partial void LogConnectionClosedWithInvalidPyload(this ILogger logger, string closeStatusDescription); } \ No newline at end of file diff --git a/src/GenerativeAI.Live/Models/MultiModalLiveClient.cs b/src/GenerativeAI.Live/Models/MultiModalLiveClient.cs index 180911e2..88c138b2 100644 --- a/src/GenerativeAI.Live/Models/MultiModalLiveClient.cs +++ b/src/GenerativeAI.Live/Models/MultiModalLiveClient.cs @@ -429,6 +429,11 @@ public async Task ConnectAsync(bool autoSendSetup = true,CancellationToken cance _logger?.LogConnectionClosedWithError(info.Type, info.Exception!); ErrorOccurred?.Invoke(this, new ErrorEventArgs(info.Exception!)); } + else if (info.CloseStatus == WebSocketCloseStatus.InvalidPayloadData) + { + //log info.CloseStatusDescription + _logger?.LogConnectionClosedWithInvalidPyload(info.CloseStatusDescription!); + } else { _logger?.LogConnectionClosed(); diff --git a/src/GenerativeAI/Types/MultimodalLive/BidiGenerateContentSetup.cs b/src/GenerativeAI/Types/MultimodalLive/BidiGenerateContentSetup.cs index 64f9c951..6b1c8a4b 100644 --- a/src/GenerativeAI/Types/MultimodalLive/BidiGenerateContentSetup.cs +++ b/src/GenerativeAI/Types/MultimodalLive/BidiGenerateContentSetup.cs @@ -43,4 +43,14 @@ public class BidiGenerateContentSetup /// [JsonPropertyName("tools")] public Tool[]? Tools { get; set; } + + [JsonPropertyName("outputAudioTranscription")] + public OutputAudioTranscription? OutputAudioTranscription { get; set; } = new OutputAudioTranscription(); + + [JsonPropertyName("inputAudioTranscription")] + public OutputAudioTranscription? InputAudioTranscription { get; set; } +} +public class OutputAudioTranscription +{ + } \ No newline at end of file