MCPcopy
hub / github.com/stanfordnlp/dspy / test_syncify_works_with_optimizers

Function test_syncify_works_with_optimizers

tests/utils/test_syncify.py:28–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26
27
28def test_syncify_works_with_optimizers():
29 class MyProgram(dspy.Module):
30 def __init__(self):
31 self.predict = dspy.Predict("question->answer")
32
33 async def aforward(self, question: str):
34 return await self.predict.acall(question=question)
35
36 async_program = MyProgram()
37
38 def dummy_metric(gold, pred, traces=None):
39 return True
40
41 # We only test the optimizer completes without errors, so the LM response doesn't matter.
42 lm = dspy.utils.DummyLM([{"answer": "dummy"} for _ in range(100)])
43 dspy.configure(lm=lm)
44
45 dataset = [dspy.Example(question="question", answer="answer").with_inputs("question") for _ in range(10)]
46
47 optimizer = dspy.BootstrapFewShot(metric=dummy_metric, max_bootstrapped_demos=2, max_labeled_demos=0)
48
49 # Test syncify in place
50 sync_program = dspy.syncify(async_program, in_place=True)
51 optimized_program = optimizer.compile(sync_program, trainset=dataset)
52 assert len(optimized_program.predictors()[0].demos) == 2
53
54 # Test syncify with wrapper
55 sync_program = dspy.syncify(async_program, in_place=False)
56 optimized_program = optimizer.compile(sync_program, trainset=dataset)
57 assert len(optimized_program.predictors()[0].demos) == 2

Callers

nothing calls this directly

Calls 5

compileMethod · 0.95
configureMethod · 0.80
with_inputsMethod · 0.80
predictorsMethod · 0.80
MyProgramClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…