Commit d3f17d2a authored by 段廷瑞's avatar 段廷瑞

pref: Agent配置统一到默认路径

parent 63b72095
{"ApiKey":"sk-bfaffa679dac4f7e9b2f128ee022022d","BaseUrl":"https://api.deepseek.com","Model":"deepseek-v4-flash","KnowledgeBasePath":"D:\\working\\docs\\个人文档","Temperature":0.3,"MaxTokens":2048}
\ No newline at end of file
...@@ -82,9 +82,36 @@ namespace Tools.MyAgent ...@@ -82,9 +82,36 @@ namespace Tools.MyAgent
/// <summary>默认知识库路径:程序输出目录下的 Agent 文件夹(未设置知识库时生效)</summary> /// <summary>默认知识库路径:程序输出目录下的 Agent 文件夹(未设置知识库时生效)</summary>
private static string DefaultKbRoot => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Agent"); private static string DefaultKbRoot => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Agent");
/// <summary>Agent 配置文件:默认 Agent 目录下的 config\AgentConfig.json</summary>
private static string AgentConfigFilePath => Path.Combine(DefaultKbRoot, "config", "AgentConfig.json");
/// <summary>读取 Agent 配置文件(默认 Agent 目录下 config 文件夹)</summary>
private AgentConfig LoadAgentConfig()
{
try
{
if (File.Exists(AgentConfigFilePath))
return Newtonsoft.Json.JsonConvert.DeserializeObject<AgentConfig>(File.ReadAllText(AgentConfigFilePath, System.Text.Encoding.UTF8));
}
catch { }
return null;
}
/// <summary>保存 Agent 配置文件到默认 Agent 目录下 config 文件夹</summary>
private void SaveAgentConfig(AgentConfig cfg)
{
try
{
Directory.CreateDirectory(Path.Combine(DefaultKbRoot, "config"));
File.WriteAllText(AgentConfigFilePath, Newtonsoft.Json.JsonConvert.SerializeObject(cfg), System.Text.Encoding.UTF8);
}
catch { }
}
private void LoadConfig() private void LoadConfig()
{ {
_config = Utils.GetJsonConfig<AgentConfig>() ?? new AgentConfig(); // 统一使用默认 Agent 目录下 config 文件夹的 AgentConfig.json(新位置)
_config = LoadAgentConfig() ?? new AgentConfig();
// 模型归一化:仅允许支持的模型,旧值回退到默认 // 模型归一化:仅允许支持的模型,旧值回退到默认
if (!SupportedModels.Contains(_config.Model ?? "")) if (!SupportedModels.Contains(_config.Model ?? ""))
_config.Model = SupportedModels[0]; _config.Model = SupportedModels[0];
...@@ -102,7 +129,8 @@ namespace Tools.MyAgent ...@@ -102,7 +129,8 @@ namespace Tools.MyAgent
private void SaveConfig() private void SaveConfig()
{ {
Utils.SaveJsonConfig(_config); // 统一保存到默认 Agent 目录下 config 文件夹(唯一位置)
SaveAgentConfig(_config);
} }
private void ApplyConfig() private void ApplyConfig()
...@@ -809,7 +837,7 @@ namespace Tools.MyAgent ...@@ -809,7 +837,7 @@ namespace Tools.MyAgent
}; };
var lblHint = new Label var lblHint = new Label
{ {
Text = "API Key 仅保存在本机 config\\AgentConfig.json", Text = "API Key 仅保存在本机 Agent\\config\\AgentConfig.json",
AutoSize = true, AutoSize = true,
ForeColor = Color.Gray, ForeColor = Color.Gray,
Location = new Point(150, 160), Location = new Point(150, 160),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment