Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signature rework #2033

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

chenmoneygithub
Copy link
Collaborator

@chenmoneygithub chenmoneygithub commented Jan 9, 2025

We are doing a rework of dspy.Signature. This is 98% internal code quality improvement, and our users don't need to be aware of this change at all.

  • We are now abusing the metaclass, which should be kept as small as possible to easy maintenance: https://google.github.io/styleguide/pyguide.html#2194-decision. At this point we cannot get rid of metaclass (and we don't need to), but we should make it as simple as possible. With this PR I am moving methods to class Signature with @classmethod decorator, which does the same job as before.
  • Remove the replace method and update_signature utility function. The history of these 2 methods can be found here: Feature/make signatures replaceable with context manager #1090. But reading the context it's unclear how this in-place swapping helps with i18n. For i18n, we should probably use the translation way instead of having users do challenging hacks with swapping signatures. Furthermore, if users can access the signature, they can set it to a new one, which is how we play with built-in predictors. In all, I don't see the necessity of these 2 methods, while meanwhile they are pretty complex.
  • Add example for confusing methods, e.g., _parse_type_node, which is a very intelligent implementation while very hard to follow without examples.
  • General improvements, including error message, comments, docstring improvements, and variable name changes.

The only risk is update_signature is removed, however I am not aware of any actual usage of it. I am almost sure that users can do similar as our avatar code:

def _update_signature(self, idx: int, omit_action: bool = False):

@chenmoneygithub chenmoneygithub requested a review from okhat January 9, 2025 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant