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

Method parseSummaryResponse

pkg/memory/session_summary.go:393–435  ·  view source on GitHub ↗
(content string)

Source from the content-addressed store, hash-verified

391}
392
393func (m *SessionSummaryManager) parseSummaryResponse(content string) (*SessionSummary, error) {
394 // 尝试提取 JSON(可能包含在代码块中)
395 jsonContent := extractJSON(content)
396
397 // 解析 JSON
398 var data struct {
399 Summary string `json:"summary"`
400 Topics []string `json:"topics"`
401 KeyPoints []string `json:"key_points"`
402 Decisions []string `json:"decisions"`
403 ActionItems []string `json:"action_items"`
404 }
405
406 if err := json.Unmarshal([]byte(jsonContent), &data); err != nil {
407 return nil, fmt.Errorf("failed to unmarshal JSON: %w", err)
408 }
409
410 // 创建摘要对象
411 summary := &SessionSummary{
412 Summary: data.Summary,
413 Topics: data.Topics,
414 KeyPoints: data.KeyPoints,
415 Decisions: data.Decisions,
416 ActionItems: data.ActionItems,
417 Metadata: make(map[string]any),
418 }
419
420 // 确保切片不为 nil
421 if summary.Topics == nil {
422 summary.Topics = []string{}
423 }
424 if summary.KeyPoints == nil {
425 summary.KeyPoints = []string{}
426 }
427 if summary.Decisions == nil {
428 summary.Decisions = []string{}
429 }
430 if summary.ActionItems == nil {
431 summary.ActionItems = []string{}
432 }
433
434 return summary, nil
435}
436
437func (m *SessionSummaryManager) estimateTokens(messages []types.Message) int {
438 totalTokens := 0

Callers 2

GenerateSummaryMethod · 0.95
UpdateSummaryMethod · 0.95

Calls 1

extractJSONFunction · 0.70

Tested by

no test coverage detected