-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #517 from guardrails-ai/skeleton-reask-engineering
Skeleton reask prompt engineering
- Loading branch information
Showing
6 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,9 @@ def __init__( | |
self.description = description | ||
self.optional = optional | ||
|
||
def get_example(self): | ||
raise NotImplementedError | ||
|
||
@property | ||
def validators(self) -> TypedList: | ||
return self.validators_attr.validators | ||
|
@@ -188,6 +191,9 @@ class String(ScalarType): | |
|
||
tag = "string" | ||
|
||
def get_example(self): | ||
return "string" | ||
|
||
def from_str(self, s: str) -> Optional[str]: | ||
"""Create a String from a string.""" | ||
return to_string(s) | ||
|
@@ -214,6 +220,9 @@ class Integer(ScalarType): | |
|
||
tag = "integer" | ||
|
||
def get_example(self): | ||
return 1 | ||
|
||
def from_str(self, s: str) -> Optional[int]: | ||
"""Create an Integer from a string.""" | ||
return to_int(s) | ||
|
@@ -225,6 +234,9 @@ class Float(ScalarType): | |
|
||
tag = "float" | ||
|
||
def get_example(self): | ||
return 1.5 | ||
|
||
def from_str(self, s: str) -> Optional[float]: | ||
"""Create a Float from a string.""" | ||
return to_float(s) | ||
|
@@ -236,6 +248,9 @@ class Boolean(ScalarType): | |
|
||
tag = "bool" | ||
|
||
def get_example(self): | ||
return True | ||
|
||
def from_str(self, s: Union[str, bool]) -> Optional[bool]: | ||
"""Create a Boolean from a string.""" | ||
if s is None: | ||
|
@@ -273,6 +288,9 @@ def __init__( | |
super().__init__(children, validators_attr, optional, name, description) | ||
self.date_format = None | ||
|
||
def get_example(self): | ||
return datetime.date.today() | ||
|
||
def from_str(self, s: str) -> Optional[datetime.date]: | ||
"""Create a Date from a string.""" | ||
if s is None: | ||
|
@@ -312,6 +330,9 @@ def __init__( | |
self.time_format = "%H:%M:%S" | ||
super().__init__(children, validators_attr, optional, name, description) | ||
|
||
def get_example(self): | ||
return datetime.time() | ||
|
||
def from_str(self, s: str) -> Optional[datetime.time]: | ||
"""Create a Time from a string.""" | ||
if s is None: | ||
|
@@ -340,6 +361,9 @@ def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | ||
deprecate_type(type(self)) | ||
|
||
def get_example(self): | ||
return "[email protected]" | ||
|
||
|
||
@deprecate_type | ||
@register_type("url") | ||
|
@@ -352,6 +376,9 @@ def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | ||
deprecate_type(type(self)) | ||
|
||
def get_example(self): | ||
return "https://example.com" | ||
|
||
|
||
@deprecate_type | ||
@register_type("pythoncode") | ||
|
@@ -364,6 +391,9 @@ def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | ||
deprecate_type(type(self)) | ||
|
||
def get_example(self): | ||
return "print('hello world')" | ||
|
||
|
||
@deprecate_type | ||
@register_type("sql") | ||
|
@@ -376,13 +406,19 @@ def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | ||
deprecate_type(type(self)) | ||
|
||
def get_example(self): | ||
return "SELECT * FROM table" | ||
|
||
|
||
@register_type("percentage") | ||
class Percentage(ScalarType): | ||
"""Element tag: `<percentage>`""" | ||
|
||
tag = "percentage" | ||
|
||
def get_example(self): | ||
return "20%" | ||
|
||
|
||
@register_type("enum") | ||
class Enum(ScalarType): | ||
|
@@ -402,6 +438,9 @@ def __init__( | |
super().__init__(children, validators_attr, optional, name, description) | ||
self.enum_values = enum_values | ||
|
||
def get_example(self): | ||
return self.enum_values[0] | ||
|
||
def from_str(self, s: str) -> Optional[str]: | ||
"""Create an Enum from a string.""" | ||
if s is None: | ||
|
@@ -434,6 +473,9 @@ class List(NonScalarType): | |
|
||
tag = "list" | ||
|
||
def get_example(self): | ||
return [e.get_example() for e in self._children.values()] | ||
|
||
def collect_validation( | ||
self, | ||
key: str, | ||
|
@@ -476,6 +518,9 @@ class Object(NonScalarType): | |
|
||
tag = "object" | ||
|
||
def get_example(self): | ||
return {k: v.get_example() for k, v in self._children.items()} | ||
|
||
def collect_validation( | ||
self, | ||
key: str, | ||
|
@@ -546,6 +591,14 @@ def __init__( | |
super().__init__(children, validators_attr, optional, name, description) | ||
self.discriminator_key = discriminator_key | ||
|
||
def get_example(self): | ||
first_discriminator = list(self._children.keys())[0] | ||
first_child = list(self._children.values())[0] | ||
return { | ||
self.discriminator_key: first_discriminator, | ||
**first_child.get_example(), | ||
} | ||
|
||
@classmethod | ||
def from_xml(cls, element: ET._Element, strict: bool = False, **kwargs) -> Self: | ||
# grab `discriminator` attribute | ||
|
@@ -606,6 +659,9 @@ def __init__( | |
) -> None: | ||
super().__init__(children, validators_attr, optional, name, description) | ||
|
||
def get_example(self): | ||
return {k: v.get_example() for k, v in self._children.items()} | ||
|
||
def collect_validation( | ||
self, | ||
key: str, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters