Skip to content

Conversation

@datvo06
Copy link

@datvo06 datvo06 commented Dec 22, 2025

Summarize changes:

  1. Adding Optional Template parameter to decode
  2. Use the Template to gather lexical context for decoding synthesized function
  3. Simplify ProgramSynthesisHandler.

@datvo06 datvo06 requested review from eb8680 and jfeser December 22, 2025 20:13
@classmethod
@abstractmethod
def decode(cls, vl: U) -> T:
def decode(cls, vl: U, template: typing.Any = None) -> T:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encode and decode are intended mainly to deal with types that have special meaning for the LLM api. We shouldn't extend the interface in this way.


# Start with provided context or empty dict
# Include collections module for type hints in synthesized code
exec_globals: dict[str, typing.Any] = {"collections": collections}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The synthesized code should have imports for types or they should come from the lexical context.

_decode_counter: typing.ClassVar[int] = 0

@classmethod
def decode(cls, vl: SynthesizedFunction, template: typing.Any = None) -> Callable:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a decode_response handler, rather than changing the decode interface.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! it makes sense, so we add an indirection between the LLM response and decode?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented it, but I'm not sure it's the cleanest implementation, mainly in how we would pass context to decode, because context has to be bound before executing the returned code.

Comment on lines 86 to 89
context: LexicalContext | None = None
if template is not None and hasattr(template, "__context__"):
ctx = template.__context__
context = ctx if isinstance(ctx, LexicalContext) else LexicalContext(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should assume there is always a lexical context.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've updated it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants