zakerytclarke commited on
Commit
470c35a
·
verified ·
1 Parent(s): beef5d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -120
app.py CHANGED
@@ -1,121 +1,3 @@
1
- # import streamlit as st
2
- # import hashlib
3
- # import os
4
- # import aiohttp
5
- # import asyncio
6
- # import time
7
- # from langsmith import traceable
8
- # import random
9
- # import discord
10
- # from transformers import pipeline
11
- # from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
12
- # import numpy as np
13
- # from sklearn.metrics.pairwise import cosine_similarity
14
- # from pydantic import BaseModel
15
- # from typing import List, Optional
16
- # from tqdm import tqdm
17
- # import re
18
- # import os
19
- # from teapotai import TeapotAI, TeapotAISettings
20
- # import pandas as pd
21
-
22
-
23
- # st.set_page_config(page_title="TeapotAI Discord Bot", page_icon=":robot_face:", layout="wide")
24
-
25
-
26
-
27
- # wiki_data = pd.read_csv("https://docs.google.com/spreadsheets/d/1NNbdQWIfVHq09lMhVSN36_SkGu6XgmKTXgBWPyQcBpk/export?format=csv")
28
- # documents = wiki_data['content'].str.split('\n\n').explode().reset_index(drop=True)
29
- # documents
30
-
31
- # # Intialize Teapot with documents
32
- # teapot_ai = TeapotAI(documents=documents.to_list(), settings=TeapotAISettings(rag_num_results=7))
33
-
34
- # # I apologize, but I'm not qualified to provide personalized advice or recommendations.
35
- # # Latent caching is a feature of the training process that saves intermediate data and can be used to speed up the training.
36
- # # Yes
37
- # # I'm sorry, but I don't have information on the optimizers.
38
- # # 2
39
- # # The Concepts tab is made up of the following elements: For expert users: Embedding Training To get a general overview of the UI, please read the Quick Start Guide first.
40
-
41
-
42
- # def log_time(func):
43
- # async def wrapper(*args, **kwargs):
44
- # start_time = time.time()
45
- # result = await func(*args, **kwargs) # Make it awaitable
46
- # end_time = time.time()
47
- # print(f"{func.__name__} executed in {end_time - start_time:.4f} seconds")
48
- # return result
49
- # return wrapper
50
-
51
-
52
- # # @traceable
53
- # @log_time
54
- # async def handle_chat(user_input):
55
- # def run_sync_query():
56
- # return teapot_ai.query(user_input)
57
-
58
- # output_text = await asyncio.to_thread(run_sync_query)
59
-
60
- # return output_text
61
-
62
-
63
- # st.write("418 I'm a teapot")
64
-
65
- # DISCORD_TOKEN = os.environ.get("discord_key")
66
-
67
- # # Create an instance of Intents and enable the required ones
68
- # intents = discord.Intents.default() # Default intents enable basic functionality
69
- # intents.messages = True # Enable message-related events
70
-
71
- # # Create an instance of a client with the intents
72
- # client = discord.Client(intents=intents)
73
-
74
- # # Event when the bot has connected to the server
75
- # @client.event
76
- # async def on_ready():
77
- # print(f'Logged in as {client.user}')
78
-
79
- # # Event when a message is received
80
- # @client.event
81
- # async def on_message(message):
82
- # # Check if the message is from the bot itself to prevent a loop
83
- # if message.author == client.user:
84
- # return
85
-
86
- # # Exit the function if the bot is not mentioned
87
- # if f'<@{client.user.id}>' not in message.content:
88
- # return
89
-
90
- # print(message.content)
91
-
92
- # is_debug = "debug:" in message.content or "Debug:" in message.content
93
- # async with message.channel.typing():
94
- # cleaned_message=message.content.replace("debug:", "").replace("Debug:","").replace(f'<@{client.user.id}>',"")
95
- # response = await handle_chat(cleaned_message)
96
- # print(response)
97
- # sent_message = await message.reply(response)
98
-
99
- # # Create a thread from the sent message
100
- # if is_debug:
101
- # thread = await sent_message.create_thread(name=f"""Debug Thread: '{cleaned_message[:80]}'""", auto_archive_duration=60)
102
-
103
- # # Send a message in the created thread
104
- # await thread.send(debug_info)
105
-
106
-
107
- # @st.cache_resource
108
- # def initialize():
109
- # st.session_state["initialized"] = True
110
- # client.run(DISCORD_TOKEN)
111
-
112
- # return
113
-
114
- # initialize()
115
-
116
-
117
-
118
-
119
  import streamlit as st
120
  import os
121
  import aiohttp
@@ -144,7 +26,8 @@ client = discord.Client(intents=intents)
144
  async def handle_teapot_inference(server_name, user_input):
145
  teapot_instance = CONFIG.get(server_name, CONFIG["Teapot AI"])
146
  print(f"Using Teapot instance for server: {server_name}")
147
- response = await teapot_instance.query(user_input)
 
148
  return response
149
 
150
 
@@ -162,7 +45,7 @@ async def on_message(message):
162
  return
163
 
164
  server_name = message.guild.name if message.guild else "Teapot AI"
165
- server_name ="OneTrainer"
166
  async with message.channel.typing():
167
  cleaned_message = message.content.replace(f'<@{client.user.id}>', "").strip()
168
  response = await handle_teapot_inference(server_name, cleaned_message)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import os
3
  import aiohttp
 
26
  async def handle_teapot_inference(server_name, user_input):
27
  teapot_instance = CONFIG.get(server_name, CONFIG["Teapot AI"])
28
  print(f"Using Teapot instance for server: {server_name}")
29
+ # Running query in a separate thread to avoid blocking the event loop
30
+ response = await asyncio.to_thread(teapot_instance.query, user_input)
31
  return response
32
 
33
 
 
45
  return
46
 
47
  server_name = message.guild.name if message.guild else "Teapot AI"
48
+ server_name = "OneTrainer" # This seems to be hardcoded, but you can change it based on your logic
49
  async with message.channel.typing():
50
  cleaned_message = message.content.replace(f'<@{client.user.id}>', "").strip()
51
  response = await handle_teapot_inference(server_name, cleaned_message)