File size: 1,898 Bytes
526ff33
 
db6e2f8
526ff33
 
db6e2f8
526ff33
 
db6e2f8
526ff33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6a674e3
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
import telebot
import requests

with open('cokk.txt', 'r', encoding='utf-8') as file:
    info = file.read()

# Replace 'YOUR_TOKEN' with your actual bot token
bot = telebot.TeleBot('6990801595:AAE79xNVO1D_0SeWZlzYLE57Suwfp9GyKT8')

def get_assistant_response(user_input):
    payload = {
        "mode": "chat",
        "chat_history": conversation_history,
        "data": {
            "query": f"{info}\n \n \n \n CHAT START HERE : \n \n Stuident : {user_input} \n C Learner :",
            "loader": "PDFReader",
            "text": ""
        }
    }

    response = requests.post(url2, headers=headers, json=payload)
    data = response.json()

    # Extract the response from the data
    response_text = data["data"]["response"]

    return response_text

url2 = "https://api.braininc.net/be/vectordb/indexers/"
headers = {
    "Authorization": "token 72ec00483379076f580eb8126f29da802a5140c3",
    "Content-Type": "application/json"
}

conversation_history = []

@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
    global conversation_history
    conversation_history=[]

    bot.reply_to(message, "Hello there")

@bot.message_handler(func=lambda message: True)
def echo_all(message):
    chat_id = message.chat.id
    user_input = message.text
    conversation_history.append({
        "role": "user",
        "content": f"Stuident :{user_input}",
        "additional_kwargs": {}
    })

    if user_input.lower() == "exit":
        bot.reply_to(message, "Goodbye!")
        return

    response_text = get_assistant_response(user_input)
    conversation_history.append({
        "role": "assistant",
        "content": f"C Learner :{response_text}",
        "additional_kwargs": {}
    })
    bot.reply_to(message, response_text)
    print(conversation_history)

# Specify the host parameter when calling the polling method
bot.polling(dp, skip_updates=True)