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

Method parseJSONStep

pkg/reasoning/engine.go:203–223  ·  view source on GitHub ↗

parseJSONStep 解析 JSON 格式的步骤

(text string)

Source from the content-addressed store, hash-verified

201
202// parseJSONStep 解析 JSON 格式的步骤
203func (e *Engine) parseJSONStep(text string) (*Step, error) {
204 // 提取 JSON 代码块
205 jsonPattern := regexp.MustCompile("```json\\s*\\n([\\s\\S]*?)\\n```")
206 matches := jsonPattern.FindStringSubmatch(text)
207
208 var jsonText string
209 if len(matches) > 1 {
210 jsonText = matches[1]
211 } else {
212 // 尝试直接解析整个文本
213 jsonText = text
214 }
215
216 var step Step
217 if err := json.Unmarshal([]byte(jsonText), &step); err != nil {
218 return nil, fmt.Errorf("unmarshal json step: %w", err)
219 }
220
221 step.Status = StepStatusCompleted
222 return &step, nil
223}
224
225// parseTextStep 解析文本格式的步骤
226func (e *Engine) parseTextStep(text string) (*Step, error) {

Callers 1

parseStepResponseMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected