Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -103,8 +103,11 @@ class MyClient(commands.Bot):
|
|
| 103 |
return
|
| 104 |
if not self.is_message_in_specific_channel(message):
|
| 105 |
return
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
self.is_processing = True
|
| 110 |
try:
|
|
@@ -125,15 +128,9 @@ class MyClient(commands.Bot):
|
|
| 125 |
await channel.send(part)
|
| 126 |
|
| 127 |
async def generate_response(message):
|
| 128 |
-
global conversation_histories
|
| 129 |
user_input = message.content
|
| 130 |
user_mention = message.author.mention
|
| 131 |
|
| 132 |
-
if message.author.id not in conversation_histories:
|
| 133 |
-
conversation_histories[message.author.id] = []
|
| 134 |
-
|
| 135 |
-
conversation_history = conversation_histories[message.author.id]
|
| 136 |
-
|
| 137 |
system_message = f"{user_mention}, DISCORD์์ ์ฌ์ฉ์๋ค์ ์ง๋ฌธ์ ๋ตํ๋ ์ด์์คํดํธ์
๋๋ค."
|
| 138 |
system_prefix = """
|
| 139 |
๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ์ญ์์ค. ์ถ๋ ฅ์ markdown ํ์์ผ๋ก ์ถ๋ ฅํ๋ผ.
|
|
@@ -159,12 +156,6 @@ async def generate_response(message):
|
|
| 159 |
{"role": "user", "content": f"์ฌ์ฉ์ ์ง๋ฌธ: {user_input}\n\n๊ฒ์ ๊ฒฐ๊ณผ:\n{search_results}"}
|
| 160 |
]
|
| 161 |
|
| 162 |
-
# ์ด์ ๋ํ ๊ธฐ๋ก ์ถ๊ฐ (์ต๋ 5๊ฐ์ ์ด์ ๋ํ๋ง ํฌํจ)
|
| 163 |
-
for i in range(min(len(conversation_history), 10), 0, -2):
|
| 164 |
-
messages.insert(1, conversation_history[-i])
|
| 165 |
-
if i > 1:
|
| 166 |
-
messages.insert(1, conversation_history[-i+1])
|
| 167 |
-
|
| 168 |
logging.debug(f'Messages to be sent to the model: {messages}')
|
| 169 |
|
| 170 |
try:
|
|
@@ -178,20 +169,11 @@ async def generate_response(message):
|
|
| 178 |
if "์ฐธ๊ณ ๋งํฌ:" not in full_response_text:
|
| 179 |
full_response_text += "\n\n์ฐธ๊ณ ๋งํฌ:\n" + "\n".join(links[:3]) # ์์ 3๊ฐ ๋งํฌ๋ง ํฌํจ
|
| 180 |
|
| 181 |
-
# ๋ํ ํ์คํ ๋ฆฌ์ ์ฌ์ฉ์ ์
๋ ฅ๊ณผ ์ด์์คํดํธ ์๋ต ์ถ๊ฐ
|
| 182 |
-
conversation_history.append({"role": "user", "content": user_input})
|
| 183 |
-
conversation_history.append({"role": "assistant", "content": full_response_text})
|
| 184 |
-
|
| 185 |
-
# ๋ํ ํ์คํ ๋ฆฌ ๊ธธ์ด ์ ํ (์ต๊ทผ 20๊ฐ ๋ฉ์์ง๋ง ์ ์ง)
|
| 186 |
-
conversation_histories[message.author.id] = conversation_history[-20:]
|
| 187 |
-
|
| 188 |
-
logging.debug(f'Conversation history updated: {conversation_histories[message.author.id]}')
|
| 189 |
-
|
| 190 |
return f"{user_mention}, {full_response_text}"
|
| 191 |
except Exception as e:
|
| 192 |
logging.error(f"Error in generate_response: {e}")
|
| 193 |
return f"{user_mention}, ์ฃ์กํฉ๋๋ค. ์๋ต์ ์์ฑํ๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ค์ ์๋ํด ์ฃผ์ธ์."
|
| 194 |
-
|
| 195 |
if __name__ == "__main__":
|
| 196 |
# Discord ํด๋ผ์ด์ธํธ ์คํ
|
| 197 |
bot = MyClient()
|
|
|
|
| 103 |
return
|
| 104 |
if not self.is_message_in_specific_channel(message):
|
| 105 |
return
|
| 106 |
+
|
| 107 |
+
response = await generate_response(message)
|
| 108 |
+
await self.send_long_message(message.channel, response)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
|
| 112 |
self.is_processing = True
|
| 113 |
try:
|
|
|
|
| 128 |
await channel.send(part)
|
| 129 |
|
| 130 |
async def generate_response(message):
|
|
|
|
| 131 |
user_input = message.content
|
| 132 |
user_mention = message.author.mention
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
system_message = f"{user_mention}, DISCORD์์ ์ฌ์ฉ์๋ค์ ์ง๋ฌธ์ ๋ตํ๋ ์ด์์คํดํธ์
๋๋ค."
|
| 135 |
system_prefix = """
|
| 136 |
๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ์ญ์์ค. ์ถ๋ ฅ์ markdown ํ์์ผ๋ก ์ถ๋ ฅํ๋ผ.
|
|
|
|
| 156 |
{"role": "user", "content": f"์ฌ์ฉ์ ์ง๋ฌธ: {user_input}\n\n๊ฒ์ ๊ฒฐ๊ณผ:\n{search_results}"}
|
| 157 |
]
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
logging.debug(f'Messages to be sent to the model: {messages}')
|
| 160 |
|
| 161 |
try:
|
|
|
|
| 169 |
if "์ฐธ๊ณ ๋งํฌ:" not in full_response_text:
|
| 170 |
full_response_text += "\n\n์ฐธ๊ณ ๋งํฌ:\n" + "\n".join(links[:3]) # ์์ 3๊ฐ ๋งํฌ๋ง ํฌํจ
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
return f"{user_mention}, {full_response_text}"
|
| 173 |
except Exception as e:
|
| 174 |
logging.error(f"Error in generate_response: {e}")
|
| 175 |
return f"{user_mention}, ์ฃ์กํฉ๋๋ค. ์๋ต์ ์์ฑํ๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ค์ ์๋ํด ์ฃผ์ธ์."
|
| 176 |
+
|
| 177 |
if __name__ == "__main__":
|
| 178 |
# Discord ํด๋ผ์ด์ธํธ ์คํ
|
| 179 |
bot = MyClient()
|