Skip to content

integrate speech reconition #1052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -143,55 +143,29 @@ public async Task<IEnumerable<ChatResponseModel>> GetDialogs([FromRoute] string
{
var service = _services.GetRequiredService<IConversationService>();
var userService = _services.GetRequiredService<IUserService>();
var settings = _services.GetRequiredService<PluginSettings>();

var (isAdmin, user) = await userService.IsAdminUser(_user.Id);
if (user == null)
{
return null;
}

var filter = new ConversationFilter
{
Id = conversationId,
UserId = !isAdmin ? user.Id : null,
UserId = !isAdmin ? user?.Id : null,
IsLoadLatestStates = isLoadStates
};
var conversations = await service.GetConversations(filter);
if (conversations.Items.IsNullOrEmpty())
{
return null;
}

var result = ConversationViewModel.FromSession(conversations.Items.First());
var state = _services.GetRequiredService<IConversationStateService>();
user = await userService.GetUser(result.User.Id);
result.User = UserViewModel.FromUser(user);

return result;
}

[HttpPost("/conversation/summary")]
public async Task<string> GetConversationSummary([FromBody] ConversationSummaryModel input)
{
var service = _services.GetRequiredService<IConversationService>();
return await service.GetConversationSummary(input.ConversationIds);
}
var conversations = await service.GetConversations(filter);
var conv = !conversations.Items.IsNullOrEmpty()
? ConversationViewModel.FromSession(conversations.Items.First())
: new();

[HttpGet("/conversation/{conversationId}/user")]
public async Task<UserViewModel> GetConversationUser([FromRoute] string conversationId)
{
var service = _services.GetRequiredService<IConversationService>();
var conversations = await service.GetConversations(new ConversationFilter
{
Id = conversationId
});
user = !string.IsNullOrEmpty(conv?.User?.Id)
? await userService.GetUser(conv.User.Id)
: null;

var userService = _services.GetRequiredService<IUserService>();
var conversation = conversations?.Items?.FirstOrDefault();
var userId = conversation == null ? _user.Id : conversation.UserId;
var user = await userService.GetUser(userId);
if (user == null)
{
return new UserViewModel
user = new User
{
Id = _user.Id,
UserName = _user.UserName,
Expand All @@ -202,7 +176,16 @@ public async Task<UserViewModel> GetConversationUser([FromRoute] string conversa
};
}

return UserViewModel.FromUser(user);
conv.User = UserViewModel.FromUser(user);
conv.IsRealtimeEnabled = settings?.Assemblies?.Contains("BotSharp.Core.Realtime") ?? false;
return conv;
}

[HttpPost("/conversation/summary")]
public async Task<string> GetConversationSummary([FromBody] ConversationSummaryModel input)
{
var service = _services.GetRequiredService<IConversationService>();
return await service.GetConversationSummary(input.ConversationIds);
}

[HttpPut("/conversation/{conversationId}/update-title")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using BotSharp.Abstraction.Conversations.Dtos;
using System.Text.Json.Serialization;

namespace BotSharp.OpenAPI.ViewModels.Conversations;

public class ConversationViewModel : ConversationDto
{
[JsonPropertyName("is_realtime_enabled")]
public bool IsRealtimeEnabled { get; set; }

public static ConversationViewModel FromSession(Conversation sess)
{
return new ConversationViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class RealtimeSessionTurnDetection
public string Type { get; set; } = "semantic_vad";

[JsonPropertyName("eagerness")]
public string eagerness { get;set; } = "auto";
public string Eagerness { get;set; } = "auto";
}

public class InputAudioTranscription
Expand Down
Loading