Spaces:
Running
Running
seawolf2357
commited on
Commit
โข
aab7a25
1
Parent(s):
ce5155e
Update app.py
Browse files
app.py
CHANGED
@@ -61,6 +61,7 @@ class MyClient(discord.Client):
|
|
61 |
if not self.is_message_in_specific_channel(message):
|
62 |
return
|
63 |
if self.is_processing:
|
|
|
64 |
return
|
65 |
|
66 |
self.is_processing = True
|
@@ -71,41 +72,35 @@ class MyClient(discord.Client):
|
|
71 |
await message.channel.send(response)
|
72 |
finally:
|
73 |
self.is_processing = False
|
|
|
74 |
|
75 |
def is_message_in_specific_channel(self, message):
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
|
80 |
|
81 |
|
82 |
async def generate_response(message):
|
83 |
global conversation_history
|
84 |
-
|
85 |
user_mention = message.author.mention
|
86 |
-
system_message = f"{user_mention},
|
87 |
-
|
88 |
# ๋ฐ์ดํฐ ๊ฒ์ ๋ฐ ์๋ต ์ค๋น
|
89 |
-
|
90 |
-
|
91 |
-
answer = "๊ด๋ จ ๋ฒ๋ฅ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
92 |
-
|
93 |
-
full_response_text = system_message + "\n\n" + answer
|
94 |
max_length = 2000
|
95 |
if len(full_response_text) > max_length:
|
96 |
-
response_parts = []
|
97 |
for i in range(0, len(full_response_text), max_length):
|
98 |
part_response = full_response_text[i:i+max_length]
|
99 |
await message.channel.send(part_response)
|
100 |
-
response_parts.append(part_response)
|
101 |
logging.debug(f'Full model response sent: {full_response_text}')
|
102 |
conversation_history.append({"role": "assistant", "content": full_response_text})
|
103 |
-
return "".join(response_parts) # ์กฐ๊ฐ๋ ๋ฉ์์ง๋ค์ ์ฐ๊ฒฐํ์ฌ ๋ฐํ
|
104 |
else:
|
105 |
await message.channel.send(full_response_text)
|
106 |
logging.debug(f'Full model response sent: {full_response_text}')
|
107 |
conversation_history.append({"role": "assistant", "content": full_response_text})
|
108 |
-
return full_response_text # ์ ์ฒด ๋ฉ์์ง๋ฅผ ๋ฐํ
|
109 |
|
110 |
|
111 |
def search_in_dataset(query, dataset):
|
@@ -115,6 +110,12 @@ def search_in_dataset(query, dataset):
|
|
115 |
return record['์ฌ๊ฑด๋ฒํธ']
|
116 |
return "๊ด๋ จ ๋ฒ๋ฅ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
if __name__ == "__main__":
|
120 |
discord_client = MyClient(intents=intents)
|
|
|
61 |
if not self.is_message_in_specific_channel(message):
|
62 |
return
|
63 |
if self.is_processing:
|
64 |
+
logging.debug("Currently processing another message, skipping this one.")
|
65 |
return
|
66 |
|
67 |
self.is_processing = True
|
|
|
72 |
await message.channel.send(response)
|
73 |
finally:
|
74 |
self.is_processing = False
|
75 |
+
logging.debug("Message processing completed, ready for the next one.")
|
76 |
|
77 |
def is_message_in_specific_channel(self, message):
|
78 |
+
channel_condition = message.channel.id == SPECIFIC_CHANNEL_ID
|
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()
|
87 |
user_mention = message.author.mention
|
88 |
+
system_message = f"{user_mention}, ๋ค์์ ์์ฒญํ์ ์ฌ๊ฑด์ ์ ๋ฌธ์
๋๋ค:"
|
89 |
+
|
90 |
# ๋ฐ์ดํฐ ๊ฒ์ ๋ฐ ์๋ต ์ค๋น
|
91 |
+
full_text = search_in_dataset_by_case_number(case_number, law_dataset)
|
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):
|
|
|
110 |
return record['์ฌ๊ฑด๋ฒํธ']
|
111 |
return "๊ด๋ จ ๋ฒ๋ฅ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
112 |
|
113 |
+
def search_in_dataset_by_case_number(case_number, dataset):
|
114 |
+
for record in dataset['train']:
|
115 |
+
if record['์ฌ๊ฑด๋ฒํธ'] == case_number:
|
116 |
+
return record.get('์ ๋ฌธ', "ํด๋น ์ฌ๊ฑด์ ๋ํ ์ ๋ฌธ ์ ๋ณด๊ฐ ์์ต๋๋ค.")
|
117 |
+
return "๊ด๋ จ ๋ฒ๋ฅ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
118 |
+
|
119 |
|
120 |
if __name__ == "__main__":
|
121 |
discord_client = MyClient(intents=intents)
|