Update controller.py
Browse files- controller.py +14 -3
controller.py
CHANGED
|
@@ -31,7 +31,16 @@ def handle_submission(user_message, selected_tools, url_endpoint, document, imag
|
|
| 31 |
log_response("Agent Response\n {}".format(response))
|
| 32 |
|
| 33 |
return response
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
def handle_submission_chat(user_message, response):
|
| 36 |
# os.environ['HUGGINGFACEHUB_API_TOKEN'] = os.environ['HF_token']
|
| 37 |
agent_chat_bot = get_conversation_chain()
|
|
@@ -41,8 +50,10 @@ def handle_submission_chat(user_message, response):
|
|
| 41 |
else:
|
| 42 |
text = agent_chat_bot.predict(input=user_message)
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
def get_conversation_chain( ):
|
|
|
|
| 31 |
log_response("Agent Response\n {}".format(response))
|
| 32 |
|
| 33 |
return response
|
| 34 |
+
|
| 35 |
+
def cut_text_after_keyword(text, keyword):
|
| 36 |
+
index = text.find(keyword)
|
| 37 |
+
if index != -1:
|
| 38 |
+
return text[:index].strip()
|
| 39 |
+
return text
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
def handle_submission_chat(user_message, response):
|
| 45 |
# os.environ['HUGGINGFACEHUB_API_TOKEN'] = os.environ['HF_token']
|
| 46 |
agent_chat_bot = get_conversation_chain()
|
|
|
|
| 50 |
else:
|
| 51 |
text = agent_chat_bot.predict(input=user_message)
|
| 52 |
|
| 53 |
+
result = cut_text_after_keyword(text, "Human:")
|
| 54 |
+
print(result)
|
| 55 |
+
|
| 56 |
+
return result
|
| 57 |
|
| 58 |
|
| 59 |
def get_conversation_chain( ):
|