Skip to content

Commit

Permalink
feat: Updated dspy/teleprompt/ensemble.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Dec 20, 2023
1 parent 930f948 commit 09314f6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions dspy/teleprompt/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@ def __init__(self, *, reduce_fn=None, size=None, deterministic=False):
self.size = size
self.deterministic = deterministic

def compile(self, programs):
async def compile(self, programs):
size = self.size
reduce_fn = self.reduce_fn

import dspy
import asyncio
class EnsembledProgram(dspy.Module):
def __init__(self):
super().__init__()
self.programs = programs

def forward(self, *args, **kwargs):
programs = random.sample(self.programs, size) if size else self.programs
outputs = [prog(*args, **kwargs) for prog in programs]
async def gather_outputs():
return [await prog(*args, **kwargs) for prog in programs]

outputs = asyncio.run(gather_outputs())

if reduce_fn:
return reduce_fn(outputs)
Expand Down

0 comments on commit 09314f6

Please sign in to comment.