compactFormat 紧凑格式
(prompt string)
| 418 | |
| 419 | // compactFormat 紧凑格式 |
| 420 | func (c *EnhancedPromptCompressor) compactFormat(prompt string) string { |
| 421 | lines := strings.Split(prompt, "\n") |
| 422 | var result []string |
| 423 | |
| 424 | for _, line := range lines { |
| 425 | // 保留缩进,但移除行尾空格 |
| 426 | trimmed := strings.TrimRight(line, " \t") |
| 427 | result = append(result, trimmed) |
| 428 | } |
| 429 | |
| 430 | return strings.Join(result, "\n") |
| 431 | } |
| 432 | |
| 433 | // EstimateTokens 估算 Token 数 |
| 434 | func (c *EnhancedPromptCompressor) EstimateTokens(ctx context.Context, text string) (int, error) { |