enricorampazzo commited on
Commit
d680b24
·
1 Parent(s): 88f9105

now taking into account saved details when prompting and parsing the answer of the LLM

Browse files
Files changed (2) hide show
  1. app.py +7 -5
  2. local_storage/ls_manager.py +32 -33
app.py CHANGED
@@ -8,7 +8,7 @@ from streamlit.runtime.scriptrunner_utils.exceptions import StopException
8
  from form.form import build_form_data_from_answers, write_pdf_form, work_categories
9
  from llm_manager.llm_parser import LlmParser
10
  from local_storage.entities import PersonalDetails, LocationDetails, ContractorDetails
11
- from local_storage.ls_manager import save_details, get_detail
12
  from prompts.prompts_manager import PromptsManager
13
  from enums import Questions as Q
14
  from repository.repository import build_repo_from_environment, get_repository
@@ -42,8 +42,9 @@ class UIManager:
42
  self.pm: PromptsManager = PromptsManager(work_categories=work_categories)
43
  self.repository = (build_repo_from_environment(self.pm.system_prompt) or
44
  get_repository("testing",
45
- Model("fakeModel", ModelRoles("a", "b", "c"))))
46
-
 
47
  @staticmethod
48
  def get_current_step() -> int:
49
  try:
@@ -76,8 +77,9 @@ class UIManager:
76
  def build_ui_for_parsing_answers(self):
77
  self._build_base_ui()
78
  with st.status("parsing user input for tags"):
 
79
  tags = find_tags_regex.findall(ss["user_input"])
80
- details = [get_detail(t) for t in tags]
81
  with st.status("initialising LLM"):
82
  self.repository.init()
83
  with st.status("waiting for LLM"):
@@ -140,7 +142,7 @@ class UIManager:
140
  details = func(details_key)
141
  if details:
142
  key = ss[details_key] # get the name under which this data should be saved
143
- save_details(details, key)
144
  self.set_current_step(Steps.FIND_CATEGORIES)
145
  st.rerun()
146
 
 
8
  from form.form import build_form_data_from_answers, write_pdf_form, work_categories
9
  from llm_manager.llm_parser import LlmParser
10
  from local_storage.entities import PersonalDetails, LocationDetails, ContractorDetails
11
+ from local_storage.ls_manager import LocalStorageManager
12
  from prompts.prompts_manager import PromptsManager
13
  from enums import Questions as Q
14
  from repository.repository import build_repo_from_environment, get_repository
 
42
  self.pm: PromptsManager = PromptsManager(work_categories=work_categories)
43
  self.repository = (build_repo_from_environment(self.pm.system_prompt) or
44
  get_repository("testing",
45
+ Model("fakeModel",
46
+ ModelRoles("a", "b", "c"))))
47
+ self.lsm = None
48
  @staticmethod
49
  def get_current_step() -> int:
50
  try:
 
77
  def build_ui_for_parsing_answers(self):
78
  self._build_base_ui()
79
  with st.status("parsing user input for tags"):
80
+ self.lsm = LocalStorageManager() if not self.lsm else self.lsm
81
  tags = find_tags_regex.findall(ss["user_input"])
82
+ details = [self.lsm.get_detail(t) for t in tags]
83
  with st.status("initialising LLM"):
84
  self.repository.init()
85
  with st.status("waiting for LLM"):
 
142
  details = func(details_key)
143
  if details:
144
  key = ss[details_key] # get the name under which this data should be saved
145
+ self.lsm.save_details(details, key)
146
  self.set_current_step(Steps.FIND_CATEGORIES)
147
  st.rerun()
148
 
local_storage/ls_manager.py CHANGED
@@ -1,39 +1,38 @@
1
- import json
2
-
3
  from streamlit_local_storage import LocalStorage
4
 
5
  from local_storage.entities import SavedDetails, PersonalDetails, LocationDetails, ContractorDetails
6
  from enums import DetailsType
7
 
8
 
9
- def get_detail(key: str):
10
- for detail_type in DetailsType.values():
11
- detail = LocalStorage(key=detail_type.name).getItem(detail_type.name).get(key)
12
- if detail:
13
- if detail_type.value == DetailsType.PERSONAL_DETAILS.value:
14
- return PersonalDetails(**detail)
15
- elif detail_type.value == DetailsType.LOCATION_DETAILS.value:
16
- return LocationDetails(**detail)
17
- elif detail_type.value == DetailsType.CONTRACTOR_DETAILS.value:
18
- return ContractorDetails(**detail)
19
- return None
20
- return None
21
-
22
-
23
- def save_details(details: SavedDetails, key: str):
24
- if isinstance(details, PersonalDetails):
25
- type_ = DetailsType.PERSONAL_DETAILS
26
- elif isinstance(details, LocationDetails):
27
- type_ = DetailsType.LOCATION_DETAILS
28
- elif isinstance(details, ContractorDetails):
29
- type_ = DetailsType.CONTRACTOR_DETAILS
30
- else:
31
- raise ValueError("Unexpected type: {}", type(details))
32
- existing_data = (ls.getItem(type_.name) or {})
33
- existing_data[key] = details.to_json()
34
- ls.setItem(type_.name, existing_data, type_.name)
35
-
36
-
37
- def get_details(type_: DetailsType):
38
- return ls.getItem(type_.name) or {}
39
-
 
 
 
 
1
  from streamlit_local_storage import LocalStorage
2
 
3
  from local_storage.entities import SavedDetails, PersonalDetails, LocationDetails, ContractorDetails
4
  from enums import DetailsType
5
 
6
 
7
+ class LocalStorageManager:
8
+ def __init__(self):
9
+ self.ls: LocalStorage = LocalStorage()
10
+
11
+ def get_detail(self, key: str):
12
+ for detail_type in DetailsType.values():
13
+ detail = self.ls.getItem(detail_type.name).get(key)
14
+ if detail:
15
+ if detail_type.value == DetailsType.PERSONAL_DETAILS.value:
16
+ return PersonalDetails(**detail)
17
+ elif detail_type.value == DetailsType.LOCATION_DETAILS.value:
18
+ return LocationDetails(**detail)
19
+ elif detail_type.value == DetailsType.CONTRACTOR_DETAILS.value:
20
+ return ContractorDetails(**detail)
21
+ return None
22
+ return None
23
+
24
+ def save_details(self, details: SavedDetails, key: str):
25
+ if isinstance(details, PersonalDetails):
26
+ type_ = DetailsType.PERSONAL_DETAILS
27
+ elif isinstance(details, LocationDetails):
28
+ type_ = DetailsType.LOCATION_DETAILS
29
+ elif isinstance(details, ContractorDetails):
30
+ type_ = DetailsType.CONTRACTOR_DETAILS
31
+ else:
32
+ raise ValueError("Unexpected type: {}", type(details))
33
+ existing_data = (self.ls.getItem(type_.name) or {})
34
+ existing_data[key] = details.to_json()
35
+ self.ls.setItem(type_.name, existing_data, type_.name)
36
+
37
+ def get_details(self, type_: DetailsType):
38
+ return self.ls.getItem(type_.name) or {}