fix: add JSON validation to prevent range values and thousand separators

修復 LLM 返回範圍值導致 JSON 解析失敗的問題

## 問題
LLM 有時返回價格範圍 [98,000 ~ 102,000] 而不是單一數值,
導致 JSON 解析失敗:invalid character '0' after array element

## 修復內容

### 1. Prompts 更新(3 個文件)
- prompts/default.txt: 添加數字格式要求(中文)
- prompts/adaptive.txt: 添加數字格式要求(中文)
- prompts/nof1.txt: 添加數字格式要求(英文)

明確禁止:
-  範圍符號 ~
-  千位分隔符 98,000
-  文字描述

### 2. JSON 驗證邏輯(decision/engine.go)
新增函數:
- validateJSONFormat(): 檢測範圍、千位分隔符等錯誤
- min(): 輔助函數

檢測內容:
1. 必須是對象數組 [{...}]
2. 不可包含範圍符號 ~
3. 不可包含千位分隔符 98,000

## 測試
✓ go build ./...  編譯成功
✓ go fmt ./...    格式正確

修改統計:+132 行(46 行代碼 + 86 行 prompts)
This commit is contained in:
ZhouYongyou
2025-11-04 21:18:27 +08:00
parent c46f0be315
commit 8bf6c2e1e2
4 changed files with 132 additions and 0 deletions

View File

@@ -387,6 +387,35 @@ Key insight: 一句话总结本次决策
}
```
### ⚠️ 数字格式要求
**所有数字字段必须是精确的单一数值**,不可使用范围或特殊格式:
✅ **正确格式**
```json
{
"stop_loss": 98500.0,
"take_profit": 102000.0,
"position_size_usd": 50.0,
"confidence": 85
}
```
❌ **错误格式(会导致解析失败)**
```json
{
"stop_loss": "98,000 ~ 102,000", // ❌ 不可使用范围符号 ~
"take_profit": 102,000, // ❌ 不可使用千位分隔符
"confidence": "85左右" // ❌ 不可使用文字描述
}
```
**注意**
- 必须使用精确数值,不可使用范围 (如 `~`、`-`、`to`)
- 不可使用千位分隔符逗号 (98000 而非 98,000)
- 不可使用约数或文字描述
- confidence 使用整数 0-100其他价格使用浮点数
---
# 最终检查清单(开仓前必须全部通过)