File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,9 @@ class FewShotPromptTemplate(BasePromptTemplate, BaseModel):
41
41
template_format : str = "f-string"
42
42
"""The format of the prompt template. Options are: 'f-string', 'jinja2'."""
43
43
44
+ validate_template : bool = True
45
+ """Whether or not to try validating the template."""
46
+
44
47
@root_validator (pre = True )
45
48
def check_examples_and_selector (cls , values : Dict ) -> Dict :
46
49
"""Check that one and only one of examples/example_selector are provided."""
@@ -61,11 +64,12 @@ def check_examples_and_selector(cls, values: Dict) -> Dict:
61
64
@root_validator ()
62
65
def template_is_valid (cls , values : Dict ) -> Dict :
63
66
"""Check that prefix, suffix and input variables are consistent."""
64
- check_valid_template (
65
- values ["prefix" ] + values ["suffix" ],
66
- values ["template_format" ],
67
- values ["input_variables" ],
68
- )
67
+ if values ["validate_template" ]:
68
+ check_valid_template (
69
+ values ["prefix" ] + values ["suffix" ],
70
+ values ["template_format" ],
71
+ values ["input_variables" ],
72
+ )
69
73
return values
70
74
71
75
class Config :
Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ class PromptTemplate(BasePromptTemplate, BaseModel):
31
31
template_format : str = "f-string"
32
32
"""The format of the prompt template. Options are: 'f-string', 'jinja2'."""
33
33
34
+ validate_template : bool = True
35
+ """Whether or not to try validating the template."""
36
+
34
37
@property
35
38
def _prompt_type (self ) -> str :
36
39
"""Return the prompt type key."""
@@ -61,9 +64,10 @@ def format(self, **kwargs: Any) -> str:
61
64
@root_validator ()
62
65
def template_is_valid (cls , values : Dict ) -> Dict :
63
66
"""Check that template and input variables are consistent."""
64
- check_valid_template (
65
- values ["template" ], values ["template_format" ], values ["input_variables" ]
66
- )
67
+ if values ["validate_template" ]:
68
+ check_valid_template (
69
+ values ["template" ], values ["template_format" ], values ["input_variables" ]
70
+ )
67
71
return values
68
72
69
73
@classmethod
You can’t perform that action at this time.
0 commit comments