Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -84,16 +84,32 @@ def query_teapot(prompt, context, user_input):
|
|
84 |
|
85 |
@log_time
|
86 |
def handle_chat(user_input):
|
87 |
-
|
88 |
results = brave_search(user_input)
|
|
|
89 |
|
90 |
documents = [desc.replace('<strong>','').replace('</strong>','') for _, desc, _ in results]
|
91 |
|
92 |
context = "\n".join(documents)
|
93 |
prompt = """You are Teapot, an open-source AI assistant optimized for low-end devices, providing short, accurate responses without hallucinating while excelling at information extraction and text summarization. If a user asks who you are reply "I am Teapot"."""
|
|
|
94 |
response = query_teapot(prompt, context, user_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
st.write("418 I'm a teapot")
|
99 |
|
@@ -118,10 +134,23 @@ async def on_message(message):
|
|
118 |
if message.author == client.user:
|
119 |
return
|
120 |
print(message.content)
|
|
|
|
|
|
|
|
|
121 |
# Respond with "pong" if the message contains "ping"
|
122 |
-
response = handle_chat(message.content)
|
|
|
123 |
print(response)
|
124 |
-
await message.channel.send(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
# Run the bot with your token
|
127 |
|
|
|
84 |
|
85 |
@log_time
|
86 |
def handle_chat(user_input):
|
87 |
+
search_start_time = time.time()
|
88 |
results = brave_search(user_input)
|
89 |
+
search_end_time = time.time()
|
90 |
|
91 |
documents = [desc.replace('<strong>','').replace('</strong>','') for _, desc, _ in results]
|
92 |
|
93 |
context = "\n".join(documents)
|
94 |
prompt = """You are Teapot, an open-source AI assistant optimized for low-end devices, providing short, accurate responses without hallucinating while excelling at information extraction and text summarization. If a user asks who you are reply "I am Teapot"."""
|
95 |
+
generation_start_time = time.time()
|
96 |
response = query_teapot(prompt, context, user_input)
|
97 |
+
generation_end_time = time.time()
|
98 |
+
|
99 |
+
debug_info = f"""
|
100 |
+
Prompt:
|
101 |
+
{prompt}
|
102 |
+
|
103 |
+
Context:
|
104 |
+
{context}
|
105 |
|
106 |
+
Search time: {search_end_time - search_start_time:.2f} seconds
|
107 |
+
Generation time: {generation_end_time - generation_start_time:.2f} seconds
|
108 |
+
Response: {response}
|
109 |
+
"""
|
110 |
+
|
111 |
+
|
112 |
+
return response, debug_info
|
113 |
|
114 |
st.write("418 I'm a teapot")
|
115 |
|
|
|
134 |
if message.author == client.user:
|
135 |
return
|
136 |
print(message.content)
|
137 |
+
|
138 |
+
|
139 |
+
is_debug = "<debug>" in message.content
|
140 |
+
|
141 |
# Respond with "pong" if the message contains "ping"
|
142 |
+
response, debug_info = handle_chat(message.content.replace("<debug>","").replace("</debug>",""))
|
143 |
+
|
144 |
print(response)
|
145 |
+
sent_message = await message.channel.send(response)
|
146 |
+
|
147 |
+
# Create a thread from the sent message
|
148 |
+
if is_debug:
|
149 |
+
thread = await sent_message.create_thread(name="Debug Thread", auto_archive_duration=60)
|
150 |
+
|
151 |
+
# Send a message in the created thread
|
152 |
+
await thread.send(debug_info)
|
153 |
+
|
154 |
|
155 |
# Run the bot with your token
|
156 |
|