CompressSection 压缩单个段落
(ctx context.Context, section string, targetLength int)
| 70 | |
| 71 | // CompressSection 压缩单个段落 |
| 72 | func (c *LLMPromptCompressor) CompressSection(ctx context.Context, section string, targetLength int) (string, error) { |
| 73 | systemPrompt := c.buildSectionCompressionPrompt(targetLength) |
| 74 | |
| 75 | messages := []types.Message{ |
| 76 | { |
| 77 | Role: "user", |
| 78 | Content: section, |
| 79 | }, |
| 80 | } |
| 81 | |
| 82 | opts := &provider.StreamOptions{ |
| 83 | System: systemPrompt, |
| 84 | Temperature: 0.3, |
| 85 | MaxTokens: targetLength * 4 / 3, |
| 86 | } |
| 87 | |
| 88 | response, err := c.provider.Complete(ctx, messages, opts) |
| 89 | if err != nil { |
| 90 | return "", fmt.Errorf("section compression failed: %w", err) |
| 91 | } |
| 92 | |
| 93 | return response.Message.Content, nil |
| 94 | } |
| 95 | |
| 96 | // buildCompressionPrompt 构建压缩提示词 |
| 97 | func (c *LLMPromptCompressor) buildCompressionPrompt(targetLength int, preserveSections []string, level int) string { |
nothing calls this directly
no test coverage detected