compressHybrid 混合压缩(先规则后 LLM)
(ctx context.Context, prompt string, opts *CompressOptions)
| 225 | |
| 226 | // compressHybrid 混合压缩(先规则后 LLM) |
| 227 | func (c *EnhancedPromptCompressor) compressHybrid(ctx context.Context, prompt string, opts *CompressOptions) (string, error) { |
| 228 | // 第一阶段:规则压缩 |
| 229 | simpleCompressed := c.compressSimple(prompt, &CompressOptions{ |
| 230 | TargetLength: int(float64(len(prompt)) * 0.7), // 先压缩到 70% |
| 231 | Level: CompressionLevelLight, |
| 232 | PreserveSections: opts.PreserveSections, |
| 233 | }) |
| 234 | |
| 235 | // 检查是否达到目标 |
| 236 | if opts.TargetLength > 0 && len(simpleCompressed) <= opts.TargetLength { |
| 237 | return simpleCompressed, nil |
| 238 | } |
| 239 | |
| 240 | // 第二阶段:LLM 精压缩 |
| 241 | return c.compressLLM(ctx, simpleCompressed, opts) |
| 242 | } |
| 243 | |
| 244 | // ScoredSection 带评分的段落 |
| 245 | type ScoredSection struct { |
no test coverage detected