-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
122: Added integration with audio transcription tool
- Loading branch information
Showing
23 changed files
with
211 additions
and
47 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
API/ASSISTENTE.Infrastructure.Audio/ASSISTENTE.Infrastructure.Audio.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<InternalsVisibleTo Include="ASSISTENTE.Infrastructure"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ASSISTENTE.Infrastructure.LLM.OpenAi\ASSISTENTE.Infrastructure.LLM.OpenAi.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
35 changes: 35 additions & 0 deletions
35
API/ASSISTENTE.Infrastructure.Audio/Contracts/AudioFile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using CSharpFunctionalExtensions; | ||
using SOFTURE.Results; | ||
|
||
namespace ASSISTENTE.Infrastructure.Audio.Contracts; | ||
|
||
public sealed class AudioFile : ValueObject | ||
{ | ||
private AudioFile(string name, Stream stream) | ||
{ | ||
Name = name; | ||
Stream = stream; | ||
} | ||
|
||
public string Name { get; } | ||
public Stream Stream { get; } | ||
|
||
public static Result<AudioFile> Create(string name, Stream stream) | ||
{ | ||
if (string.IsNullOrEmpty(name)) | ||
return Result.Failure<AudioFile>(EmbeddingTextErrors.EmptyContent.Build()); | ||
|
||
return new AudioFile(name, stream); | ||
} | ||
|
||
protected override IEnumerable<IComparable> GetEqualityComponents() | ||
{ | ||
yield return Name; | ||
} | ||
} | ||
|
||
public static class EmbeddingTextErrors | ||
{ | ||
public static readonly Error EmptyContent = new( | ||
"Prompt.EmptyContent", "Prompt cannot be empty."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace ASSISTENTE.Infrastructure.Audio.Contracts; | ||
|
||
public enum AudioType | ||
{ | ||
OpenAi | ||
} |
8 changes: 8 additions & 0 deletions
8
API/ASSISTENTE.Infrastructure.Audio/Contracts/IAudioClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using CSharpFunctionalExtensions; | ||
|
||
namespace ASSISTENTE.Infrastructure.Audio.Contracts; | ||
|
||
public interface IAudioClient | ||
{ | ||
Task<Result<Transcription>> GenerateTranscription(AudioFile audioFile); | ||
} |
27 changes: 27 additions & 0 deletions
27
API/ASSISTENTE.Infrastructure.Audio/Contracts/Transcription.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using CSharpFunctionalExtensions; | ||
using SOFTURE.Results; | ||
|
||
namespace ASSISTENTE.Infrastructure.Audio.Contracts; | ||
|
||
public sealed class Transcription : ValueObject | ||
{ | ||
private Transcription(string text) | ||
{ | ||
Text = text; | ||
} | ||
|
||
public string Text { get; } | ||
|
||
public static Result<Transcription> Create(string? text) | ||
{ | ||
if (string.IsNullOrEmpty(text)) | ||
return Result.Failure<Transcription>(CommonErrors.EmptyParameter.Build()); | ||
|
||
return new Transcription(text); | ||
} | ||
|
||
protected override IEnumerable<IComparable> GetEqualityComponents() | ||
{ | ||
yield return Text; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
API/ASSISTENTE.Infrastructure.Audio/DependencyInjection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using ASSISTENTE.Infrastructure.Audio.Contracts; | ||
using ASSISTENTE.Infrastructure.LLM.OpenAi; | ||
using ASSISTENTE.Infrastructure.LLM.OpenAi.Settings; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace ASSISTENTE.Infrastructure.Audio | ||
{ | ||
internal static class DependencyInjection | ||
{ | ||
public static IServiceCollection AddOpenAiAudio<TSettings>(this IServiceCollection services) | ||
where TSettings : IOpenAiSettings | ||
{ | ||
services.AddOpenAi<TSettings>(); | ||
|
||
services.AddScoped<IAudioClient, OpenAiClient>(); | ||
|
||
return services; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using ASSISTENTE.Infrastructure.Audio.Contracts; | ||
using ASSISTENTE.Infrastructure.LLM.OpenAi.Errors; | ||
using CSharpFunctionalExtensions; | ||
using OpenAI; | ||
using OpenAI.Audio; | ||
using OpenAI.Models; | ||
|
||
namespace ASSISTENTE.Infrastructure.Audio; | ||
|
||
internal sealed class OpenAiClient(OpenAIClient client) : IAudioClient | ||
{ | ||
public async Task<Result<Transcription>> GenerateTranscription(AudioFile audioFile) | ||
{ | ||
var transcriptionRequest = new AudioTranscriptionRequest( | ||
audio: audioFile.Stream, | ||
audioName: audioFile.Name, | ||
model: Model.Whisper1, | ||
responseFormat: AudioResponseFormat.Text, | ||
language: "pl" | ||
); | ||
|
||
var transcriptionText = await client.AudioEndpoint.CreateTranscriptionTextAsync(transcriptionRequest); | ||
|
||
if (transcriptionText is null) | ||
return Result.Failure<Transcription>(ClientErrors.EmptyAnswer.Build()); | ||
|
||
return Transcription.Create(transcriptionText); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters