Prompting: response_model | schema does not work with Enum
class Armor(str, Enum):
leather = "leather"
chainmail = "chainmail"
plate = "plate"
class Character(BaseModel):
"""
A character in a fantasy world.
"""
name: constr(max_length=12)
armor: Armor
strength: int
@text.prompt
def ppt(response_model):
"""Make A character in a fantasy world.
RESPONSE FORMAT:
{{ response_model | schema }}
"""
print(ppt(Character))
Get error KeyError: 'properties'
If remove armor from Character this works fine
Thanks! Feel free to open a PR to fix this, it shouldn't be a big change to the current logic.
It looks like this is a feature request for Enum and constr prompts, and it's not entirely clear to me how we should translate those to prompts. Do we want them to take their JSON schema formats?
Hey guys, I'm about to rewrite text.prompts.parse_pydantic_schema
Based on :
class JokeType(str, Enum):
dark = "dark"
light = "light"
class Joke(BaseModel):
joke: str
type: JokeType = Field(..., description="description_value")
explanation: str
@text.prompt
def prompt_func(response_model):
"""Make a joke about c++.
RESPONSE FORMAT:
{{ response_model | schema }}
"""
prompt = prompt_func(Joke)
#Make a joke about c++.
#RESPONSE FORMAT:
#{
# "joke": "<joke>",
# "type": "description_value",
# "explanation": "<explanation>"
#}
But I have few questions of improvements, do you have a topic where you decided how "<value>" should be displayed ?
-
Do we want to keep
Optional[Any]fields ?we can loop on required
- What about fields with default values ? should user don't use it ?
-
iterable display :
"<[value1, ..., value_n]>" -
constr : should we display
"<value | **constr_kwarg>"could pop
titleandtypeNeed to check nested ones to be sure, but could pop also "required" values -
add type ?
"<value | type>"handle primitive or most used/adopt by python community only
-
add description
Field(..., description='my custom description)->"<value | description>" -
handle Validator and transcribe into description
use transformer to explain the code within ? might be dangerous
Values will look like this in the prompt :
"<value | type | **constr_kwargs & description>"
What about it, if you have ideas or no go, let me know
The get_schema function in outlines.templates.py should use the outlines.types.JsonSchema class.