Spaces:
Sleeping
Sleeping
ivnban27-ctl
commited on
Commit
·
be43fc0
1
Parent(s):
eda0ce6
fixed bug on changin source in comparisor
Browse files- models/custom_parsers.py +1 -0
- pages/comparisor.py +23 -14
models/custom_parsers.py
CHANGED
@@ -11,6 +11,7 @@ class CustomStringOutputParser(BaseOutputParser[List[str]]):
|
|
11 |
def parse(self, text: str) -> str:
|
12 |
"""Parse the output of an LLM call."""
|
13 |
text = text.split("texter:")[0]
|
|
|
14 |
text = text.rstrip("\n")
|
15 |
text = text.strip()
|
16 |
return text
|
|
|
11 |
def parse(self, text: str) -> str:
|
12 |
"""Parse the output of an LLM call."""
|
13 |
text = text.split("texter:")[0]
|
14 |
+
text = text.split("helper")[0]
|
15 |
text = text.rstrip("\n")
|
16 |
text = text.strip()
|
17 |
return text
|
pages/comparisor.py
CHANGED
@@ -13,17 +13,24 @@ from app_config import ISSUES, SOURCES, source2label
|
|
13 |
|
14 |
logger = get_logger(__name__)
|
15 |
openai_api_key = os.environ['OPENAI_API_KEY']
|
16 |
-
|
17 |
-
|
18 |
-
'
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
st.session_state["db_client"] = get_db_client()
|
23 |
if 'previous_sourceA' not in st.session_state:
|
24 |
st.session_state['previous_sourceA'] = SOURCES[0]
|
25 |
if 'previous_sourceB' not in st.session_state:
|
26 |
st.session_state['previous_sourceB'] = SOURCES[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
if 'counselor_name' not in st.session_state:
|
28 |
st.session_state["counselor_name"] = get_random_name()
|
29 |
if 'texter_name' not in st.session_state:
|
@@ -91,7 +98,7 @@ def regenerateBoth():
|
|
91 |
st.session_state['commonMemory'].buffer_as_str, prompt, responseA, responseB)
|
92 |
|
93 |
def bothGood():
|
94 |
-
if
|
95 |
pass
|
96 |
else:
|
97 |
i = random.choice([memoryA, memoryB])
|
@@ -137,18 +144,19 @@ with st.sidebar:
|
|
137 |
# regenB = sbcol2.button("Regenerate B", on_click=regenerateB)
|
138 |
clear = st.button("Clear History", on_click=clear_memory, kwargs={"memories":memories, "username":username, "language":language})
|
139 |
|
140 |
-
memories = {
|
141 |
-
'memoryA': {"issue": issue, "source": sourceA},
|
142 |
-
'memoryB': {"issue": issue, "source": sourceB},
|
143 |
-
'commonMemory': {"issue": issue, "source": SOURCES[0]}
|
144 |
-
}
|
145 |
changed_source = any([
|
146 |
st.session_state['previous_sourceA'] != sourceA,
|
147 |
-
st.session_state['previous_sourceB'] != sourceB
|
|
|
148 |
])
|
149 |
if changed_source:
|
|
|
150 |
st.session_state["counselor_name"] = get_random_name()
|
151 |
st.session_state["texter_name"] = get_random_name()
|
|
|
|
|
|
|
|
|
152 |
create_memory_add_initial_message(memories,
|
153 |
issue,
|
154 |
language,
|
@@ -185,6 +193,7 @@ def disable_chat():
|
|
185 |
return True
|
186 |
|
187 |
if prompt := st.chat_input(disabled=disable_chat()):
|
|
|
188 |
if 'convo_id' not in st.session_state:
|
189 |
push_convo2db(memories, username, language)
|
190 |
|
|
|
13 |
|
14 |
logger = get_logger(__name__)
|
15 |
openai_api_key = os.environ['OPENAI_API_KEY']
|
16 |
+
|
17 |
+
if "sent_messages" not in st.session_state:
|
18 |
+
st.session_state['sent_messages'] = 0
|
19 |
+
logger.info(f'sent messages {st.session_state["sent_messages"]}')
|
20 |
+
if "issue" not in st.session_state:
|
21 |
+
st.session_state['issue'] = ISSUES[0]
|
|
|
22 |
if 'previous_sourceA' not in st.session_state:
|
23 |
st.session_state['previous_sourceA'] = SOURCES[0]
|
24 |
if 'previous_sourceB' not in st.session_state:
|
25 |
st.session_state['previous_sourceB'] = SOURCES[0]
|
26 |
+
|
27 |
+
memories = {
|
28 |
+
'memoryA': {"issue": st.session_state['issue'], "source": st.session_state['previous_sourceA']},
|
29 |
+
'memoryB': {"issue": st.session_state['issue'], "source": st.session_state['previous_sourceB']},
|
30 |
+
'commonMemory': {"issue": st.session_state['issue'], "source": SOURCES[0]}
|
31 |
+
}
|
32 |
+
if 'db_client' not in st.session_state:
|
33 |
+
st.session_state["db_client"] = get_db_client()
|
34 |
if 'counselor_name' not in st.session_state:
|
35 |
st.session_state["counselor_name"] = get_random_name()
|
36 |
if 'texter_name' not in st.session_state:
|
|
|
98 |
st.session_state['commonMemory'].buffer_as_str, prompt, responseA, responseB)
|
99 |
|
100 |
def bothGood():
|
101 |
+
if st.session_state['sent_messages'] == 0:
|
102 |
pass
|
103 |
else:
|
104 |
i = random.choice([memoryA, memoryB])
|
|
|
144 |
# regenB = sbcol2.button("Regenerate B", on_click=regenerateB)
|
145 |
clear = st.button("Clear History", on_click=clear_memory, kwargs={"memories":memories, "username":username, "language":language})
|
146 |
|
|
|
|
|
|
|
|
|
|
|
147 |
changed_source = any([
|
148 |
st.session_state['previous_sourceA'] != sourceA,
|
149 |
+
st.session_state['previous_sourceB'] != sourceB,
|
150 |
+
st.session_state['issue'] != issue
|
151 |
])
|
152 |
if changed_source:
|
153 |
+
print("changed something")
|
154 |
st.session_state["counselor_name"] = get_random_name()
|
155 |
st.session_state["texter_name"] = get_random_name()
|
156 |
+
st.session_state['previous_sourceA'] = sourceA
|
157 |
+
st.session_state['previous_sourceB'] = sourceB
|
158 |
+
st.session_state['issue'] = issue
|
159 |
+
st.session_state['sent_messages'] = 0
|
160 |
create_memory_add_initial_message(memories,
|
161 |
issue,
|
162 |
language,
|
|
|
193 |
return True
|
194 |
|
195 |
if prompt := st.chat_input(disabled=disable_chat()):
|
196 |
+
st.session_state['sent_messages'] += 1
|
197 |
if 'convo_id' not in st.session_state:
|
198 |
push_convo2db(memories, username, language)
|
199 |
|