Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Commit
โข
8da9618
1
Parent(s):
4d5e738
Update app.py
Browse files
app.py
CHANGED
@@ -48,7 +48,7 @@ class MyClient(discord.Client):
|
|
48 |
return
|
49 |
self.is_processing = True
|
50 |
try:
|
51 |
-
response = await generate_response(message)
|
52 |
await message.channel.send(response)
|
53 |
finally:
|
54 |
self.is_processing = False
|
@@ -58,70 +58,37 @@ class MyClient(discord.Client):
|
|
58 |
isinstance(message.channel, discord.Thread) and message.channel.parent_id == SPECIFIC_CHANNEL_ID
|
59 |
)
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
await message.channel.send(full_response_text)
|
93 |
-
|
94 |
-
logging.debug(f'Full model response sent: {full_response_text}')
|
95 |
-
conversation_history.append({"role": "assistant", "content": full_response_text})
|
96 |
-
|
97 |
-
async def generate_response(message):
|
98 |
-
global conversation_history
|
99 |
-
user_input = message.content
|
100 |
-
user_mention = message.author.mention
|
101 |
-
system_prefix = """
|
102 |
-
๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ์ญ์์ค.
|
103 |
-
"""
|
104 |
-
system_message = f"{user_mention}, DISCORD์์ ์ฌ์ฉ์๋ค์ ์ง๋ฌธ์ ๋ตํ๋ ์ด์์คํดํธ์
๋๋ค."
|
105 |
-
answer = search_in_dataset(user_input, law_dataset)
|
106 |
-
full_response_text = system_prefix + "\n\n" + answer
|
107 |
-
|
108 |
-
# ์๋ต ๋ฉ์์ง๊ฐ ๋น์ด ์๋์ง ํ์ธํ๊ณ ์ฒ๋ฆฌ
|
109 |
-
if full_response_text.strip() == "":
|
110 |
-
full_response_text = "์ฃ์กํฉ๋๋ค, ์ ๋ณด๋ฅผ ์ ๊ณตํ ์ ์์ต๋๋ค."
|
111 |
-
|
112 |
-
max_length = 2000
|
113 |
-
if len(full_response_text) > max_length:
|
114 |
-
# ๋ฉ์์ง๋ฅผ ์ ์ ํ ๊ธธ์ด๋ก ๋๋์ด ์ ์ก
|
115 |
-
for i in range(0, len(full_response_text), max_length):
|
116 |
-
part_response = full_response_text[i:i+max_length]
|
117 |
-
await message.channel.send(part_response)
|
118 |
-
else:
|
119 |
-
# ์ ์ฒด ๋ฉ์์ง๋ฅผ ํ ๋ฒ์ ์ ์ก
|
120 |
-
await message.channel.send(full_response_text)
|
121 |
-
|
122 |
-
logging.debug(f'Full model response sent: {full_response_text}')
|
123 |
-
conversation_history.append({"role": "assistant", "content": full_response_text})
|
124 |
-
|
125 |
|
126 |
if __name__ == "__main__":
|
127 |
discord_client = MyClient(intents=intents)
|
|
|
48 |
return
|
49 |
self.is_processing = True
|
50 |
try:
|
51 |
+
response = await self.generate_response(message)
|
52 |
await message.channel.send(response)
|
53 |
finally:
|
54 |
self.is_processing = False
|
|
|
58 |
isinstance(message.channel, discord.Thread) and message.channel.parent_id == SPECIFIC_CHANNEL_ID
|
59 |
)
|
60 |
|
61 |
+
async def generate_response(self, message):
|
62 |
+
global conversation_history
|
63 |
+
user_input = message.content
|
64 |
+
user_mention = message.author.mention
|
65 |
+
system_message = f"{user_mention}, DISCORD์์ ์ฌ์ฉ์๋ค์ ์ง๋ฌธ์ ๋ตํ๋ ์ด์์คํดํธ์
๋๋ค."
|
66 |
+
answer = self.search_in_dataset(user_input, law_dataset)
|
67 |
+
full_response_text = system_message + "\n\n" + answer
|
68 |
+
|
69 |
+
if not full_response_text.strip():
|
70 |
+
full_response_text = "์ฃ์กํฉ๋๋ค, ์ ๋ณด๋ฅผ ์ ๊ณตํ ์ ์์ต๋๋ค."
|
71 |
+
|
72 |
+
max_length = 2000
|
73 |
+
if len(full_response_text) > max_length:
|
74 |
+
for i in range(0, len(full_response_text), max_length):
|
75 |
+
part_response = full_response_text[i:i+max_length]
|
76 |
+
await message.channel.send(part_response)
|
77 |
+
else:
|
78 |
+
await message.channel.send(full_response_text)
|
79 |
+
|
80 |
+
logging.debug(f'Full model response sent: {full_response_text}')
|
81 |
+
conversation_history.append({"role": "assistant", "content": full_response_text})
|
82 |
+
|
83 |
+
def search_in_dataset(self, query, dataset):
|
84 |
+
# ์ฌ์ฉ์์ ์ฟผ๋ฆฌ์ ๊ด๋ จ๋ ์ฌ๊ฑด๋ช
์ ์ฐพ์ ์ฌ๊ฑด๋ฒํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
85 |
+
response = []
|
86 |
+
for record in dataset['train']:
|
87 |
+
if query in record['์ฌ๊ฑด๋ช
']:
|
88 |
+
detail = f"์ฌ๊ฑด๋ฒํธ: {record['์ฌ๊ฑด๋ฒ๏ฟฝ๏ฟฝ๏ฟฝ']}"
|
89 |
+
response.append(detail)
|
90 |
+
|
91 |
+
return "\n".join(response) if response else "๊ด๋ จ ๋ฒ๋ฅ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
if __name__ == "__main__":
|
94 |
discord_client = MyClient(intents=intents)
|