Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Commit
โข
aece062
1
Parent(s):
aab7a25
Update app.py
Browse files
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'))
|