seawolf2357 commited on
Commit
aece062
โ€ข
1 Parent(s): aab7a25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -67,7 +67,7 @@ class MyClient(discord.Client):
67
  self.is_processing = True
68
  try:
69
  response = await generate_response(message)
70
- if response.strip() == "":
71
  response = "์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค, ์ œ๊ณตํ•  ์ˆ˜ ์žˆ๋Š” ์ •๋ณด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."
72
  await message.channel.send(response)
73
  finally:
@@ -79,8 +79,6 @@ class MyClient(discord.Client):
79
  thread_condition = isinstance(message.channel, discord.Thread) and message.channel.parent_id == SPECIFIC_CHANNEL_ID
80
  return channel_condition or thread_condition
81
 
82
-
83
-
84
  async def generate_response(message):
85
  global conversation_history
86
  case_number = message.content.strip()
@@ -92,20 +90,24 @@ async def generate_response(message):
92
  full_response_text = f"{system_message}\n\n{full_text}"
93
  max_length = 2000
94
  if len(full_response_text) > max_length:
 
95
  for i in range(0, len(full_response_text), max_length):
96
  part_response = full_response_text[i:i+max_length]
97
  await message.channel.send(part_response)
 
98
  logging.debug(f'Full model response sent: {full_response_text}')
99
  conversation_history.append({"role": "assistant", "content": full_response_text})
 
100
  else:
101
  await message.channel.send(full_response_text)
102
  logging.debug(f'Full model response sent: {full_response_text}')
103
  conversation_history.append({"role": "assistant", "content": full_response_text})
 
104
 
 
105
 
106
  def search_in_dataset(query, dataset):
107
  for record in dataset['train']:
108
- # '์‚ฌ๊ฑด๋ช…'์ด None์ด ์•„๋‹Œ์ง€ ํ™•์ธํ•˜๊ณ , query๊ฐ€ ํ•ด๋‹น ๊ฐ’์— ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌ
109
  if record['์‚ฌ๊ฑด๋ช…'] and query in record['์‚ฌ๊ฑด๋ช…']:
110
  return record['์‚ฌ๊ฑด๋ฒˆํ˜ธ']
111
  return "๊ด€๋ จ ๋ฒ•๋ฅ  ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
@@ -116,7 +118,6 @@ def search_in_dataset_by_case_number(case_number, dataset):
116
  return record.get('์ „๋ฌธ', "ํ•ด๋‹น ์‚ฌ๊ฑด์— ๋Œ€ํ•œ ์ „๋ฌธ ์ •๋ณด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.")
117
  return "๊ด€๋ จ ๋ฒ•๋ฅ  ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
118
 
119
-
120
  if __name__ == "__main__":
121
  discord_client = MyClient(intents=intents)
122
  discord_client.run(os.getenv('DISCORD_TOKEN'))
 
67
  self.is_processing = True
68
  try:
69
  response = await generate_response(message)
70
+ if response and response.strip() == "":
71
  response = "์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค, ์ œ๊ณตํ•  ์ˆ˜ ์žˆ๋Š” ์ •๋ณด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."
72
  await message.channel.send(response)
73
  finally:
 
79
  thread_condition = isinstance(message.channel, discord.Thread) and message.channel.parent_id == SPECIFIC_CHANNEL_ID
80
  return channel_condition or thread_condition
81
 
 
 
82
  async def generate_response(message):
83
  global conversation_history
84
  case_number = message.content.strip()
 
90
  full_response_text = f"{system_message}\n\n{full_text}"
91
  max_length = 2000
92
  if len(full_response_text) > max_length:
93
+ response_parts = []
94
  for i in range(0, len(full_response_text), max_length):
95
  part_response = full_response_text[i:i+max_length]
96
  await message.channel.send(part_response)
97
+ response_parts.append(part_response)
98
  logging.debug(f'Full model response sent: {full_response_text}')
99
  conversation_history.append({"role": "assistant", "content": full_response_text})
100
+ return "".join(response_parts) # ์กฐ๊ฐ๋‚œ ๋ฉ”์‹œ์ง€๋“ค์„ ์—ฐ๊ฒฐํ•˜์—ฌ ๋ฐ˜ํ™˜
101
  else:
102
  await message.channel.send(full_response_text)
103
  logging.debug(f'Full model response sent: {full_response_text}')
104
  conversation_history.append({"role": "assistant", "content": full_response_text})
105
+ return full_response_text # ์ „์ฒด ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ˜ํ™˜
106
 
107
+ return "" # ๋ฐ˜ํ™˜ ๊ฐ’์ด ์—†์„ ๊ฒฝ์šฐ ๋นˆ ๋ฌธ์ž์—ด ๋ฐ˜ํ™˜
108
 
109
  def search_in_dataset(query, dataset):
110
  for record in dataset['train']:
 
111
  if record['์‚ฌ๊ฑด๋ช…'] and query in record['์‚ฌ๊ฑด๋ช…']:
112
  return record['์‚ฌ๊ฑด๋ฒˆํ˜ธ']
113
  return "๊ด€๋ จ ๋ฒ•๋ฅ  ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
 
118
  return record.get('์ „๋ฌธ', "ํ•ด๋‹น ์‚ฌ๊ฑด์— ๋Œ€ํ•œ ์ „๋ฌธ ์ •๋ณด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.")
119
  return "๊ด€๋ จ ๋ฒ•๋ฅ  ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
120
 
 
121
  if __name__ == "__main__":
122
  discord_client = MyClient(intents=intents)
123
  discord_client.run(os.getenv('DISCORD_TOKEN'))