-
Notifications
You must be signed in to change notification settings - Fork 523
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
Translate Pydantic models into a regular expression that accept the corresponding YAML #923
Comments
I love the idea, yaml uses fewer syntactic tokens and allows language models to generate without needing to keep track of as much "nesting" / context. Here's what I'm thinking for a strategy, would love to hear your thoughts: We should refactor class JSONSchemaRegexGenerator:
def __init__(self):
self.handlers = {
"string": self.handle_string,
"array": self.handle_array,
...
}
@classmethod
def get_pattern(cls, schema):
return cls().handle_node(schema)
def get_pattern(self, node):
handler = self.handlers.get(node["type"], self.handle_default)
return handler(node)
def handle_string(self, node):
return STRING
def handle_array(self, node):
...
return rf"\[{whitespace_pattern}({'|'.join(regexes)})(,{whitespace_pattern}({'|'.join(regexes)})){num_repeats}){allow_empty}{whitespace_pattern}\]"
class YAMLSchemaRegexGenerator(JSONSchemaRegexGenerator):
def handle_array(self, node):
"""handle format for yaml arrays:
- elem0
- elem1
"""
... This would make the code more readable, extensible, reduce technical debt, and make it so we don't have to have conditional handling for a passed |
I can get on board with this. To follow |
No description provided.
The text was updated successfully, but these errors were encountered: