33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
using BotSharp.Abstraction.Routing;
|
|
using BotSharp.Abstraction.Routing.Enums;
|
|
|
|
namespace BotSharp.OpenAPI.Controllers;
|
|
|
|
[Authorize]
|
|
[ApiController]
|
|
public class RealtimeController : ControllerBase
|
|
{
|
|
private readonly IServiceProvider _services;
|
|
|
|
public RealtimeController(IServiceProvider services)
|
|
{
|
|
_services = services;
|
|
}
|
|
|
|
[HttpPost("/agent/{agentId}/function/{functionName}/execute")]
|
|
public async Task<string> ExecuteFunction(string agentId, string functionName, [FromBody] JsonDocument args)
|
|
{
|
|
// var agentService = _services.GetRequiredService<IAgentService>();
|
|
// var agent = await agentService.LoadAgent(agentId);
|
|
var routing = _services.GetRequiredService<IRoutingService>();
|
|
// Call functions
|
|
var message = new RoleDialogModel(AgentRole.Function, "")
|
|
{
|
|
FunctionName = functionName,
|
|
FunctionArgs = JsonSerializer.Serialize(args)
|
|
};
|
|
await routing.InvokeFunction(functionName, message, options: new() { From = InvokeSource.Llm });
|
|
return message.Content;
|
|
}
|
|
}
|