Skip to content

[Feature] Make Teleprompt.compile methods more type checker friendly. #9015

@TyTodd

Description

@TyTodd

What feature would you like to see?

In the following code, the type checker won't recognize the member weather_function on compiled_agent because it was returned from MIPROv2.compile.

class MyAgent(Module):
    def __init__(self):
        super().__init__()
        self.predict = dspy.ReAct("question -> answer", tools=[self.weather_function])

    def weather_function(self):
        return random.random()

optimizer = MIPROv2(metric=dspy.evaluate.answer_exact_match, auto="light")
compiled_agent = optimizer.compile(student=MyAgent(), trainset=trainset, teacher=teacher, valset=valset)
print(compiled_agent.weather_function())

This can be a small nuisance for certain workflows where you want to extend the functionality of a dspy.Module with certain functions and attributes. And it can be easily fixed using TypeVars.

Just made the PR #9013 to solve this but realized I should have added an issue first. Also wanted to gauge how important this is to others given its such a small change.

Would you like to contribute?

  • Yes, I'd like to help implement this.
  • No, I just want to request it.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions