Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Apps.OpenAI/Actions/AudioActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Blackbird.Applications.Sdk.Common.Invocation;
using Blackbird.Applications.Sdk.Utils.Extensions.Files;
using Blackbird.Applications.SDK.Extensions.FileManagement.Interfaces;
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -77,14 +76,14 @@ public async Task<TranscriptionResponse> CreateTranscription(
}

var response = await UniversalClient.ExecuteWithErrorHandling<TranscriptionDto>(request);
var words = response.Words?.Select(x => new WordResponse(x)).ToList() ?? new List<WordResponse>();
var segments = response.Segments?.Select(x => new SegmentResponse(x)).ToList() ?? new List<SegmentResponse>();
var words = response.Words?.Select(x => new WordResponse(x)).ToList() ?? [];
var segments = response.Segments?.Select(x => new SegmentResponse(x)).ToList() ?? [];

return new()
{
Transcription = BuildTranscription(response, isDiarizationModel),
Words = JsonConvert.SerializeObject(words),
Segments = JsonConvert.SerializeObject(segments)
Words = words,
Segments = segments
};

static string GetResponseFormat(string model) => model switch
Expand Down
2 changes: 1 addition & 1 deletion Apps.OpenAI/Apps.OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Product>OpenAI</Product>
<Description>Creating safe artificial general intelligence that benefits all of humanity</Description>
<Version>2.8.42</Version>
<Version>2.8.43</Version>
<AssemblyName>Apps.OpenAI</AssemblyName>
</PropertyGroup>

Expand Down
15 changes: 8 additions & 7 deletions Apps.OpenAI/Models/Responses/Audio/TranscriptionResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Apps.OpenAI.Dtos;
using System.Collections.Generic;
using Apps.OpenAI.Dtos;
using Blackbird.Applications.Sdk.Common;

namespace Apps.OpenAI.Models.Responses.Audio;
Expand All @@ -7,14 +8,14 @@ public class TranscriptionResponse
{
public string Transcription { get; set; }

[Display("Words (serialized)")]
public string Words { get; set; }
[Display("Words")]
public List<WordResponse> Words { get; set; }

[Display("Segments (serialized)")]
public string Segments { get; set; }
[Display("Segments")]
public List<SegmentResponse> Segments { get; set; }
}

public record WordResponse(WordDto dto)
public class WordResponse(WordDto dto)
{
public string Word { get; set; } = dto.Word;

Expand All @@ -23,7 +24,7 @@ public record WordResponse(WordDto dto)
public double End { get; set; } = dto.End;
}

public record SegmentResponse(SegmentDto dto)
public class SegmentResponse(SegmentDto dto)
{
[Display("Segment ID")]
public string Id { get; set; } = dto.Id;
Expand Down
17 changes: 5 additions & 12 deletions Tests.OpenAI/AudioServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,30 @@
using Blackbird.Applications.Sdk.Common.Files;
using Blackbird.Applications.Sdk.Common.Exceptions;
using Blackbird.Applications.Sdk.Common.Invocation;
using Newtonsoft.Json.Linq;

namespace Tests.OpenAI;

[TestClass]
public class AudioServiceTests : TestBaseWithContext
{
[TestMethod, ContextDataSource(ConnectionTypes.OpenAiEmbedded, ConnectionTypes.OpenAi)]
public async Task CreateTranscription_OpenAi_ReturnsTranscription_DiarizedJsonFormat(InvocationContext context)
[TestMethod, ContextDataSource(ConnectionTypes.OpenAi)]
public async Task CreateTranscription_OpenAi_ReturnsTranscription(InvocationContext context)
{
// Arrange
var handler = new AudioActions(context, FileManagementClient);
var model = new AudioModelIdentifier { ModelId = "gpt-4o-transcribe-diarize" };
var request = new TranscriptionRequest
{
File = new FileReference { Name = "Transcription sample short.mp3" },
Language = "pt",
File = new FileReference { Name = "tts delorean.mp3" },
Language = "en",
};

// Act
var result = await handler.CreateTranscription(model, request);
var segments = JArray.Parse(result.Segments);

// Assert
TestContext.WriteLine(result.Transcription);
TestContext.WriteLine(result.Segments);
PrintResult(result);
Assert.IsNotNull(result);
Assert.IsTrue(segments.Count > 0);
Assert.IsTrue(segments.Any(x => x["Speaker"] != null));
}

[TestMethod, ContextDataSource(ConnectionTypes.OpenAiEmbedded, ConnectionTypes.OpenAi)]
Expand Down Expand Up @@ -75,7 +70,6 @@ public async Task CreateTranscription_OpenAi_StandardModel_ReturnsSingleBlobText

// Assert
TestContext.WriteLine(result.Transcription);
TestContext.WriteLine(result.Segments);
Assert.IsNotNull(result);
Assert.IsFalse(result.Transcription.Contains("A:"));
}
Expand All @@ -96,7 +90,6 @@ public async Task CreateTranscription_AzureOpenAi_ReturnsTranscription(Invocatio

// Assert
TestContext.WriteLine(result.Transcription);
TestContext.WriteLine(result.Segments);
Assert.IsNotNull(result);
}

Expand Down