mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-30 00:53:14 +00:00
Merge branch 'main' of github.com:arc53/DocsGPT into feature/nicks-list1
This commit is contained in:
77
extensions/chatwoot/app.py
Normal file
77
extensions/chatwoot/app.py
Normal file
@@ -0,0 +1,77 @@
|
||||
import requests
|
||||
import dotenv
|
||||
import os
|
||||
import json
|
||||
|
||||
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")
|
||||
|
||||
|
||||
def send_to_bot(sender, message):
|
||||
data = {
|
||||
'sender': sender,
|
||||
'question': message,
|
||||
'api_key': docsgpt_key,
|
||||
'embeddings_key': docsgpt_key,
|
||||
'history': ''
|
||||
}
|
||||
headers = {"Content-Type": "application/json",
|
||||
"Accept": "application/json"}
|
||||
|
||||
r = requests.post(f'{docsgpt_url}/api/answer',
|
||||
json=data, headers=headers)
|
||||
return r.json()['answer']
|
||||
|
||||
|
||||
def send_to_chatwoot(account, conversation, message):
|
||||
data = {
|
||||
'content': message
|
||||
}
|
||||
url = f"{chatwoot_url}/api/v1/accounts/{account}/conversations/{conversation}/messages"
|
||||
headers = {"Content-Type": "application/json",
|
||||
"Accept": "application/json",
|
||||
"api_access_token": f"{chatwoot_token}"}
|
||||
|
||||
r = requests.post(url,
|
||||
json=data, headers=headers)
|
||||
return r.json()
|
||||
|
||||
|
||||
from flask import Flask, request
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route('/docsgpt', methods=['POST'])
|
||||
def docsgpt():
|
||||
data = request.get_json()
|
||||
message_type = data['message_type']
|
||||
message = data['content']
|
||||
conversation = data['conversation']['id']
|
||||
contact = data['sender']['id']
|
||||
account = data['account']['id']
|
||||
|
||||
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')
|
||||
@@ -1,9 +1,18 @@
|
||||
export default function Avatar({
|
||||
avatar,
|
||||
size,
|
||||
className,
|
||||
}: {
|
||||
avatar: string;
|
||||
size?: 'SMALL' | 'MEDIUM' | 'LARGE';
|
||||
className: string;
|
||||
}) {
|
||||
return <div>{avatar}</div>;
|
||||
const styles = {
|
||||
transform: 'scale(-1, 1)',
|
||||
};
|
||||
return (
|
||||
<div style={styles} className={className}>
|
||||
{avatar}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,21 +14,26 @@ const ConversationBubble = forwardRef<
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
className={`flex rounded-3xl ${
|
||||
className={`flex ${
|
||||
type === 'ANSWER'
|
||||
? 'self-start bg-gray-1000'
|
||||
? 'self-start '
|
||||
: type === 'ERROR'
|
||||
? 'self-start bg-red-1000'
|
||||
: 'flex-row-reverse self-end bg-blue-1000 text-white'
|
||||
} py-7 px-5 ${className}`}
|
||||
? 'self-start'
|
||||
: 'flex-row-reverse self-end '
|
||||
} ${className}`}
|
||||
>
|
||||
<Avatar avatar={type === 'QUESTION' ? '👤' : '🦖'}></Avatar>
|
||||
<Avatar
|
||||
className="mt-4 text-2xl"
|
||||
avatar={type === 'QUESTION' ? '🧑💻' : '🦖'}
|
||||
></Avatar>
|
||||
<div
|
||||
className={`${
|
||||
type === 'QUESTION' ? 'mr-5' : 'ml-5'
|
||||
} flex items-center ${
|
||||
type === 'QUESTION'
|
||||
? ' mr-2 ml-10 bg-blue-1000 py-5 px-5 text-white'
|
||||
: ' ml-2 mr-10 bg-gray-1000 py-5 px-5'
|
||||
} flex items-center rounded-3xl ${
|
||||
type === 'ERROR'
|
||||
? 'rounded-lg border border-red-2000 p-2 text-red-3000'
|
||||
? 'rounded-lg border border-red-2000 bg-red-1000 p-2 text-red-3000'
|
||||
: ''
|
||||
}`}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user