executeReasoningStep 执行单个推理步骤
(ctx context.Context, chain *Chain, basePrompt string)
| 86 | |
| 87 | // executeReasoningStep 执行单个推理步骤 |
| 88 | func (e *Engine) executeReasoningStep(ctx context.Context, chain *Chain, basePrompt string) (*Step, error) { |
| 89 | // 构建当前步骤的提示词 |
| 90 | prompt := e.buildStepPrompt(chain, basePrompt) |
| 91 | |
| 92 | // 调用 Provider |
| 93 | messages := []types.Message{ |
| 94 | { |
| 95 | Role: types.MessageRoleUser, |
| 96 | ContentBlocks: []types.ContentBlock{ |
| 97 | &types.TextBlock{Text: prompt}, |
| 98 | }, |
| 99 | }, |
| 100 | } |
| 101 | |
| 102 | response, err := e.provider.Complete(ctx, messages, nil) |
| 103 | if err != nil { |
| 104 | return nil, fmt.Errorf("provider complete: %w", err) |
| 105 | } |
| 106 | |
| 107 | // 解析响应 |
| 108 | step, err := e.parseStepResponse(response) |
| 109 | if err != nil { |
| 110 | return nil, fmt.Errorf("parse step response: %w", err) |
| 111 | } |
| 112 | |
| 113 | return step, nil |
| 114 | } |
| 115 | |
| 116 | // buildReasoningPrompt 构建推理提示词 |
| 117 | func (e *Engine) buildReasoningPrompt(query string, systemPrompt string) string { |
no test coverage detected