Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,68 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
-
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
with open('info.txt', 'r') as file:
|
8 |
-
info = file.read().replace('\n', '<br>')
|
9 |
-
return render_template('index.html', info=info)
|
10 |
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import telebot
|
2 |
+
import requests
|
3 |
|
4 |
+
with open('cokk.txt', 'r', encoding='utf-8') as file:
|
5 |
+
info = file.read()
|
6 |
|
7 |
+
# Replace 'YOUR_TOKEN' with your actual bot token
|
8 |
+
bot = telebot.TeleBot('6990801595:AAE79xNVO1D_0SeWZlzYLE57Suwfp9GyKT8')
|
|
|
|
|
|
|
9 |
|
10 |
+
def get_assistant_response(user_input):
|
11 |
+
payload = {
|
12 |
+
"mode": "chat",
|
13 |
+
"chat_history": conversation_history,
|
14 |
+
"data": {
|
15 |
+
"query": f"{info}\n \n \n \n CHAT START HERE : \n \n Stuident : {user_input} \n C Learner :",
|
16 |
+
"loader": "PDFReader",
|
17 |
+
"text": ""
|
18 |
+
}
|
19 |
+
}
|
20 |
+
|
21 |
+
response = requests.post(url2, headers=headers, json=payload)
|
22 |
+
data = response.json()
|
23 |
+
|
24 |
+
# Extract the response from the data
|
25 |
+
response_text = data["data"]["response"]
|
26 |
+
|
27 |
+
return response_text
|
28 |
+
|
29 |
+
url2 = "https://api.braininc.net/be/vectordb/indexers/"
|
30 |
+
headers = {
|
31 |
+
"Authorization": "token 72ec00483379076f580eb8126f29da802a5140c3",
|
32 |
+
"Content-Type": "application/json"
|
33 |
+
}
|
34 |
+
|
35 |
+
conversation_history = []
|
36 |
+
|
37 |
+
@bot.message_handler(commands=['start', 'help'])
|
38 |
+
def send_welcome(message):
|
39 |
+
global conversation_history
|
40 |
+
conversation_history=[]
|
41 |
+
|
42 |
+
bot.reply_to(message, "Hello there")
|
43 |
+
|
44 |
+
@bot.message_handler(func=lambda message: True)
|
45 |
+
def echo_all(message):
|
46 |
+
chat_id = message.chat.id
|
47 |
+
user_input = message.text
|
48 |
+
conversation_history.append({
|
49 |
+
"role": "user",
|
50 |
+
"content": f"Stuident :{user_input}",
|
51 |
+
"additional_kwargs": {}
|
52 |
+
})
|
53 |
+
|
54 |
+
if user_input.lower() == "exit":
|
55 |
+
bot.reply_to(message, "Goodbye!")
|
56 |
+
return
|
57 |
+
|
58 |
+
response_text = get_assistant_response(user_input)
|
59 |
+
conversation_history.append({
|
60 |
+
"role": "assistant",
|
61 |
+
"content": f"C Learner :{response_text}",
|
62 |
+
"additional_kwargs": {}
|
63 |
+
})
|
64 |
+
bot.reply_to(message, response_text)
|
65 |
+
print(conversation_history)
|
66 |
+
|
67 |
+
# Specify the host parameter when calling the polling method
|
68 |
+
bot.polling(host="0.0.0.0", port=7860)
|