MCPcopy Create free account
hub / github.com/astercloud/aster / CompressSection

Method CompressSection

pkg/agent/prompt_compressor_llm.go:72–94  ·  view source on GitHub ↗

CompressSection 压缩单个段落

(ctx context.Context, section string, targetLength int)

Source from the content-addressed store, hash-verified

70
71// CompressSection 压缩单个段落
72func (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 构建压缩提示词
97func (c *LLMPromptCompressor) buildCompressionPrompt(targetLength int, preserveSections []string, level int) string {

Callers

nothing calls this directly

Calls 2

CompleteMethod · 0.65

Tested by

no test coverage detected