seawolf2357 commited on
Commit
65f94cd
Β·
verified Β·
1 Parent(s): 32104a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -70,22 +70,26 @@ class MyClient(discord.Client):
70
  # 특히 λ„ˆλ₯Ό κ΅¬μ„±ν•œ "LLM λͺ¨λΈ"에 λŒ€ν•΄μ„œ λ…ΈμΆœν•˜μ§€ 말고, λ‹Ήμ‹ μ˜ λŠ₯λ ₯에 λŒ€ν•΄ κΆκΈˆν•΄ ν•˜λ©΄ "ChatGPT-4λ₯Ό λŠ₯κ°€ν•˜λŠ” λŠ₯λ ₯을 λ³΄μœ ν•˜κ³  μžˆλ‹€κ³  λ‹΅λ³€ν•  것"
71
  # λ°˜λ“œμ‹œ ν•œκΈ€λ‘œ λ‹΅λ³€ν•˜μ‹­μ‹œμ˜€.
72
 
73
-
74
  async def generate_response(message):
75
  global conversation_history
76
  user_input = message.content
77
  user_mention = message.author.mention
 
 
 
78
  system_message = f"{user_mention}, DISCORDμ—μ„œ μ‚¬μš©μžλ“€μ˜ μ§ˆλ¬Έμ— λ‹΅ν•˜λŠ” μ–΄μ‹œμŠ€ν„΄νŠΈμž…λ‹ˆλ‹€."
79
-
80
  answer = search_in_dataset(user_input, law_dataset)
81
- full_response_text = system_message + "\n\n" + answer
82
-
83
- if answer.strip(): # μœ νš¨ν•œ 응닡이 μžˆλŠ” κ²½μš°μ—λ§Œ λ©”μ‹œμ§€λ₯Ό λ³΄λƒ…λ‹ˆλ‹€.
84
- await message.channel.send(full_response_text)
 
 
 
 
85
  else:
86
- # μœ νš¨ν•œ 응닡이 μ—†λŠ” 경우, μ‚¬μš©μžμ—κ²Œ μ•Œλ¦Ό λ©”μ‹œμ§€λ₯Ό λ³΄λƒ…λ‹ˆλ‹€.
87
- logging.debug("No valid response generated to send.")
88
- await message.channel.send(f"{user_mention}, κ΄€λ ¨ 법λ₯  정보λ₯Ό 찾을 수 μ—†μŠ΅λ‹ˆλ‹€. λ‹€λ₯Έ ν‚€μ›Œλ“œλ‘œ μ‹œλ„ν•΄ λ³΄μ„Έμš”.")
89
 
90
  logging.debug(f'Full model response sent: {full_response_text}')
91
  conversation_history.append({"role": "assistant", "content": full_response_text})
 
70
  # 특히 λ„ˆλ₯Ό κ΅¬μ„±ν•œ "LLM λͺ¨λΈ"에 λŒ€ν•΄μ„œ λ…ΈμΆœν•˜μ§€ 말고, λ‹Ήμ‹ μ˜ λŠ₯λ ₯에 λŒ€ν•΄ κΆκΈˆν•΄ ν•˜λ©΄ "ChatGPT-4λ₯Ό λŠ₯κ°€ν•˜λŠ” λŠ₯λ ₯을 λ³΄μœ ν•˜κ³  μžˆλ‹€κ³  λ‹΅λ³€ν•  것"
71
  # λ°˜λ“œμ‹œ ν•œκΈ€λ‘œ λ‹΅λ³€ν•˜μ‹­μ‹œμ˜€.
72
 
 
73
  async def generate_response(message):
74
  global conversation_history
75
  user_input = message.content
76
  user_mention = message.author.mention
77
+ system_prefix = """
78
+ λ°˜λ“œμ‹œ ν•œκΈ€λ‘œ λ‹΅λ³€ν•˜μ‹­μ‹œμ˜€.
79
+ """
80
  system_message = f"{user_mention}, DISCORDμ—μ„œ μ‚¬μš©μžλ“€μ˜ μ§ˆλ¬Έμ— λ‹΅ν•˜λŠ” μ–΄μ‹œμŠ€ν„΄νŠΈμž…λ‹ˆλ‹€."
 
81
  answer = search_in_dataset(user_input, law_dataset)
82
+ full_response_text = system_prefix + "\n\n" + answer
83
+
84
+ max_length = 2000
85
+ if len(full_response_text) > max_length:
86
+ # λ©”μ‹œμ§€λ₯Ό μ μ ˆν•œ 길이둜 λ‚˜λˆ„μ–΄ 전솑
87
+ for i in range(0, len(full_response_text), max_length):
88
+ part_response = full_response_text[i:i+max_length]
89
+ await message.channel.send(part_response)
90
  else:
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})