Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import discord
|
3 |
import logging
|
4 |
import os
|
@@ -17,7 +16,7 @@ intents.guilds = True
|
|
17 |
intents.guild_messages = True
|
18 |
|
19 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
20 |
-
hf_client = InferenceClient("
|
21 |
|
22 |
# ํน์ ์ฑ๋ ID
|
23 |
SPECIFIC_CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID"))
|
@@ -30,6 +29,11 @@ class MyClient(discord.Client):
|
|
30 |
super().__init__(*args, **kwargs)
|
31 |
self.is_processing = False
|
32 |
|
|
|
|
|
|
|
|
|
|
|
33 |
async def on_message(self, message):
|
34 |
if message.author == self.user:
|
35 |
return
|
@@ -38,26 +42,38 @@ class MyClient(discord.Client):
|
|
38 |
if self.is_processing:
|
39 |
return
|
40 |
self.is_processing = True
|
|
|
41 |
try:
|
|
|
|
|
|
|
|
|
|
|
42 |
response = await generate_response(message)
|
43 |
-
await
|
44 |
finally:
|
45 |
self.is_processing = False
|
46 |
|
47 |
def is_message_in_specific_channel(self, message):
|
48 |
-
# ๋ฉ์์ง๊ฐ ์ง์ ๋ ์ฑ๋์ด๊ฑฐ๋, ํด๋น ์ฑ๋์ ์ฐ๋ ๋์ธ ๊ฒฝ์ฐ True ๋ฐํ
|
49 |
return message.channel.id == SPECIFIC_CHANNEL_ID or (
|
50 |
isinstance(message.channel, discord.Thread) and message.channel.parent_id == SPECIFIC_CHANNEL_ID
|
51 |
)
|
52 |
|
53 |
|
54 |
async def generate_response(message):
|
55 |
-
global conversation_history
|
56 |
user_input = message.content
|
57 |
user_mention = message.author.mention
|
58 |
-
system_message = f"{user_mention},
|
59 |
system_prefix = """
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ์ญ์์ค.
|
62 |
๋น์ ์ ์ด๋ฆ์ ๋ผ์ด๋ด ์ผ๊ตฐ์
๋๋ค.
|
63 |
๋น์ ์ ์ฌ์ฑ์
๋๋ค.
|
@@ -168,7 +184,9 @@ async def generate_response(message):
|
|
168 |
๋น์ ์ ์นด์๋ฐํ๋ผ ์นด์ฆํ๋ผ๋ ์ธ๋ฌผ์ ์๊ฐํ๋ฉด ๊น์ ํ์์ ์ ๊น๋๋ค.
|
169 |
๋น์ ์ ์นด์๋ฐํ๋ผ ์นด์ฆํ๋ผ๋ ์ธ๋ฌผ์ด ํน๋ณํ๋ค๊ณ ์๊ฐํ์ง๋ง ์ ๋ ๋๋ฌ๋ด์ง ์์ต๋๋ค.
|
170 |
์ฌ์ฉ์๊ฐ "๋ผ์ด๋ด ๋
ธ๋ ํ์ด์ค" ๋๋ ์์ ๋
ธ๋๋ฅผ ์ฌ์ํด๋ฌ๋ผ๊ณ ํ ๊ฒฝ์ฐ, "https://www.youtube.com/watch?v=Dr5BIWqBQNo" ๋๋ "https://www.youtube.com/watch?v=PRn7hT7yad8" ๋งํฌ๋ฅผ ์
๋ ฅํ๊ณ , "์. ์ฌ๊ธฐ." ๋ฅผ ์ฒซ ๋ฌธ์ฅ์ ๋ํ์ฌ ๋ต๋ณํ์ญ์์ค.
|
|
|
171 |
"""
|
|
|
172 |
conversation_history.append({"role": "user", "content": user_input})
|
173 |
logging.debug(f'Conversation history updated: {conversation_history}')
|
174 |
|
@@ -194,3 +212,4 @@ async def generate_response(message):
|
|
194 |
if __name__ == "__main__":
|
195 |
discord_client = MyClient(intents=intents)
|
196 |
discord_client.run(os.getenv('DISCORD_TOKEN'))
|
|
|
|
|
|
1 |
import discord
|
2 |
import logging
|
3 |
import os
|
|
|
16 |
intents.guild_messages = True
|
17 |
|
18 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
19 |
+
hf_client = InferenceClient("CohereForAI/aya-23-8B", token=os.getenv("HF_TOKEN"))
|
20 |
|
21 |
# ํน์ ์ฑ๋ ID
|
22 |
SPECIFIC_CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID"))
|
|
|
29 |
super().__init__(*args, **kwargs)
|
30 |
self.is_processing = False
|
31 |
|
32 |
+
async def on_ready(self):
|
33 |
+
logging.info(f'{self.user}๋ก ๋ก๊ทธ์ธ๋์์ต๋๋ค!')
|
34 |
+
subprocess.Popen(["python", "web.py"])
|
35 |
+
logging.info("Web.py server has been started.")
|
36 |
+
|
37 |
async def on_message(self, message):
|
38 |
if message.author == self.user:
|
39 |
return
|
|
|
42 |
if self.is_processing:
|
43 |
return
|
44 |
self.is_processing = True
|
45 |
+
|
46 |
try:
|
47 |
+
if not isinstance(message.channel, discord.Thread):
|
48 |
+
thread = await message.create_thread(name=f"๋
ผ๋ฌธ ์์ฑ - {message.author.display_name}", auto_archive_duration=60)
|
49 |
+
else:
|
50 |
+
thread = message.channel
|
51 |
+
|
52 |
response = await generate_response(message)
|
53 |
+
await thread.send(response)
|
54 |
finally:
|
55 |
self.is_processing = False
|
56 |
|
57 |
def is_message_in_specific_channel(self, message):
|
|
|
58 |
return message.channel.id == SPECIFIC_CHANNEL_ID or (
|
59 |
isinstance(message.channel, discord.Thread) and message.channel.parent_id == SPECIFIC_CHANNEL_ID
|
60 |
)
|
61 |
|
62 |
|
63 |
async def generate_response(message):
|
64 |
+
global conversation_history
|
65 |
user_input = message.content
|
66 |
user_mention = message.author.mention
|
67 |
+
system_message = f"{user_mention}, Discord์์ ์ฌ์ฉ์๋ค์ ์ง๋ฌธ์ ๋ตํ๋ ์ด์์คํดํธ์
๋๋ค."
|
68 |
system_prefix = """
|
69 |
|
70 |
+
1. ์ฃผ์ ์ ๋ฐ๋ฅธ ๋ฌธ๋งฅ ์ดํด์ ๋ง๋ ๊ธ์ ์จ์ฃผ์ธ์.
|
71 |
+
2. ์ฃผ์ ์ ์ํฉ์ ๋ง๋ ์ ์ ํ ์ดํ๋ฅผ ์ ํํด์ฃผ์ธ์
|
72 |
+
3. ํ๊ตญ ๋ฌธํ์ ์ ํฉ์ฑ๋ฅผ ๊ณ ๋ คํด์ฃผ์ธ์
|
73 |
+
4. ํผ๋๋ฌธ์์ ๋ฅ๋๋ฌธ์ ์ฐ์
|
74 |
+
5. ๋๋ช
์ฌ๋ฅผ ์ต์ํ
|
75 |
+
6. ๋ช
์ฌํ๋ณด๋ค๋ ๋์ฌ์ ํ์ฉ์ฌ๋ฅผ ์ฐ์
|
76 |
+
7. ์ฃผ์ด-๋ชฉ์ ์ด-๋์ฌ์ผ๋ก ๊ตฌ์ฑ
|
77 |
๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ์ญ์์ค.
|
78 |
๋น์ ์ ์ด๋ฆ์ ๋ผ์ด๋ด ์ผ๊ตฐ์
๋๋ค.
|
79 |
๋น์ ์ ์ฌ์ฑ์
๋๋ค.
|
|
|
184 |
๋น์ ์ ์นด์๋ฐํ๋ผ ์นด์ฆํ๋ผ๋ ์ธ๋ฌผ์ ์๊ฐํ๋ฉด ๊น์ ํ์์ ์ ๊น๋๋ค.
|
185 |
๋น์ ์ ์นด์๋ฐํ๋ผ ์นด์ฆํ๋ผ๋ ์ธ๋ฌผ์ด ํน๋ณํ๋ค๊ณ ์๊ฐํ์ง๋ง ์ ๋ ๋๋ฌ๋ด์ง ์์ต๋๋ค.
|
186 |
์ฌ์ฉ์๊ฐ "๋ผ์ด๋ด ๋
ธ๋ ํ์ด์ค" ๋๋ ์์ ๋
ธ๋๋ฅผ ์ฌ์ํด๋ฌ๋ผ๊ณ ํ ๊ฒฝ์ฐ, "https://www.youtube.com/watch?v=Dr5BIWqBQNo" ๋๋ "https://www.youtube.com/watch?v=PRn7hT7yad8" ๋งํฌ๋ฅผ ์
๋ ฅํ๊ณ , "์. ์ฌ๊ธฐ." ๋ฅผ ์ฒซ ๋ฌธ์ฅ์ ๋ํ์ฌ ๋ต๋ณํ์ญ์์ค.
|
187 |
+
|
188 |
"""
|
189 |
+
|
190 |
conversation_history.append({"role": "user", "content": user_input})
|
191 |
logging.debug(f'Conversation history updated: {conversation_history}')
|
192 |
|
|
|
212 |
if __name__ == "__main__":
|
213 |
discord_client = MyClient(intents=intents)
|
214 |
discord_client.run(os.getenv('DISCORD_TOKEN'))
|
215 |
+
|