ExtractAndParse 提取 JSON 并解析为通用 map
(ctx context.Context, text string)
| 77 | |
| 78 | // ExtractAndParse 提取 JSON 并解析为通用 map |
| 79 | func (tp *TypedParser) ExtractAndParse(ctx context.Context, text string) (map[string]any, error) { |
| 80 | rawJSON, err := extractJSONSegment(text) |
| 81 | if err != nil { |
| 82 | return nil, fmt.Errorf("extract json: %w", err) |
| 83 | } |
| 84 | |
| 85 | var result map[string]any |
| 86 | if err := json.Unmarshal([]byte(rawJSON), &result); err != nil { |
| 87 | return nil, fmt.Errorf("unmarshal json: %w", err) |
| 88 | } |
| 89 | |
| 90 | return result, nil |
| 91 | } |
| 92 | |
| 93 | // TypedOutputSpec 类型化输出规范 |
| 94 | type TypedOutputSpec struct { |
nothing calls this directly
no test coverage detected