-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt_wrapper.py
115 lines (95 loc) · 3.71 KB
/
prompt_wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from enum import Enum
import json
class DecisionOption(Enum):
YES = "YES"
NO = "NO"
UNDECIDED = "UNDECIDED"
ALL_DECISION_OPTIONS = [DecisionOption.YES,
DecisionOption.NO, DecisionOption.UNDECIDED]
class OutputComponentType(Enum):
DECISION = "DECISION"
FRAMEWORK_EXPLANATION = "FRAMEWORK_EXPLANATION"
DECISION_REASON = "DECISION_REASON"
class OutputStructure:
def __init__(self, sorted_output_components: list[OutputComponentType], sorted_decision_options: list[DecisionOption], first_unstructred_output: bool):
self.sorted_output_components = sorted_output_components
self.sorted_decision_options = sorted_decision_options
self.first_unstructred_output = first_unstructred_output
def to_dict(self):
return {
"sorted_output_components": [component.value for component in self.sorted_output_components],
"sorted_decision_options": [option.value for option in self.sorted_decision_options],
"first_unstructred_output": self.first_unstructred_output,
}
@classmethod
def from_dict(cls, data: dict):
"""
Create an OutputStructure object from a dictionary.
"""
return cls(
sorted_output_components=[OutputComponentType(
component) for component in data["sorted_output_components"]],
sorted_decision_options=[DecisionOption(
option) for option in data["sorted_decision_options"]],
first_unstructred_output=data["first_unstructred_output"],
)
class PromptWrapper:
def __init__(
self,
prompts: list[str],
dilemma_identifier: str,
framework_identifier: str,
base_prompt_identifier: str,
output_structure: OutputStructure,
version: str,
):
self.prompts = prompts
self.dilemma_identifier = dilemma_identifier
self.framework_identifier = framework_identifier
self.base_prompt_identifier = base_prompt_identifier
self.output_structure = output_structure
self.version = version
def __str__(self):
str = "--------PromptWrapper--------"
for prompt in self.prompts:
str += f"\nprompt:\n{prompt}"
str += "-----------------------------"
return str
def to_dict(self):
return {
"prompts": self.prompts,
"dilemma_identifier": self.dilemma_identifier,
"framework_identifier": self.framework_identifier,
"base_prompt_identifier": self.base_prompt_identifier,
"output_structure": self.output_structure.to_dict(),
"version": self.version,
}
@classmethod
def from_dict(cls, data: dict):
"""
Create a PromptWrapper object from a dictionary.
"""
return cls(
prompts=data["prompts"],
dilemma_identifier=data["dilemma_identifier"],
framework_identifier=data["framework_identifier"],
base_prompt_identifier=data["base_prompt_identifier"],
output_structure=OutputStructure.from_dict(
data["output_structure"]),
version=data["version"],
)
class Model(Enum):
GPT4O = "gpt-4o"
class Response:
def __init__(self, wrapped_prompt: PromptWrapper, decision: DecisionOption, model: Model, messages: list[str]):
self.wrapped_prompt = wrapped_prompt
self.decision = decision
self.model = model
self.messages = messages
def to_dict(self):
return {
"wrapped_prompt": self.wrapped_prompt.to_dict(),
"decision": self.decision.value,
"model": self.model.value,
"messages": self.messages,
}