Expose translation API.
This commit is contained in:
parent
c3f0e3aa67
commit
4b16a86e0d
|
|
@ -0,0 +1,8 @@
|
|||
namespace BotSharp.Abstraction.Agents.Enums;
|
||||
|
||||
public class BuiltInAgentId
|
||||
{
|
||||
public const string AIAssistant = "01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a";
|
||||
public const string Chatbot = "01e2fc5c-2c89-4ec7-8470-7688608b496c";
|
||||
public const string HumanSupport = "01dcc3e5-0af7-49e6-ad7a-a760bd12dc4b";
|
||||
}
|
||||
|
|
@ -17,9 +17,9 @@ public class AgentPlugin : IBotSharpPlugin
|
|||
|
||||
public string[] AgentIds => new string[]
|
||||
{
|
||||
"01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a",
|
||||
"01e2fc5c-2c89-4ec7-8470-7688608b496c",
|
||||
"01dcc3e5-0af7-49e6-ad7a-a760bd12dc4b"
|
||||
BuiltInAgentId.AIAssistant,
|
||||
BuiltInAgentId.Chatbot,
|
||||
BuiltInAgentId.HumanSupport
|
||||
};
|
||||
|
||||
public object GetNewSettingsInstance() =>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
using BotSharp.Abstraction.Agents.Models;
|
||||
using BotSharp.Abstraction.Translation;
|
||||
using BotSharp.OpenAPI.ViewModels.Translations;
|
||||
|
||||
namespace BotSharp.OpenAPI.Controllers;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class TranslationController : ControllerBase
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
|
||||
public TranslationController(IServiceProvider services)
|
||||
{
|
||||
_services = services;
|
||||
}
|
||||
|
||||
[HttpPost("/translate")]
|
||||
public async Task<TranslationResponseModel> Translate([FromBody] TranslationRequestModel model)
|
||||
{
|
||||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
var agent = await agentService.LoadAgent(BuiltInAgentId.AIAssistant);
|
||||
var translator = _services.GetRequiredService<ITranslationService>();
|
||||
var text = await translator.Translate(agent, Guid.NewGuid().ToString(), model.Text, language: model.ToLang);
|
||||
return new TranslationResponseModel
|
||||
{
|
||||
Text = text
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
using BotSharp.Abstraction.Infrastructures.Enums;
|
||||
|
||||
namespace BotSharp.OpenAPI.ViewModels.Translations;
|
||||
|
||||
public class TranslationRequestModel
|
||||
{
|
||||
public string Text { get; set; } = null!;
|
||||
public string ToLang { get; set; } = LanguageType.CHINESE;
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace BotSharp.OpenAPI.ViewModels.Translations;
|
||||
|
||||
public class TranslationResponseModel
|
||||
{
|
||||
public string Text { get; set; } = null!;
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string FromLang { get; set; } = null!;
|
||||
}
|
||||
|
|
@ -71,7 +71,10 @@ public class PlaywrightInstance : IDisposable
|
|||
Serilog.Log.Information($"Page is closed: {e.Url}");
|
||||
};
|
||||
Serilog.Log.Information($"New page is created: {page.Url}");
|
||||
await page.SetViewportSizeAsync(1600, 900);
|
||||
if (!page.IsClosed)
|
||||
{
|
||||
await page.SetViewportSizeAsync(1600, 900);
|
||||
}
|
||||
|
||||
/*page.Response += async (sender, e) =>
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue