seawolf2357 commited on
Commit
ba9f987
ยท
verified ยท
1 Parent(s): 43789da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -24
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
- if self.is_processing:
107
- return
 
 
 
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()