migrate agents
This commit is contained in:
parent
5fc8238785
commit
3f06b58a60
|
|
@ -102,11 +102,28 @@ public partial class AgentService
|
|||
|
||||
private List<FunctionDef> FetchFunctionsFromFile(string fileDir)
|
||||
{
|
||||
var file = Path.Combine(fileDir, "functions.json");
|
||||
if (!File.Exists(file)) return new List<FunctionDef>();
|
||||
var functions = new List<FunctionDef>();
|
||||
var functionDir = Path.Combine(fileDir, "functions");
|
||||
|
||||
var functionsJson = File.ReadAllText(file);
|
||||
var functions = JsonSerializer.Deserialize<List<FunctionDef>>(functionsJson, _options);
|
||||
if (!Directory.Exists(functionDir)) return functions;
|
||||
|
||||
foreach (var file in Directory.GetFiles(functionDir))
|
||||
{
|
||||
try
|
||||
{
|
||||
var extension = Path.GetExtension(file).Substring(1);
|
||||
if (extension != "json") continue;
|
||||
|
||||
var json = File.ReadAllText(file);
|
||||
var function = JsonSerializer.Deserialize<FunctionDef>(json, _options);
|
||||
functions.Add(function);
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
return functions;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using BotSharp.Abstraction.Routing.Models;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace BotSharp.Core.Repository
|
||||
{
|
||||
|
|
@ -194,11 +195,24 @@ namespace BotSharp.Core.Repository
|
|||
var (agent, agentFile) = GetAgentFromFile(agentId);
|
||||
if (agent == null) return;
|
||||
|
||||
var functionFile = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir,
|
||||
agentId, AGENT_FUNCTIONS_FILE);
|
||||
var functionDir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir,
|
||||
agentId, AGENT_FUNCTIONS_FOLDER);
|
||||
|
||||
var functionText = JsonSerializer.Serialize(inputFunctions, _options);
|
||||
File.WriteAllText(functionFile, functionText);
|
||||
if (Directory.Exists(functionDir))
|
||||
{
|
||||
Directory.Delete(functionDir, true);
|
||||
}
|
||||
Directory.CreateDirectory(functionDir);
|
||||
|
||||
foreach (var func in inputFunctions)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(func.Name)) continue;
|
||||
|
||||
var text = JsonSerializer.Serialize(func, _options);
|
||||
var file = Path.Combine(functionDir, $"{func.Name}.json");
|
||||
File.WriteAllText(file, text);
|
||||
Thread.Sleep(200);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAgentTemplates(string agentId, List<AgentTemplate> templates)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ public partial class FileRepository : IBotSharpRepository
|
|||
|
||||
private const string AGENT_FILE = "agent.json";
|
||||
private const string AGENT_INSTRUCTION_FILE = "instruction";
|
||||
private const string AGENT_FUNCTIONS_FILE = "functions.json";
|
||||
private const string AGENT_SAMPLES_FILE = "samples.txt";
|
||||
private const string USER_FILE = "user.json";
|
||||
private const string USER_AGENT_FILE = "agents.json";
|
||||
|
|
|
|||
Loading…
Reference in a new issue