Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chatwoot, label + id checks #173

Merged
merged 3 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions application/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions extensions/chatwoot/.env_sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
docsgpt_url=<docsgpt_api_url>
chatwoot_url=<chatwoot_url>
docsgpt_key=<openai_api_key or other llm>
chatwoot_token=xxxxx
account_id=(optional) 1
assignee_id=(optional) 1
```
38 changes: 24 additions & 14 deletions extensions/chatwoot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
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 = {
Expand Down Expand Up @@ -47,31 +50,38 @@ def send_to_chatwoot(account, conversation, message):
@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')
app.run(debug=True, host='0.0.0.0', port=80)
Fixed Show fixed Hide fixed