@@ -21,14 +21,21 @@ class PromptMixin:
2121 eg: [BaseSynthesizer][ragas.testset.synthesizers.base.BaseSynthesizer], [MetricWithLLM][ragas.metrics.base.MetricWithLLM]
2222 """
2323
24+ def _get_prompts (self ) -> t .Dict [str , PydanticPrompt ]:
25+
26+ prompts = {}
27+ for key , value in inspect .getmembers (self ):
28+ if isinstance (value , PydanticPrompt ):
29+ prompts .update ({key : value })
30+ return prompts
31+
2432 def get_prompts (self ) -> t .Dict [str , PydanticPrompt ]:
2533 """
2634 Returns a dictionary of prompts for the class.
2735 """
2836 prompts = {}
29- for name , value in inspect .getmembers (self ):
30- if isinstance (value , PydanticPrompt ):
31- prompts .update ({name : value })
37+ for _ , value in self ._get_prompts ().items ():
38+ prompts .update ({value .name : value })
3239 return prompts
3340
3441 def set_prompts (self , ** prompts ):
@@ -41,6 +48,7 @@ def set_prompts(self, **prompts):
4148 If the prompt is not an instance of `PydanticPrompt`.
4249 """
4350 available_prompts = self .get_prompts ()
51+ name_to_var = {v .name : k for k , v in self ._get_prompts ().items ()}
4452 for key , value in prompts .items ():
4553 if key not in available_prompts :
4654 raise ValueError (
@@ -50,7 +58,7 @@ def set_prompts(self, **prompts):
5058 raise ValueError (
5159 f"Prompt with name '{ key } ' must be an instance of 'ragas.prompt.PydanticPrompt'"
5260 )
53- setattr (self , key , value )
61+ setattr (self , name_to_var [ key ] , value )
5462
5563 async def adapt_prompts (
5664 self , language : str , llm : BaseRagasLLM , adapt_instruction : bool = False
0 commit comments