Remove CreateSession API
This commit is contained in:
parent
c0b982f6cc
commit
019be0113d
|
|
@ -22,7 +22,6 @@ public interface IRealTimeCompletion
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -31,9 +31,6 @@ public class RealtimeConversationHook : ConversationHookBase, IConversationHook
|
|||
return;
|
||||
}
|
||||
|
||||
// Clear cache to force to rebuild the agent instruction
|
||||
Utilities.ClearCache();
|
||||
|
||||
var routing = _services.GetRequiredService<IRoutingService>();
|
||||
|
||||
message.Role = AgentRole.Function;
|
||||
|
|
@ -60,6 +57,9 @@ public class RealtimeConversationHook : ConversationHookBase, IConversationHook
|
|||
}
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using BotSharp.Abstraction.Realtime.Models;
|
||||
using BotSharp.Abstraction.Routing;
|
||||
using BotSharp.Core.Infrastructures;
|
||||
|
||||
namespace BotSharp.OpenAPI.Controllers;
|
||||
|
||||
|
|
@ -15,21 +13,6 @@ public class RealtimeController : ControllerBase
|
|||
_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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -228,31 +228,6 @@ public class GoogleRealTimeProvider : IRealTimeCompletion
|
|||
//todo Send Audio Chunks to Model, Botsharp RealTime Implementation seems to be incomplete
|
||||
}
|
||||
|
||||
public async Task<RealtimeSession> CreateSession(Agent agent, List<RoleDialogModel> conversations)
|
||||
{
|
||||
var (prompt, request) = PrepareOptions(_chatClient, agent, conversations);
|
||||
|
||||
var config = request.GenerationConfig;
|
||||
|
||||
// Output Modality can either be text or audio
|
||||
config.ResponseModalities = new List<Modality>([Modality.AUDIO]);
|
||||
|
||||
await _client.SendSetupAsync(new BidiGenerateContentSetup()
|
||||
{
|
||||
GenerationConfig = config,
|
||||
Model = Model,
|
||||
SystemInstruction = request.SystemInstruction,
|
||||
Tools = request.Tools?.ToArray(),
|
||||
});
|
||||
|
||||
return new RealtimeSession()
|
||||
{
|
||||
Id = _client.ConnectionId.ToString(),
|
||||
Model = _model,
|
||||
Voice = "default"
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<string> UpdateSession(RealtimeHubConnection conn, bool interruptResponse = true)
|
||||
{
|
||||
var convService = _services.GetRequiredService<IConversationService>();
|
||||
|
|
|
|||
|
|
@ -40,10 +40,10 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
|||
Action onUserInterrupted)
|
||||
{
|
||||
var llmProviderService = _services.GetRequiredService<ILlmProviderService>();
|
||||
_model = llmProviderService.GetProviderModel("openai", "gpt-4o", modelType: LlmModelType.Realtime).Name;
|
||||
_model = llmProviderService.GetProviderModel(Provider, "gpt-4o", modelType: LlmModelType.Realtime).Name;
|
||||
|
||||
var settingsService = _services.GetRequiredService<ILlmProviderService>();
|
||||
var settings = settingsService.GetSetting(provider: "openai", _model);
|
||||
var settings = settingsService.GetSetting(Provider, _model);
|
||||
|
||||
_webSocket = new ClientWebSocket();
|
||||
_webSocket.Options.SetRequestHeader("Authorization", $"Bearer {settings.ApiKey}");
|
||||
|
|
@ -276,41 +276,6 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
|||
await _webSocket.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
}
|
||||
|
||||
public async Task<RealtimeSession> CreateSession(Agent agent, List<RoleDialogModel> conversations)
|
||||
{
|
||||
var contentHooks = _services.GetServices<IContentGeneratingHook>().ToList();
|
||||
|
||||
var client = ProviderHelper.GetClient(Provider, _model, _services);
|
||||
var chatClient = client.GetChatClient(_model);
|
||||
var (prompt, messages, options) = PrepareOptions(agent, conversations);
|
||||
|
||||
var instruction = messages.FirstOrDefault()?.Content.FirstOrDefault()?.Text ?? agent.Description;
|
||||
|
||||
var args = new RealtimeSessionCreationRequest
|
||||
{
|
||||
Model = _model,
|
||||
Instructions = instruction,
|
||||
ToolChoice = "auto",
|
||||
Tools = options.Tools.Select(x =>
|
||||
{
|
||||
var fn = new FunctionDef
|
||||
{
|
||||
Name = x.FunctionName,
|
||||
Description = x.FunctionDescription
|
||||
};
|
||||
fn.Parameters = JsonSerializer.Deserialize<FunctionParametersDef>(x.FunctionParameters);
|
||||
return fn;
|
||||
}).ToArray(),
|
||||
};
|
||||
|
||||
var settingsService = _services.GetRequiredService<ILlmProviderService>();
|
||||
var settings = settingsService.GetSetting(Provider, args.Model ?? _model);
|
||||
|
||||
var api = _services.GetRequiredService<IOpenAiRealtimeApi>();
|
||||
var session = await api.CreateSessionAsync(args, settings.ApiKey);
|
||||
return session;
|
||||
}
|
||||
|
||||
public async Task<string> UpdateSession(RealtimeHubConnection conn, bool interruptResponse = true)
|
||||
{
|
||||
var convService = _services.GetRequiredService<IConversationService>();
|
||||
|
|
|
|||
Loading…
Reference in a new issue