-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
90 lines (77 loc) · 2.68 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
from twilio.rest import Client
import flask
from flask import send_from_directory, request
from openai import OpenAI
from typing import List
import keys
training_data = ""#read(estilo.pdf) + read(whatsapp.pdf)
import requests
import json
def assist_journalist(prompt):
api_url = "https://reverse.mubi.tech/v1/chat/completions"
headers = {
'Content-Type': 'application/json',
'Origin': 'https://gptcall.net/',
'Referer': 'https://gptcall.net/'
}
data = {
'model': keys.ai_model,
'messages': [{'role': "user", 'content': prompt}]
}
response = requests.post(api_url, headers=headers, data=json.dumps(data))
if response.status_code != 200:
print(f"Error sending prompt to GPT: {response.status_code} {response.text}")
return f"Error: {response.text}"
else:
return response.json()["choices"][0]["message"]["content"]
app = flask.Flask(__name__)
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),
'favicon.ico', mimetype='image/favicon.png')
@app.route('/')
@app.route('/home')
def home():
return "Hello World"
clients = {}
ACCOUNT_SID = keys.twilio_sid
AUTH_TOKEN = keys.twilio_token
client = Client(ACCOUNT_SID, AUTH_TOKEN)
def mensaje(number, text):
message = client.messages.create(
from_=keys.twilio_number,
body=text,
to=number
)
print(message.sid)
def mensaje_nuevo(tlf, message, name):
telephone = "whatsapp:+" + tlf
if message == "{clients}":
mensaje(telephone, clients)
if training_data == "":
mensaje(telephone, "Los datos de entrenamiento no están disponibles. Sorry!")
else:
mensaje(telephone, training_data)
else:
send = assist_journalist(keys.prompt + "Tu nombre es " + keys.bot_name + str("El cliente te ha dicho: " + message) + "La persona que te contacta se llama" + name)
mensaje(telephone, send)
return send
@app.route('/', methods=['GET', 'POST'])
def whatsapp():
message = request.form['Body']
name = request.form['ProfileName']
senderId = request.form['From'].split('+')[1]
response = mensaje_nuevo(senderId, message, name)
os.system("cls")
print("###############################")
print()
print(f'Message --> {message}')
print(f'Tlf number --> {senderId}')
print(f'Name --> {name}')
print(f'AI response --> {response}')
print()
print("###############################")
return "lol"
if __name__ == "__main__":
app.run(port=keys.ngrok_port, debug=True)