Skip to content

Commit 710a1e1

Browse files
author
Jicheng Lu
committed
integrate
1 parent 872b57f commit 710a1e1

3 files changed

Lines changed: 26 additions & 39 deletions

File tree

src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -143,55 +143,29 @@ public async Task<IEnumerable<ChatResponseModel>> GetDialogs([FromRoute] string
143143
{
144144
var service = _services.GetRequiredService<IConversationService>();
145145
var userService = _services.GetRequiredService<IUserService>();
146+
var settings = _services.GetRequiredService<PluginSettings>();
147+
146148
var (isAdmin, user) = await userService.IsAdminUser(_user.Id);
147-
if (user == null)
148-
{
149-
return null;
150-
}
151149

152150
var filter = new ConversationFilter
153151
{
154152
Id = conversationId,
155-
UserId = !isAdmin ? user.Id : null,
153+
UserId = !isAdmin ? user?.Id : null,
156154
IsLoadLatestStates = isLoadStates
157155
};
158-
var conversations = await service.GetConversations(filter);
159-
if (conversations.Items.IsNullOrEmpty())
160-
{
161-
return null;
162-
}
163156

164-
var result = ConversationViewModel.FromSession(conversations.Items.First());
165-
var state = _services.GetRequiredService<IConversationStateService>();
166-
user = await userService.GetUser(result.User.Id);
167-
result.User = UserViewModel.FromUser(user);
168-
169-
return result;
170-
}
171-
172-
[HttpPost("/conversation/summary")]
173-
public async Task<string> GetConversationSummary([FromBody] ConversationSummaryModel input)
174-
{
175-
var service = _services.GetRequiredService<IConversationService>();
176-
return await service.GetConversationSummary(input.ConversationIds);
177-
}
157+
var conversations = await service.GetConversations(filter);
158+
var conv = !conversations.Items.IsNullOrEmpty()
159+
? ConversationViewModel.FromSession(conversations.Items.First())
160+
: new();
178161

179-
[HttpGet("/conversation/{conversationId}/user")]
180-
public async Task<UserViewModel> GetConversationUser([FromRoute] string conversationId)
181-
{
182-
var service = _services.GetRequiredService<IConversationService>();
183-
var conversations = await service.GetConversations(new ConversationFilter
184-
{
185-
Id = conversationId
186-
});
162+
user = !string.IsNullOrEmpty(conv?.User?.Id)
163+
? await userService.GetUser(conv.User.Id)
164+
: null;
187165

188-
var userService = _services.GetRequiredService<IUserService>();
189-
var conversation = conversations?.Items?.FirstOrDefault();
190-
var userId = conversation == null ? _user.Id : conversation.UserId;
191-
var user = await userService.GetUser(userId);
192166
if (user == null)
193167
{
194-
return new UserViewModel
168+
user = new User
195169
{
196170
Id = _user.Id,
197171
UserName = _user.UserName,
@@ -202,7 +176,16 @@ public async Task<UserViewModel> GetConversationUser([FromRoute] string conversa
202176
};
203177
}
204178

205-
return UserViewModel.FromUser(user);
179+
conv.User = UserViewModel.FromUser(user);
180+
conv.IsRealtimeEnabled = settings?.Assemblies?.Contains("BotSharp.Core.Realtime") ?? false;
181+
return conv;
182+
}
183+
184+
[HttpPost("/conversation/summary")]
185+
public async Task<string> GetConversationSummary([FromBody] ConversationSummaryModel input)
186+
{
187+
var service = _services.GetRequiredService<IConversationService>();
188+
return await service.GetConversationSummary(input.ConversationIds);
206189
}
207190

208191
[HttpPut("/conversation/{conversationId}/update-title")]

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/View/ConversationViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using BotSharp.Abstraction.Conversations.Dtos;
2+
using System.Text.Json.Serialization;
23

34
namespace BotSharp.OpenAPI.ViewModels.Conversations;
45

56
public class ConversationViewModel : ConversationDto
67
{
8+
[JsonPropertyName("is_realtime_enabled")]
9+
public bool IsRealtimeEnabled { get; set; }
10+
711
public static ConversationViewModel FromSession(Conversation sess)
812
{
913
return new ConversationViewModel

src/Plugins/BotSharp.Plugin.OpenAI/Models/Realtime/RealtimeSessionBody.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class RealtimeSessionTurnDetection
7676
public string Type { get; set; } = "semantic_vad";
7777

7878
[JsonPropertyName("eagerness")]
79-
public string eagerness { get;set; } = "auto";
79+
public string Eagerness { get;set; } = "auto";
8080
}
8181

8282
public class InputAudioTranscription

0 commit comments

Comments
 (0)