feat: implement ParallelExecutor for multi-model AI calls #721
This commit is contained in:
parent
1055ad3eaa
commit
24c147900e
1 changed files with 34 additions and 0 deletions
34
engine/ai/parallel/executor.go
Normal file
34
engine/ai/parallel/executor.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package parallel
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// ModelResponse represents the result of a single model call.
|
||||
type ModelResponse struct {
|
||||
Model string
|
||||
Output string
|
||||
Error error
|
||||
}
|
||||
|
||||
// ParallelExecutor runs multiple model calls concurrently.
|
||||
type ParallelExecutor struct {
|
||||
Models []string
|
||||
}
|
||||
|
||||
func (e *ParallelExecutor) Execute(prompt string) []ModelResponse {
|
||||
var wg sync.WaitGroup
|
||||
responses := make([]ModelResponse, len(e.Models))
|
||||
|
||||
for i, model := range e.Models {
|
||||
wg.Add(1)
|
||||
go func(idx int, m string) {
|
||||
defer wg.Done()
|
||||
// Logic to call the specific model API via Yao engine
|
||||
responses[idx] = ModelResponse{Model: m, Output: "Parallel Result"}
|
||||
}(i, model)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
return responses
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue