Add support for Component specified parsing and return type typing #236
jakelorocco
started this conversation in
Ideas
Replies: 1 comment
-
This is okay. We just need to provide an example (and maybe also a helper factory/method/function) for doing this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal
If we define
Components as a generic, we can use that typing information to encode the expected parsed_repr type of theModelOutputThunkreturned when generating from that component. For example:Each component will then be required to specify a parsing function to achieve the return type. This parsing function will be called after a generation request is done automatically. We can include helper functions to get this value by default (ie instead of
mot.avalue(), we could definemot.aparsed_value()which returns the parsed / typed value).This parsing function will also be responsible for handling any errors that arise during the parsing. Any errors raised during the parsing function will be propagated by Mellea.
As a part of this, we should also consider changing the naming of these fields within
ModelOutputThunks so that it's clear which value is the parsed/typed value and which is the underlying, raw string.Here is a simplified implementation of what this might look like in Mellea with the inferred types as comments:
Potential Issues:
low_grade = gen(bad_essay)line in the example above. In other words, subclasses are constrained to their parent class' return type.formatparameter as a return type. Instead, a generation that utilizes a generic component and a structured outputformatdirective will still show its return type as the defaultstr. To get a typed output, you will have to define a new component that parses that structured output.Beta Was this translation helpful? Give feedback.
All reactions