1+ import typing
2+
3+
14class PromptTemplateAdapter :
2- """ Makes DSPy base prompts better with custom model templates, for an enhanced text output. """
5+ """Makes DSPy base prompts better with custom model templates, for an enhanced text output."""
36
4- templates = {
7+ templates : typing . ClassVar = {
58 "mistral" : "[INST] {prompt} [/INST]" ,
6- "llama" : "<s>[INST] {prompt} [/INST]" ,
7- "chatml" : "<|im_start|>user\n {prompt}<|im_end|>\n <|im_start|>assistant" ,
9+ "llama" : "<s>[INST] {prompt} [/INST]" ,
10+ "chatml" : "<|im_start|>user\n {prompt}<|im_end|>\n <|im_start|>assistant" ,
811 "default" : "{prompt}" ,
912 }
1013 # Templates currently made for only 3 models as samples. This can be extended.
1114 # (function written below
1215
13-
1416 def __init__ (self , model_family : str = "default" ):
1517 if model_family not in self .templates :
1618 self .template = self .templates ["default" ]
1719 else :
1820 self .template = self .templates [model_family ]
19-
20- self .model_family = model_family
2121
22+ self .model_family = model_family
2223
2324 def wrap (self , prompt : str ) -> str :
25+ """Wqrap the prompt according to the model family template."""
2426 return self .template .format (prompt = prompt )
25-
26-
27- # Makes addition of models and the templates possible.
28- @classmethod
29- def register_template (cls , name : str , template : str ) -> None :
30- """Allow users to add custom model families."""
31- cls .templates [name ] = template
0 commit comments