Files
nofx/api
Liu Xiang Qian b0de71bdf5 feat: 支持更新 Trader 的系统提示词模板
允许在编辑 Trader 时更新系统提示词模板(SystemPromptTemplate)。

系统提示词模板用于控制 AI 交易决策的行为模式。目前创建 Trader 时可以指定模板,但编辑时无法修改。

1. **UpdateTraderRequest** 添加 `SystemPromptTemplate` 字段
   ```go
   SystemPromptTemplate string `json:"system_prompt_template"`
   ```

2. **handleUpdateTrader** 添加处理逻辑
   - 如果请求中提供新模板,使用新值
   - 如果为空字符串,保持数据库中的原有值

   ```go
   systemPromptTemplate := req.SystemPromptTemplate
   if systemPromptTemplate == "" {
       systemPromptTemplate = existingTrader.SystemPromptTemplate
   }
   ```

3. **TraderRecord** 设置 SystemPromptTemplate 字段
   ```go
   SystemPromptTemplate: systemPromptTemplate,
   ```

-  支持在编辑 Trader 时更新系统提示词模板
-  空值时保持原有值不变(向后兼容)
-  与创建 Trader 时的行为保持一致
-  无破坏性变更

1. 用户创建 Trader 时使用了默认模板
2. 后续想切换到自定义模板(如更激进或保守的策略)
3. 通过编辑功能修改 SystemPromptTemplate 字段
4. 保存后,AI 将使用新的提示词模板进行决策

1. 创建 Trader(使用默认模板 "default")
2. 编辑 Trader,修改 system_prompt_template 为 "aggressive"
3. 保存并验证修改成功
4. 再次编辑,不修改 system_prompt_template(传空字符串)
5. 验证保持 "aggressive" 不变
2025-11-03 22:15:23 +08:00
..