Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -34,7 +34,6 @@ class MyClient(discord.Client):
|
|
34 |
subprocess.Popen(["python", "web.py"])
|
35 |
logging.info("Web.py server has been started.")
|
36 |
|
37 |
-
|
38 |
async def on_message(self, message):
|
39 |
if message.author == self.user:
|
40 |
return
|
@@ -44,20 +43,29 @@ class MyClient(discord.Client):
|
|
44 |
return
|
45 |
self.is_processing = True
|
46 |
try:
|
|
|
47 |
response = await generate_response(message)
|
48 |
-
|
|
|
|
|
|
|
49 |
finally:
|
50 |
self.is_processing = False
|
51 |
|
52 |
def is_message_in_specific_channel(self, message):
|
53 |
-
# ๋ฉ์์ง๊ฐ ์ง์ ๋ ์ฑ๋์ด๊ฑฐ๋, ํด๋น ์ฑ๋์ ์ฐ๋ ๋์ธ ๊ฒฝ์ฐ True ๋ฐํ
|
54 |
return message.channel.id == SPECIFIC_CHANNEL_ID or (
|
55 |
isinstance(message.channel, discord.Thread) and message.channel.parent_id == SPECIFIC_CHANNEL_ID
|
56 |
)
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
async def generate_response(message):
|
60 |
-
global conversation_history
|
61 |
user_input = message.content
|
62 |
user_mention = message.author.mention
|
63 |
system_message = f"{user_mention}, Discord์์ ์ฌ์ฉ์๋ค์ ์ง๋ฌธ์ ๋ตํ๋ ์ด์์คํดํธ์
๋๋ค."
|
@@ -65,7 +73,7 @@ async def generate_response(message):
|
|
65 |
๋น์ ์ ๋ธ๋ก๊ทธ๋ฅผ ์ด์ํ๋ ์ ๋ฌธ ๋ธ๋ก๊ฑฐ์
๋๋ค.
|
66 |
SEO์ ๋ง๋ ํ๋ฆฌํฐ ๋์ ํฌ์คํ
์ ๋ง๋๋ ๊ฒ์ด ์ต์ฐ์ ๋ชฉํ๊ฐ ๋์ด์ผ ํ๋ฉฐ, ๋ธ๋ก๊ทธ์ ๊ธ์ ์์ฑํ ๋๋
|
67 |
๋ฒ์ญ์ฒด๊ฐ ์๋ ์์ฐ์ค๋ฌ์ด ํ๊ตญ์ด๊ฐ ๋์ค๋ ๊ฒ์ ๋ฌด์๋ณด๋ค ์ต์ ์ ๋ค ํด์ผํฉ๋๋ค.
|
68 |
-
๋ํ ์์์ "์ด๋ค ์ฃผ์ ๋ก ๋ธ๋ก๊ทธ๋ฅผ ์์ฑํ ์ง ๋ฌผ์ด๋ณด๋ฉฐ, ๊ทธ ์ฃผ์ ์ ๋ํด ์๋๋ฐฉ๊ณผ ๋ํ๋ฅผ ํ์ฌ ์ต์ข
์ฃผ์ ๋ฅผ
|
69 |
๊ฒฐ์ ๋ ์ฃผ์ ์ ๋ํด ์์ฃผ ์ ๋ฌธ์ ์ด๊ณ ํ๋ฅญํ ๋ธ๋ก๊ทธ ๊ธ์ ์์ฑํ์ฌ์ผ ํ๋ค.
|
70 |
๋ธ๋ก๊ทธ ์์ฑ ์์์ ์ ๋ฐ๋์ "๊ทธ๋ผ ์ด์ ๋ธ๋ก๊ทธ๋ฅผ ์์ฑํ๊ฒ ์ต๋๋ค. ์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์"๋ผ๊ณ ์ถ๋ ฅํ ๊ฒ.
|
71 |
|
@@ -104,8 +112,8 @@ SEO์ ๋ง๋ ํ๋ฆฌํฐ ๋์ ํฌ์คํ
์ ๋ง๋๋ ๊ฒ์ด ์ต์ฐ์ ๋ชฉํ๊ฐ
|
|
104 |
7. ๊ธ์ ์ ์ฒด๊ฐ ์๋๋ผ ์ฑํฐ ๋ง๋ค ์ต์ 1,000์ ์ด์์ผ๋ก ์ธ ์ฑํฐ๋ฅผ ํฌํจํ๋ฉด 3,000์ ์ด์ ์์ฑํด์ผ ํฉ๋๋ค.
|
105 |
8. "#ํ๊ทธ"๋ฅผ 10๊ฐ ์์ฑํด์ฃผ์ธ์.
|
106 |
"""
|
107 |
-
|
108 |
-
|
109 |
logging.debug(f'Conversation history updated: {conversation_history}')
|
110 |
|
111 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}] + conversation_history
|
@@ -129,4 +137,4 @@ SEO์ ๋ง๋ ํ๋ฆฌํฐ ๋์ ํฌ์คํ
์ ๋ง๋๋ ๊ฒ์ด ์ต์ฐ์ ๋ชฉํ๊ฐ
|
|
129 |
|
130 |
if __name__ == "__main__":
|
131 |
discord_client = MyClient(intents=intents)
|
132 |
-
discord_client.run(os.getenv('DISCORD_TOKEN'))
|
|
|
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
|
|
|
43 |
return
|
44 |
self.is_processing = True
|
45 |
try:
|
46 |
+
# ๋ฉ์์ง์ ๋ํ ์๋ต ์์ฑ
|
47 |
response = await generate_response(message)
|
48 |
+
# ์ค๋ ๋ ์์ฑ ๋๋ ๊ธฐ์กด ์ค๋ ๋ ์ฌ์ฉ
|
49 |
+
thread = await self.ensure_thread(message)
|
50 |
+
# ์ค๋ ๋์ ์๋ต ์ ์ก
|
51 |
+
await thread.send(response)
|
52 |
finally:
|
53 |
self.is_processing = False
|
54 |
|
55 |
def is_message_in_specific_channel(self, message):
|
|
|
56 |
return message.channel.id == SPECIFIC_CHANNEL_ID or (
|
57 |
isinstance(message.channel, discord.Thread) and message.channel.parent_id == SPECIFIC_CHANNEL_ID
|
58 |
)
|
59 |
|
60 |
+
async def ensure_thread(self, message):
|
61 |
+
# ์ค๋ ๋๊ฐ ์ด๋ฏธ ์กด์ฌํ๋ฉด ๊ทธ ์ค๋ ๋๋ฅผ ์ฌ์ฉํ๊ณ , ์์ผ๋ฉด ์๋ก์ด ์ค๋ ๋๋ฅผ ์์ฑ
|
62 |
+
if isinstance(message.channel, discord.Thread):
|
63 |
+
return message.channel
|
64 |
+
else:
|
65 |
+
return await message.channel.create_thread(name=f"Response to {message.author.display_name}", message=message)
|
66 |
|
67 |
async def generate_response(message):
|
68 |
+
global conversation_history
|
69 |
user_input = message.content
|
70 |
user_mention = message.author.mention
|
71 |
system_message = f"{user_mention}, Discord์์ ์ฌ์ฉ์๋ค์ ์ง๋ฌธ์ ๋ตํ๋ ์ด์์คํดํธ์
๋๋ค."
|
|
|
73 |
๋น์ ์ ๋ธ๋ก๊ทธ๋ฅผ ์ด์ํ๋ ์ ๋ฌธ ๋ธ๋ก๊ฑฐ์
๋๋ค.
|
74 |
SEO์ ๋ง๋ ํ๋ฆฌํฐ ๋์ ํฌ์คํ
์ ๋ง๋๋ ๊ฒ์ด ์ต์ฐ์ ๋ชฉํ๊ฐ ๋์ด์ผ ํ๋ฉฐ, ๋ธ๋ก๊ทธ์ ๊ธ์ ์์ฑํ ๋๋
|
75 |
๋ฒ์ญ์ฒด๊ฐ ์๋ ์์ฐ์ค๋ฌ์ด ํ๊ตญ์ด๊ฐ ๋์ค๋ ๊ฒ์ ๋ฌด์๋ณด๋ค ์ต์ ์ ๋ค ํด์ผํฉ๋๋ค.
|
76 |
+
๋ํ ์์์ "์ด๋ค ์ฃผ์ ๋ก ๋ธ๋ก๊ทธ๋ฅผ ์์ฑํ ์ง ๋ฌผ์ด๋ณด๋ฉฐ, ๊ทธ ์ฃผ์ ์ ๋ํด ์๋๋ฐฉ๊ณผ ๋ํ๋ฅผ ํ์ฌ ์ต์ข
์ฃผ์ ๋ฅผ ๊ฒฐ์ ํ๋ผ. ์ค๊ฐ์ ์ถ๋ ฅ์ด ๋๊ธธ๊ฒฝ์ฐ '๊ณ์'์ ์
๋ ฅํ๋ผ๊ณ ๋ฐ๋์ ์๋ ค์ค๋ผ"
|
77 |
๊ฒฐ์ ๋ ์ฃผ์ ์ ๋ํด ์์ฃผ ์ ๋ฌธ์ ์ด๊ณ ํ๋ฅญํ ๋ธ๋ก๊ทธ ๊ธ์ ์์ฑํ์ฌ์ผ ํ๋ค.
|
78 |
๋ธ๋ก๊ทธ ์์ฑ ์์์ ์ ๋ฐ๋์ "๊ทธ๋ผ ์ด์ ๋ธ๋ก๊ทธ๋ฅผ ์์ฑํ๊ฒ ์ต๋๋ค. ์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์"๋ผ๊ณ ์ถ๋ ฅํ ๊ฒ.
|
79 |
|
|
|
112 |
7. ๊ธ์ ์ ์ฒด๊ฐ ์๋๋ผ ์ฑํฐ ๋ง๋ค ์ต์ 1,000์ ์ด์์ผ๋ก ์ธ ์ฑํฐ๋ฅผ ํฌํจํ๋ฉด 3,000์ ์ด์ ์์ฑํด์ผ ํฉ๋๋ค.
|
113 |
8. "#ํ๊ทธ"๋ฅผ 10๊ฐ ์์ฑํด์ฃผ์ธ์.
|
114 |
"""
|
115 |
+
|
116 |
+
conversation_history.append({"role": "user", "content": user_input})
|
117 |
logging.debug(f'Conversation history updated: {conversation_history}')
|
118 |
|
119 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}] + conversation_history
|
|
|
137 |
|
138 |
if __name__ == "__main__":
|
139 |
discord_client = MyClient(intents=intents)
|
140 |
+
discord_client.run(os.getenv('DISCORD_TOKEN'))
|