Dooratre commited on
Commit
30cf6f7
·
verified ·
1 Parent(s): ec4ae5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py CHANGED
@@ -22,8 +22,77 @@ def queryar(ar):
22
  return response.json()
23
 
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  conversation_history = []
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  def generate_response(user_input):
28
  bitcoin_price, current_time = get_bitcoin_price()
29
  result = get_div_content(url)
 
22
  return response.json()
23
 
24
 
25
+ import telebot
26
+ import requests
27
+
28
+ with open('cokk.txt', 'r', encoding='utf-8') as file:
29
+ info = file.read()
30
+
31
+
32
+ # Replace 'YOUR_TOKEN' with your actual bot token
33
+ bot = telebot.TeleBot('6990801595:AAE79xNVO1D_0SeWZlzYLE57Suwfp9GyKT8')
34
+
35
+ def get_assistant_response(user_input):
36
+ payload = {
37
+ "mode": "chat",
38
+ "chat_history": conversation_history,
39
+ "data": {
40
+ "query": f"{info}\n \n \n \n CHAT START HERE : \n \n Stuident : {user_input} \n C Learner :",
41
+ "loader": "PDFReader",
42
+ "text": ""
43
+ }
44
+ }
45
+
46
+ response = requests.post(url2, headers=headers, json=payload)
47
+ data = response.json()
48
+
49
+ # Extract the response from the data
50
+ response_text = data["data"]["response"]
51
+
52
+ return response_text
53
+
54
+
55
+
56
+ url2 = "https://api.braininc.net/be/vectordb/indexers/"
57
+ headers = {
58
+ "Authorization": "token 72ec00483379076f580eb8126f29da802a5140c3",
59
+ "Content-Type": "application/json"
60
+ }
61
+
62
  conversation_history = []
63
 
64
+ @bot.message_handler(commands=['start', 'help'])
65
+ def send_welcome(message):
66
+ global conversation_history
67
+ conversation_history=[]
68
+
69
+ bot.reply_to(message, "Hello there")
70
+
71
+ @bot.message_handler(func=lambda message: True)
72
+ def echo_all(message):
73
+ chat_id = message.chat.id
74
+ user_input = message.text
75
+ conversation_history.append({
76
+ "role": "user",
77
+ "content": f"Stuident :{user_input}",
78
+ "additional_kwargs": {}
79
+ })
80
+
81
+ if user_input.lower() == "exit":
82
+ bot.reply_to(message, "Goodbye!")
83
+ return
84
+
85
+ response_text = get_assistant_response(user_input)
86
+ conversation_history.append({
87
+ "role": "assistant",
88
+ "content": f"C Learner :{response_text}",
89
+ "additional_kwargs": {}
90
+ })
91
+ bot.reply_to(message, response_text)
92
+ print(conversation_history)
93
+
94
+ bot.polling()
95
+
96
  def generate_response(user_input):
97
  bitcoin_price, current_time = get_bitcoin_price()
98
  result = get_div_content(url)