Elron commited on
Commit
975173b
1 Parent(s): d5c8a0f

Upload system_prompts.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. system_prompts.py +40 -0
system_prompts.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from abc import abstractmethod
2
+ from typing import Any, Dict, Optional
3
+
4
+ from .dataclass import NonPositionalField
5
+ from .operator import StreamInstanceOperator
6
+
7
+
8
+ class SystemPrompt(StreamInstanceOperator):
9
+ """The role of SystemPrompt is to add task-independent opening-text to every instance."""
10
+
11
+ skip_rendered_instance: bool = NonPositionalField(default=True)
12
+
13
+ def process(
14
+ self, instance: Dict[str, Any], stream_name: Optional[str] = None
15
+ ) -> Dict[str, Any]:
16
+ if self.skip_rendered_instance:
17
+ if "system_prompt" in instance:
18
+ return instance
19
+
20
+ instance["system_prompt"] = self.get_system_prompt(instance)
21
+
22
+ return instance
23
+
24
+ @abstractmethod
25
+ def get_system_prompt(self, instance: Dict[str, object]) -> str:
26
+ pass
27
+
28
+
29
+ class TextualSystemPrompt(SystemPrompt):
30
+ """Specifies the system prompt as a totally independent string."""
31
+
32
+ text: str
33
+
34
+ def get_system_prompt(self, instance: Dict[str, object]) -> str:
35
+ return self.text
36
+
37
+
38
+ class EmptySystemPrompt(SystemPrompt):
39
+ def get_system_prompt(self, instance: Dict[str, object]) -> str:
40
+ return ""