executeStreamingWorkflow 执行 workflow(流式)
(ctx context.Context, input *WorkflowInput)
| 115 | |
| 116 | // executeStreamingWorkflow 执行 workflow(流式) |
| 117 | func (wa *WorkflowAgent) executeStreamingWorkflow(ctx context.Context, input *WorkflowInput) (any, error) { |
| 118 | resultChan := make(chan any, 100) |
| 119 | |
| 120 | go func() { |
| 121 | defer close(resultChan) |
| 122 | |
| 123 | reader := wa.workflow.Execute(ctx, input) |
| 124 | for { |
| 125 | event, err := reader.Recv() |
| 126 | if err != nil { |
| 127 | if errors.Is(err, io.EOF) { |
| 128 | break |
| 129 | } |
| 130 | resultChan <- map[string]any{"error": err.Error()} |
| 131 | continue |
| 132 | } |
| 133 | resultChan <- event |
| 134 | } |
| 135 | }() |
| 136 | |
| 137 | return resultChan, nil |
| 138 | } |
| 139 | |
| 140 | // formatOutput 格式化输出为字符串 |
| 141 | func (wa *WorkflowAgent) formatOutput(output any) string { |
no test coverage detected