(no commit message)

This commit is contained in:
2026-02-04 21:37:56 -08:00
parent e17e58bbe4
commit d58378f5e9
10 changed files with 106 additions and 2 deletions

32
program/program.py Normal file
View File

@@ -0,0 +1,32 @@
from typing import Literal
import dspy
from modaic import PrecompiledConfig, PrecompiledProgram
from .mod import function_from_mod # noqa: F401
class Summarize(dspy.Signature):
question = dspy.InputField()
context = dspy.InputField()
answer = dspy.OutputField(desc="Answer to the question, based on the passage")
class ExampleConfig(PrecompiledConfig):
output_type: Literal["bool", "str"]
lm: str = "openai/gpt-4o"
number: int = 1
class ExampleProgram(PrecompiledProgram):
config: ExampleConfig
def __init__(self, config: ExampleConfig, runtime_param: str, **kwargs):
super().__init__(config, **kwargs)
self.predictor = dspy.Predict(Summarize)
self.predictor.lm = dspy.LM(self.config.lm)
self.runtime_param = runtime_param
def forward(self, question: str, context: str) -> str:
return self.predictor(question=question, context=context)