parseStepResponse 解析步骤响应
(response *provider.CompleteResponse)
| 177 | |
| 178 | // parseStepResponse 解析步骤响应 |
| 179 | func (e *Engine) parseStepResponse(response *provider.CompleteResponse) (*Step, error) { |
| 180 | // 提取文本内容 |
| 181 | text := "" |
| 182 | var textSb182 strings.Builder |
| 183 | for _, block := range response.Message.ContentBlocks { |
| 184 | if textBlock, ok := block.(*types.TextBlock); ok { |
| 185 | textSb182.WriteString(textBlock.Text) |
| 186 | } |
| 187 | } |
| 188 | text += textSb182.String() |
| 189 | |
| 190 | // 尝试 JSON 解析 |
| 191 | if e.config.UseJSON { |
| 192 | step, err := e.parseJSONStep(text) |
| 193 | if err == nil { |
| 194 | return step, nil |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | // 回退到文本解析 |
| 199 | return e.parseTextStep(text) |
| 200 | } |
| 201 | |
| 202 | // parseJSONStep 解析 JSON 格式的步骤 |
| 203 | func (e *Engine) parseJSONStep(text string) (*Step, error) { |
no test coverage detected