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

Method parseTextStep

pkg/reasoning/engine.go:226–277  ·  view source on GitHub ↗

parseTextStep 解析文本格式的步骤

(text string)

Source from the content-addressed store, hash-verified

224
225// parseTextStep 解析文本格式的步骤
226func (e *Engine) parseTextStep(text string) (*Step, error) {
227 step := &Step{
228 Status: StepStatusCompleted,
229 Confidence: 0.8, // 默认置信度
230 NextAction: NextActionContinue,
231 }
232
233 // 提取标题
234 titlePattern := regexp.MustCompile(`(?i)(?:title|step):\s*(.+)`)
235 if matches := titlePattern.FindStringSubmatch(text); len(matches) > 1 {
236 step.Title = strings.TrimSpace(matches[1])
237 }
238
239 // 提取行动
240 actionPattern := regexp.MustCompile(`(?i)action:\s*(.+)`)
241 if matches := actionPattern.FindStringSubmatch(text); len(matches) > 1 {
242 step.Action = strings.TrimSpace(matches[1])
243 }
244
245 // 提取推理
246 reasoningPattern := regexp.MustCompile(`(?i)reasoning:\s*(.+)`)
247 if matches := reasoningPattern.FindStringSubmatch(text); len(matches) > 1 {
248 step.Reasoning = strings.TrimSpace(matches[1])
249 }
250
251 // 提取结果
252 resultPattern := regexp.MustCompile(`(?i)result:\s*(.+)`)
253 if matches := resultPattern.FindStringSubmatch(text); len(matches) > 1 {
254 step.Result = strings.TrimSpace(matches[1])
255 }
256
257 // 提取置信度
258 confidencePattern := regexp.MustCompile(`(?i)confidence:\s*(0?\.\d+|1\.0?)`)
259 if matches := confidencePattern.FindStringSubmatch(text); len(matches) > 1 {
260 _, _ = fmt.Sscanf(matches[1], "%f", &step.Confidence)
261 }
262
263 // 提取下一步行动
264 if strings.Contains(strings.ToLower(text), "complete") {
265 step.NextAction = NextActionComplete
266 } else if strings.Contains(strings.ToLower(text), "retry") {
267 step.NextAction = NextActionRetry
268 }
269
270 // 如果没有提取到标题,使用整个文本作为结果
271 if step.Title == "" && step.Result == "" {
272 step.Result = text
273 step.Title = "Reasoning step"
274 }
275
276 return step, nil
277}

Callers 1

parseStepResponseMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected