Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public async Task<UpdateAiSpeechAssistantKnowledgeResponse> UpdateAiSpeechAssist
knowledge.Greetings = command.Greetings;

if (command.VoiceType.HasValue)
await UpdateAssistantVoiceIfRequiredAsync(knowledge.AssistantId, command.VoiceType.Value, cancellationToken).ConfigureAwait(false);
await UpdateAssistantVoiceIfRequiredAsync(knowledge.AssistantId, command.ModelVoice, command.VoiceType.Value, command.MediaType, cancellationToken).ConfigureAwait(false);

await _aiSpeechAssistantDataProvider.UpdateAiSpeechAssistantKnowledgesAsync([knowledge], cancellationToken: cancellationToken).ConfigureAwait(false);

Expand Down Expand Up @@ -197,15 +197,15 @@ await _redisSafeRunner.ExecuteWithLockAsync($"session-update-{command.SessionId}
};
}

private async Task UpdateAssistantVoiceIfRequiredAsync(int assistantId, AiKidVoiceType voiceType, CancellationToken cancellationToken)
private async Task UpdateAssistantVoiceIfRequiredAsync(int assistantId, string modelVoice, AiKidVoiceType? voiceType, AiSpeechAssistantMediaType? mediaType, CancellationToken cancellationToken)
{
var assistant = await _aiSpeechAssistantDataProvider.GetAiSpeechAssistantAsync(assistantId, cancellationToken).ConfigureAwait(false);

Log.Information("Get assistant for update model voice: {@Assistant}", assistant);

if (assistant != null)
{
assistant.ModelVoice = ModelVoiceMapping(voiceType);
assistant.ModelVoice = ModelVoiceMapping(modelVoice, voiceType, mediaType);

await _aiSpeechAssistantDataProvider.UpdateAiSpeechAssistantsAsync([assistant], cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand All @@ -228,13 +228,15 @@ private async Task<AiSpeechAssistantKnowledge> GetAiSpeechAssistantKnowledgeAsyn
var assistant = new Domain.AISpeechAssistant.AiSpeechAssistant
{
AgentId = agent.Id,
ModelVoice = ModelVoiceMapping(command.VoiceType),
ModelVoice = ModelVoiceMapping(command.ModelVoice, command.VoiceType, command.MediaType),
Name = command.AssistantName,
AnsweringNumberId = number?.Id,
AnsweringNumber = number?.Number,
CreatedBy = _currentUser.Id.Value,
ModelUrl = command.AgentType == AgentType.AiKid ? AiSpeechAssistantStore.AiKidDefaultUrl : AiSpeechAssistantStore.DefaultUrl,
ModelProvider = AiSpeechAssistantProvider.OpenAi,
ModelUrl = GetDefaultModuleUrl(command.ModelUrl, command.ModelProvider, command.AgentType),
ModelProvider = command.ModelProvider,
ModelName = command.ModelName,
ModelLanguage = command.ModelLanguage,
Channel = command.Channels == null ? null : string.Join(",", command.Channels.Select(x => (int)x)),
IsDisplay = command.IsDisplay
};
Expand All @@ -246,14 +248,27 @@ private async Task<AiSpeechAssistantKnowledge> GetAiSpeechAssistantKnowledgeAsyn
return assistant;
}

private string ModelVoiceMapping(AiKidVoiceType? voiceType)
private string GetDefaultModuleUrl(string modelUrl, AiSpeechAssistantProvider provider, AgentType type)
{
if (!string.IsNullOrEmpty(modelUrl)) return modelUrl;

return type switch
{
AgentType.AiKid => provider == AiSpeechAssistantProvider.OpenAi ? AiSpeechAssistantStore.AiKidDefaultUrl : AiSpeechAssistantStore.GoogleDefaultUrl,
_ => provider == AiSpeechAssistantProvider.OpenAi ? AiSpeechAssistantStore.DefaultUrl : AiSpeechAssistantStore.GoogleDefaultUrl
};
}

private string ModelVoiceMapping(string modelVoice, AiKidVoiceType? voiceType, AiSpeechAssistantMediaType? mediaType)
{
if (!string.IsNullOrEmpty(modelVoice)) return modelVoice;

if (!voiceType.HasValue) return "alloy";

return voiceType.Value switch
{
AiKidVoiceType.Male => "ash",
_ => "alloy"
AiKidVoiceType.Male => mediaType.HasValue ? (mediaType == AiSpeechAssistantMediaType.Audio ? "ash" : "Puck") : "ash",
_ => mediaType.HasValue ? (mediaType == AiSpeechAssistantMediaType.Audio ? "alloy" : "Aoede") : "alloy"
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ public class AddAiSpeechAssistantCommand : ICommand
public AgentType AgentType { get; set; } = AgentType.Restaurant;

public AgentSourceSystem SourceSystem { get; set; } = AgentSourceSystem.Self;

public string ModelVoice { get; set; }

public string ModelUrl { get; set; }

public string ModelName { get; set; }

public string ModelLanguage { get; set; }

public AiSpeechAssistantMediaType? MediaType { get; set; }

public AiSpeechAssistantProvider ModelProvider { get; set; } = AiSpeechAssistantProvider.OpenAi;
}

public class AddAiSpeechAssistantResponse : SmartTalkResponse<AiSpeechAssistantDto>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ public class UpdateAiSpeechAssistantKnowledgeCommand : ICommand

public string Greetings { get; set; }

public string ModelVoice { get; set; }

public AiKidVoiceType? VoiceType { get; set; }

public AiSpeechAssistantMediaType? MediaType { get; set; }
}

public class UpdateAiSpeechAssistantKnowledgeResponse : SmartTalkResponse<AiSpeechAssistantKnowledgeDto>
Expand Down
1 change: 1 addition & 0 deletions src/SmartTalk.Messages/Constants/AiSpeechAssistantStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public static class AiSpeechAssistantStore
{
public static string DefaultUrl = "wss://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview-2025-06-03";
public static string AiKidDefaultUrl = "wss://api.openai.com/v1/realtime?model=gpt-4o-mini-realtime-preview-2024-12-17";
public static string GoogleDefaultUrl = "wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace SmartTalk.Messages.Enums.AiSpeechAssistant;

public enum AiSpeechAssistantMediaType
{
Audio,
Video
}