shouldCompress 判断是否需要压缩
(prompt string, ctx *PromptContext)
| 164 | |
| 165 | // shouldCompress 判断是否需要压缩 |
| 166 | func (pb *PromptBuilder) shouldCompress(prompt string, ctx *PromptContext) bool { |
| 167 | if pb.compressor == nil { |
| 168 | return false |
| 169 | } |
| 170 | |
| 171 | // 检查模板配置 |
| 172 | if ctx.Template == nil || ctx.Template.Runtime == nil || ctx.Template.Runtime.PromptCompression == nil { |
| 173 | return false |
| 174 | } |
| 175 | |
| 176 | config := ctx.Template.Runtime.PromptCompression |
| 177 | if !config.Enabled { |
| 178 | return false |
| 179 | } |
| 180 | |
| 181 | // 检查长度阈值 |
| 182 | maxLength := config.MaxLength |
| 183 | if maxLength == 0 { |
| 184 | maxLength = 5000 // 默认阈值 |
| 185 | } |
| 186 | |
| 187 | return len(prompt) > maxLength |
| 188 | } |
| 189 | |
| 190 | // compress 执行压缩 |
| 191 | func (pb *PromptBuilder) compress(ctx context.Context, prompt string, pCtx *PromptContext) (string, error) { |