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

30 lines
908 B
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-06-26 23:08:24 +00:00
var db = _services.GetRequiredService<AgentDbContext>();
db.Transaction<IAgentTable>(delegate
{
var record = db.Agent.FirstOrDefault(x => x.OwnerId == agent.OwerId && x.Id == agent.Id);
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
}
}