Spaces:
Build error
Build error
niro commited on
Commit ·
4d6aabb
1
Parent(s): 972a9f4
clean up
Browse files- chatbot_csv.py +16 -2
chatbot_csv.py
CHANGED
|
@@ -82,9 +82,23 @@ def main():
|
|
| 82 |
if is_ready:
|
| 83 |
history.append("user", user_input)
|
| 84 |
output = st.session_state["chatbot"].conversational_chat(user_input)
|
| 85 |
-
|
| 86 |
# history.append("assistant", output)
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
history.generate_messages(response_container)
|
| 90 |
|
|
|
|
| 82 |
if is_ready:
|
| 83 |
history.append("user", user_input)
|
| 84 |
output = st.session_state["chatbot"].conversational_chat(user_input)
|
| 85 |
+
|
| 86 |
# history.append("assistant", output)
|
| 87 |
+
old_stdout = sys.stdout
|
| 88 |
+
sys.stdout = captured_output = StringIO()
|
| 89 |
+
agent_answer = agent.run(user_input)
|
| 90 |
+
sys.stdout = old_stdout
|
| 91 |
+
thoughts = captured_output.getvalue()
|
| 92 |
+
|
| 93 |
+
cleaned_thoughts = re.sub(r'\x1b\[[0-9;]*[a-zA-Z]', '', thoughts)
|
| 94 |
+
cleaned_thoughts = re.sub(r'\[1m>', '', cleaned_thoughts)
|
| 95 |
+
|
| 96 |
+
resp = cleaned_thoughts.split('Thought:')[-1].split('Final Answer')
|
| 97 |
+
thought = resp[0]
|
| 98 |
+
final_answer = resp[1].split('\n')[0].split(': ')[-1]
|
| 99 |
+
agent_answer_clean = '\n'.join([thought, final_answer])
|
| 100 |
+
full_answer = '\n'.join([output, agent_answer_clean])
|
| 101 |
+
history.append("assistant", full_answer)
|
| 102 |
|
| 103 |
history.generate_messages(response_container)
|
| 104 |
|