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

Function demonstrateSummary

examples/session-enhanced/main.go:97–140  ·  view source on GitHub ↗
(ctx context.Context, agentID string, st store.Store, provFactory provider.Factory)

Source from the content-addressed store, hash-verified

95}
96
97func demonstrateSummary(ctx context.Context, agentID string, st store.Store, provFactory provider.Factory) {
98 // 加载消息
99 messages, err := st.LoadMessages(ctx, agentID)
100 if err != nil {
101 log.Printf("Failed to load messages: %v", err)
102 return
103 }
104
105 // 创建 Provider
106 prov, err := provFactory.Create(&types.ModelConfig{
107 Provider: "anthropic",
108 Model: "claude-3-5-sonnet-20241022",
109 })
110 if err != nil {
111 log.Printf("Failed to create provider: %v", err)
112 return
113 }
114 defer func() {
115 if err := prov.Close(); err != nil {
116 log.Printf("Failed to close provider: %v", err)
117 }
118 }()
119
120 // 创建摘要器
121 summarizer := session.NewSummarizer(session.SummarizerConfig{
122 Provider: prov,
123 MaxMessagesPerCall: 50,
124 MinMessagesToSummarize: 3,
125 })
126
127 // 生成摘要
128 summary, err := summarizer.SummarizeSession(ctx, messages)
129 if err != nil {
130 log.Printf("Failed to generate summary: %v", err)
131 return
132 }
133
134 fmt.Printf("Summary (%d messages):\n", summary.MessageCount)
135 fmt.Printf("%s\n", truncate(summary.Text, 200))
136
137 if len(summary.KeyTopics) > 0 {
138 fmt.Printf("Key Topics: %v\n", summary.KeyTopics)
139 }
140}
141
142func demonstrateSearch(ctx context.Context, agentID string, st store.Store) {
143 // 创建搜索器

Callers 1

mainFunction · 0.85

Calls 7

SummarizeSessionMethod · 0.95
NewSummarizerFunction · 0.92
PrintfMethod · 0.80
truncateFunction · 0.70
LoadMessagesMethod · 0.65
CreateMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected