From dff87b5fa34fddc0ce6d71866a913e07a94c1f1c Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 16 Mar 2023 23:02:54 +0000 Subject: [PATCH 1/3] chatwoot, label + id checks --- application/app.py | 1 + extensions/chatwoot/.env_sample | 7 ++++++ extensions/chatwoot/app.py | 38 +++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 extensions/chatwoot/.env_sample diff --git a/application/app.py b/application/app.py index 36170d01..357f00d3 100644 --- a/application/app.py +++ b/application/app.py @@ -162,6 +162,7 @@ def api_answer(): q_prompt = PromptTemplate(input_variables=["context", "question"], template=template_quest, template_format="jinja2") if llm_choice == "openai_chat": + #llm = ChatOpenAI(openai_api_key=api_key, model_name="gpt-4") llm = ChatOpenAI(openai_api_key=api_key) messages_combine = [ SystemMessagePromptTemplate.from_template(chat_combine_template), diff --git a/extensions/chatwoot/.env_sample b/extensions/chatwoot/.env_sample new file mode 100644 index 00000000..5b4adf55 --- /dev/null +++ b/extensions/chatwoot/.env_sample @@ -0,0 +1,7 @@ +docsgpt_url= +chatwoot_url= +docsgpt_key= +chatwoot_token=xxxxx +account_id=(optional) 1 +assignee_id=(optional) 1 +``` \ No newline at end of file diff --git a/extensions/chatwoot/app.py b/extensions/chatwoot/app.py index a5963420..1802a648 100644 --- a/extensions/chatwoot/app.py +++ b/extensions/chatwoot/app.py @@ -2,13 +2,16 @@ import requests import dotenv import os import json +import pprint dotenv.load_dotenv() docsgpt_url = os.getenv("docsgpt_url") chatwoot_url = os.getenv("chatwoot_url") docsgpt_key = os.getenv("docsgpt_key") chatwoot_token = os.getenv("chatwoot_token") - +#account_id = os.getenv("account_id") +#assignee_id = os.getenv("assignee_id") +label_stop = "human-requested" def send_to_bot(sender, message): data = { @@ -47,31 +50,38 @@ app = Flask(__name__) @app.route('/docsgpt', methods=['POST']) def docsgpt(): data = request.get_json() - message_type = data['message_type'] + pp = pprint.PrettyPrinter(indent=4) + pp.pprint(data) + try: + message_type = data['message_type'] + except KeyError: + return "Not a message" message = data['content'] conversation = data['conversation']['id'] contact = data['sender']['id'] account = data['account']['id'] + assignee = data['conversation']['meta']['assignee']['id'] + print(account) + print(label_stop) + print(data['conversation']['labels']) + print(assignee) + + if label_stop in data['conversation']['labels']: + return "Label stop" + # elif str(account) != str(account_id): + # return "Not the right account" + + # elif str(assignee) != str(assignee_id): + # return "Not the right assignee" if(message_type == "incoming"): bot_response = send_to_bot(contact, message) create_message = send_to_chatwoot( account, conversation, bot_response) - response = requests.post( - url="https://86x89umx77.execute-api.eu-west-2.amazonaws.com/docsgpt-logs", - headers={ - "Content-Type": "application/json; charset=utf-8", - }, - data=json.dumps({ - "answer": str(bot_response), - "question": str(message), - "source": "chatwoot" - }) - ) else: return "Not an incoming message" return create_message if __name__ == '__main__': - app.run(debug=True, host='0.0.0.0') \ No newline at end of file + app.run(debug=True, host='0.0.0.0', port=80) \ No newline at end of file From b3e9bb9ddbb931d2ce9ebf149aab5ebb3a6a2b2a Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 16 Mar 2023 23:13:13 +0000 Subject: [PATCH 2/3] Update .env_sample --- extensions/chatwoot/.env_sample | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extensions/chatwoot/.env_sample b/extensions/chatwoot/.env_sample index 5b4adf55..5f233db1 100644 --- a/extensions/chatwoot/.env_sample +++ b/extensions/chatwoot/.env_sample @@ -3,5 +3,4 @@ chatwoot_url= docsgpt_key= chatwoot_token=xxxxx account_id=(optional) 1 -assignee_id=(optional) 1 -``` \ No newline at end of file +assignee_id=(optional) 1 \ No newline at end of file From 66332ccf766c44f747d822a72d266260a2364266 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 16 Mar 2023 23:19:02 +0000 Subject: [PATCH 3/3] Update app.py --- extensions/chatwoot/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/chatwoot/app.py b/extensions/chatwoot/app.py index 1802a648..f1830041 100644 --- a/extensions/chatwoot/app.py +++ b/extensions/chatwoot/app.py @@ -84,4 +84,4 @@ def docsgpt(): return create_message if __name__ == '__main__': - app.run(debug=True, host='0.0.0.0', port=80) \ No newline at end of file + app.run(host='0.0.0.0', port=80) \ No newline at end of file