File tree Expand file tree Collapse file tree 4 files changed +23
-5
lines changed Expand file tree Collapse file tree 4 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,17 @@ def format(self, **kwargs: Any) -> str:
135
135
prompt.format(variable1="foo")
136
136
"""
137
137
138
+ @property
139
+ @abstractmethod
140
+ def _prompt_type (self ) -> str :
141
+ """Return the prompt type key."""
142
+
143
+ def dict (self , ** kwargs : Any ) -> Dict :
144
+ """Return dictionary representation of prompt."""
145
+ prompt_dict = super ().dict ()
146
+ prompt_dict ["_type" ] = self ._prompt_type
147
+ return prompt_dict
148
+
138
149
def save (self , file_path : Union [Path , str ]) -> None :
139
150
"""Save the prompt.
140
151
Original file line number Diff line number Diff line change @@ -109,11 +109,13 @@ def format(self, **kwargs: Any) -> str:
109
109
# Format the template with the input variables.
110
110
return DEFAULT_FORMATTER_MAPPING [self .template_format ](template , ** kwargs )
111
111
112
+ @property
113
+ def _prompt_type (self ) -> str :
114
+ """Return the prompt type key."""
115
+ return "few_shot"
116
+
112
117
def dict (self , ** kwargs : Any ) -> Dict :
113
118
"""Return a dictionary of the prompt."""
114
119
if self .example_selector :
115
120
raise ValueError ("Saving an example selector is not currently supported" )
116
-
117
- prompt_dict = super ().dict ()
118
- prompt_dict ["_type" ] = "few_shot"
119
- return prompt_dict
121
+ return super ().dict (** kwargs )
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ def _load_few_shot_prompt(config: dict) -> FewShotPromptTemplate:
83
83
)
84
84
config ["example_prompt" ] = load_prompt (config .pop ("example_prompt_path" ))
85
85
else :
86
- config ["example_prompt" ] = _load_prompt (config ["example_prompt" ])
86
+ config ["example_prompt" ] = load_prompt_from_config (config ["example_prompt" ])
87
87
# Load the examples.
88
88
config = _load_examples (config )
89
89
return FewShotPromptTemplate (** config )
Original file line number Diff line number Diff line change @@ -31,6 +31,11 @@ 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
+ @property
35
+ def _prompt_type (self ) -> str :
36
+ """Return the prompt type key."""
37
+ return "prompt"
38
+
34
39
class Config :
35
40
"""Configuration for this pydantic object."""
36
41
You can’t perform that action at this time.
0 commit comments