Skip to content

Commit 03ab110

Browse files
authored
Merge pull request #997 from hchen2020/master
Clean code for GeminiLive
2 parents 18c6598 + 34a8234 commit 03ab110

28 files changed

+421
-541
lines changed

src/Infrastructure/BotSharp.Abstraction/MLTasks/IRealTimeCompletion.cs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Task Connect(RealtimeHubConnection conn,
2222
Task SendEventToModel(object message);
2323
Task Disconnect();
2424

25-
Task<RealtimeSession> CreateSession(Agent agent, List<RoleDialogModel> conversations);
2625
Task<string> UpdateSession(RealtimeHubConnection conn, bool interruptResponse = true);
2726
Task InsertConversationItem(RoleDialogModel message);
2827
Task RemoveConversationItem(string itemId);

src/Infrastructure/BotSharp.Abstraction/Realtime/Models/RealtimeHubConnection.cs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class RealtimeHubConnection
1414
public string CurrentAgentId { get; set; } = null!;
1515
public string ConversationId { get; set; } = null!;
1616
public string Data { get; set; } = string.Empty;
17-
public string Model { get; set; } = null!;
1817
public Func<string, object> OnModelMessageReceived { get; set; } = null!;
1918
public Func<object> OnModelAudioResponseDone { get; set; } = null!;
2019
public Func<object> OnModelUserInterrupted { get; set; } = null!;

src/Infrastructure/BotSharp.Core.Realtime/Hooks/RealtimeConversationHook.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ public async Task OnFunctionExecuted(RoleDialogModel message)
3131
return;
3232
}
3333

34-
// Clear cache to force to rebuild the agent instruction
35-
Utilities.ClearCache();
36-
3734
var routing = _services.GetRequiredService<IRoutingService>();
3835

3936
message.Role = AgentRole.Function;
@@ -60,6 +57,9 @@ public async Task OnFunctionExecuted(RoleDialogModel message)
6057
}
6158
else
6259
{
60+
// Clear cache to force to rebuild the agent instruction
61+
Utilities.ClearCache();
62+
6363
// Update session for changed states
6464
var instruction = await hub.Completer.UpdateSession(hub.HubConn);
6565
await hub.Completer.InsertConversationItem(message);

src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs

-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BotSharp.Abstraction.Functions.Models;
2-
using BotSharp.Abstraction.MLTasks.Settings;
32
using BotSharp.Abstraction.Options;
43
using BotSharp.Core.Infrastructures;
54

@@ -77,17 +76,6 @@ private async Task ConnectToModel(WebSocket userWebSocket)
7776
var agent = await agentService.LoadAgent(conversation.AgentId);
7877
_conn.CurrentAgentId = agent.Id;
7978

80-
// Set model
81-
var model = "gpt-4o-mini-realtime";
82-
if (agent.Profiles.Contains("realtime"))
83-
{
84-
var llmProviderService = _services.GetRequiredService<ILlmProviderService>();
85-
model = llmProviderService.GetProviderModel("openai", "gpt-4o", modelType: LlmModelType.Realtime).Name;
86-
}
87-
88-
_completer.SetModelName(model);
89-
_conn.Model = model;
90-
9179
var routing = _services.GetRequiredService<IRoutingService>();
9280
routing.Context.Push(agent.Id);
9381

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

-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using BotSharp.Abstraction.Realtime.Models;
21
using BotSharp.Abstraction.Routing;
3-
using BotSharp.Core.Infrastructures;
42

53
namespace BotSharp.OpenAPI.Controllers;
64

@@ -15,21 +13,6 @@ public RealtimeController(IServiceProvider services)
1513
_services = services;
1614
}
1715

18-
/// <summary>
19-
/// Create an ephemeral API token for use in client-side applications with the Realtime API.
20-
/// </summary>
21-
/// <returns></returns>
22-
[HttpGet("/agent/{agentId}/realtime/session")]
23-
public async Task<RealtimeSession> CreateSession(string agentId)
24-
{
25-
var completion = CompletionProvider.GetRealTimeCompletion(_services, provider: "openai", modelId: "gpt-4o");
26-
27-
var agentService = _services.GetRequiredService<IAgentService>();
28-
var agent = await agentService.LoadAgent(agentId);
29-
30-
return await completion.CreateSession(agent, []);
31-
}
32-
3316
[HttpPost("/agent/{agentId}/function/{functionName}/execute")]
3417
public async Task<string> ExecuteFunction(string agentId, string functionName, [FromBody] JsonDocument args)
3518
{

src/Plugins/BotSharp.Plugin.GoogleAI/GoogleAiPlugin.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using BotSharp.Abstraction.Plugins;
22
using BotSharp.Abstraction.Settings;
3-
using BotSharp.Plugin.GoogleAi.Providers.Chat;
43
using BotSharp.Plugin.GoogleAI.Providers.Embedding;
54
using BotSharp.Plugin.GoogleAi.Providers.Realtime;
65
using BotSharp.Plugin.GoogleAi.Providers.Text;

src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using GenerativeAI;
77
using GenerativeAI.Core;
88
using GenerativeAI.Types;
9-
using Microsoft.Extensions.Logging;
109

1110
namespace BotSharp.Plugin.GoogleAi.Providers.Chat;
1211

src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/PalmChatCompletionProvider.cs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using BotSharp.Abstraction.Routing;
66
using LLMSharp.Google.Palm;
77
using LLMSharp.Google.Palm.DiscussService;
8-
using Microsoft.Extensions.Logging;
98

109
namespace BotSharp.Plugin.GoogleAi.Providers.Chat;
1110

src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Embedding/TextEmbeddingProvider.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using BotSharp.Plugin.GoogleAi.Providers;
22
using GenerativeAI;
33
using GenerativeAI.Types;
4-
using Microsoft.Extensions.Logging;
54

65
namespace BotSharp.Plugin.GoogleAI.Providers.Embedding;
76

src/Plugins/BotSharp.Plugin.GoogleAI/Providers/ProviderHelper.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using LLMSharp.Google.Palm;
2-
using Microsoft.Extensions.Logging;
32

43
namespace BotSharp.Plugin.GoogleAi.Providers;
54

0 commit comments

Comments
 (0)