seawolf2357 commited on
Commit
4d5e738
ยท
verified ยท
1 Parent(s): fab0678

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -26
app.py CHANGED
@@ -94,32 +94,33 @@ async def generate_response(message):
94
  logging.debug(f'Full model response sent: {full_response_text}')
95
  conversation_history.append({"role": "assistant", "content": full_response_text})
96
 
97
- def search_in_dataset(query, dataset):
98
- response = []
99
- for record in dataset['train']:
100
- # '์‚ฌ๊ฑด๋ช…' ํ•„๋“œ๊ฐ€ None์ด ์•„๋‹ˆ๊ณ , ์ฟผ๋ฆฌ๊ฐ€ '์‚ฌ๊ฑด๋ช…' ํ•„๋“œ ๋‚ด์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ๊ฒฝ์šฐ๋งŒ ์ฒ˜๋ฆฌ
101
- if record['์‚ฌ๊ฑด๋ช…'] and query in record['์‚ฌ๊ฑด๋ช…']:
102
- detail = (
103
- f"ํŒ๋ก€์ •๋ณด์ผ๋ จ๋ฒˆํ˜ธ: {record['ํŒ๋ก€์ •๋ณด์ผ๋ จ๋ฒˆํ˜ธ']}\n"
104
- f"์‚ฌ๊ฑด๋ช…: {record['์‚ฌ๊ฑด๋ช…']}\n"
105
- f"์‚ฌ๊ฑด๋ฒˆํ˜ธ: {record['์‚ฌ๊ฑด๋ฒˆํ˜ธ']}\n"
106
- f"์„ ๊ณ ์ผ์ž: {record['์„ ๊ณ ์ผ์ž']}\n"
107
- f"์„ ๊ณ : {record['์„ ๊ณ ']}\n"
108
- f"๋ฒ•์›๋ช…: {record['๋ฒ•์›๋ช…']}\n"
109
- f"์‚ฌ๊ฑด์ข…๋ฅ˜๋ช…: {record['์‚ฌ๊ฑด์ข…๋ฅ˜๋ช…']}\n"
110
- f"ํŒ๊ฒฐ์œ ํ˜•: {record['ํŒ๊ฒฐ์œ ํ˜•']}\n"
111
- f"ํŒ์‹œ์‚ฌํ•ญ: {record['ํŒ์‹œ์‚ฌํ•ญ']}\n"
112
- f"ํŒ๊ฒฐ์š”์ง€: {record['ํŒ๊ฒฐ์š”์ง€']}\n"
113
- f"์ฐธ์กฐ์กฐ๋ฌธ: {record['์ฐธ์กฐ์กฐ๋ฌธ']}\n"
114
- f"์ฐธ์กฐํŒ๋ก€: {record['์ฐธ์กฐํŒ๋ก€']}\n"
115
- f"์ „๋ฌธ: {record['์ „๋ฌธ']}\n"
116
- )
117
- response.append(detail)
118
- elif not record['์‚ฌ๊ฑด๋ช…']:
119
- # '์‚ฌ๊ฑด๋ช…' ํ•„๋“œ๊ฐ€ None์ธ ๊ฒฝ์šฐ ๋กœ๊น…
120
- logging.debug(f"Skipped a record with None in '์‚ฌ๊ฑด๋ช…': {record}")
121
-
122
- return "\n".join(response) if response else "๊ด€๋ จ ๋ฒ•๋ฅ  ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
 
123
 
124
 
125
  if __name__ == "__main__":
 
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__":