Skip to content
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

Clean code for GeminiLive #997

Merged
merged 5 commits into from
Apr 5, 2025
Merged
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 @@ -22,7 +22,6 @@ Task Connect(RealtimeHubConnection conn,
Task SendEventToModel(object message);
Task Disconnect();

Task<RealtimeSession> CreateSession(Agent agent, List<RoleDialogModel> conversations);
Task<string> UpdateSession(RealtimeHubConnection conn, bool interruptResponse = true);
Task InsertConversationItem(RoleDialogModel message);
Task RemoveConversationItem(string itemId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class RealtimeHubConnection
public string CurrentAgentId { get; set; } = null!;
public string ConversationId { get; set; } = null!;
public string Data { get; set; } = string.Empty;
public string Model { get; set; } = null!;
public Func<string, object> OnModelMessageReceived { get; set; } = null!;
public Func<object> OnModelAudioResponseDone { get; set; } = null!;
public Func<object> OnModelUserInterrupted { get; set; } = null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public async Task OnFunctionExecuted(RoleDialogModel message)
return;
}

// Clear cache to force to rebuild the agent instruction
Utilities.ClearCache();

var routing = _services.GetRequiredService<IRoutingService>();

message.Role = AgentRole.Function;
Expand All @@ -60,6 +57,9 @@ public async Task OnFunctionExecuted(RoleDialogModel message)
}
else
{
// Clear cache to force to rebuild the agent instruction
Utilities.ClearCache();

// Update session for changed states
var instruction = await hub.Completer.UpdateSession(hub.HubConn);
await hub.Completer.InsertConversationItem(message);
Expand Down
12 changes: 0 additions & 12 deletions src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BotSharp.Abstraction.Functions.Models;
using BotSharp.Abstraction.MLTasks.Settings;
using BotSharp.Abstraction.Options;
using BotSharp.Core.Infrastructures;

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

// Set model
var model = "gpt-4o-mini-realtime";
if (agent.Profiles.Contains("realtime"))
{
var llmProviderService = _services.GetRequiredService<ILlmProviderService>();
model = llmProviderService.GetProviderModel("openai", "gpt-4o", modelType: LlmModelType.Realtime).Name;
}

_completer.SetModelName(model);
_conn.Model = model;

var routing = _services.GetRequiredService<IRoutingService>();
routing.Context.Push(agent.Id);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using BotSharp.Abstraction.Realtime.Models;
using BotSharp.Abstraction.Routing;
using BotSharp.Core.Infrastructures;

namespace BotSharp.OpenAPI.Controllers;

Expand All @@ -15,21 +13,6 @@ public RealtimeController(IServiceProvider services)
_services = services;
}

/// <summary>
/// Create an ephemeral API token for use in client-side applications with the Realtime API.
/// </summary>
/// <returns></returns>
[HttpGet("/agent/{agentId}/realtime/session")]
public async Task<RealtimeSession> CreateSession(string agentId)
{
var completion = CompletionProvider.GetRealTimeCompletion(_services, provider: "openai", modelId: "gpt-4o");

var agentService = _services.GetRequiredService<IAgentService>();
var agent = await agentService.LoadAgent(agentId);

return await completion.CreateSession(agent, []);
}

[HttpPost("/agent/{agentId}/function/{functionName}/execute")]
public async Task<string> ExecuteFunction(string agentId, string functionName, [FromBody] JsonDocument args)
{
Expand Down
1 change: 0 additions & 1 deletion src/Plugins/BotSharp.Plugin.GoogleAI/GoogleAiPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BotSharp.Abstraction.Plugins;
using BotSharp.Abstraction.Settings;
using BotSharp.Plugin.GoogleAi.Providers.Chat;
using BotSharp.Plugin.GoogleAI.Providers.Embedding;
using BotSharp.Plugin.GoogleAi.Providers.Realtime;
using BotSharp.Plugin.GoogleAi.Providers.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using GenerativeAI;
using GenerativeAI.Core;
using GenerativeAI.Types;
using Microsoft.Extensions.Logging;

namespace BotSharp.Plugin.GoogleAi.Providers.Chat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using BotSharp.Abstraction.Routing;
using LLMSharp.Google.Palm;
using LLMSharp.Google.Palm.DiscussService;
using Microsoft.Extensions.Logging;

namespace BotSharp.Plugin.GoogleAi.Providers.Chat;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using BotSharp.Plugin.GoogleAi.Providers;
using GenerativeAI;
using GenerativeAI.Types;
using Microsoft.Extensions.Logging;

namespace BotSharp.Plugin.GoogleAI.Providers.Embedding;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using LLMSharp.Google.Palm;
using Microsoft.Extensions.Logging;

namespace BotSharp.Plugin.GoogleAi.Providers;

Expand Down
Loading
Loading