BotSharp/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs

33 lines
1 KiB
C#
Raw Normal View History

2023-06-23 04:43:00 +00:00
using BotSharp.Abstraction.Agents.Models;
2023-06-29 23:14:57 +00:00
using System.IO;
2023-06-23 04:43:00 +00:00
namespace BotSharp.Core.Agents.Services;
public partial class AgentService
{
public async Task UpdateAgent(Agent agent)
{
2023-08-10 04:53:22 +00:00
var db = _services.GetRequiredService<IBotSharpRepository>();
2023-06-26 23:08:24 +00:00
2023-07-21 21:56:14 +00:00
db.Transaction<IBotSharpTable>(delegate
2023-06-26 23:08:24 +00:00
{
2023-07-25 02:22:18 +00:00
var record = (from a in db.Agent
join ua in db.UserAgent on a.Id equals ua.AgentId
2023-07-26 21:05:30 +00:00
where ua.UserId == _user.Id && a.Id == agent.Id
2023-07-25 02:22:18 +00:00
select a).First();
2023-06-26 23:08:24 +00:00
record.Name = agent.Name;
record.Description = agent.Description;
record.UpdatedDateTime = DateTime.UtcNow;
});
2023-06-29 23:14:57 +00:00
// Save instruction to file
var dir = GetAgentDataDir(agent.Id);
var instructionFile = Path.Combine(dir, "instruction.txt");
File.WriteAllText(instructionFile, agent.Instruction);
var samplesFile = Path.Combine(dir, "samples.txt");
File.WriteAllText(samplesFile, agent.Samples);
2023-06-23 04:43:00 +00:00
}
}