seawolf2357 commited on
Commit
43789da
ยท
verified ยท
1 Parent(s): 2b30038

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -153,14 +153,17 @@ async def generate_response(message):
153
  # ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์—์„œ ๋งํฌ ์ถ”์ถœ
154
  links = [item.split('\n')[1].split(': ')[1] for item in search_results.split('\n\n') if item.startswith('Title:')]
155
 
156
- # ๋Œ€ํ™” ํžˆ์Šคํ† ๋ฆฌ์— ์‚ฌ์šฉ์ž ์ž…๋ ฅ ์ถ”๊ฐ€
157
- conversation_history.append({"role": "user", "content": f"์‚ฌ์šฉ์ž ์งˆ๋ฌธ: {user_input}\n\n๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ:\n{search_results}"})
158
-
159
  # API ์š”์ฒญ์„ ์œ„ํ•œ ๋ฉ”์‹œ์ง€ ๊ตฌ์„ฑ
160
  messages = [
161
  {"role": "system", "content": f"{system_prefix} {system_message}"},
 
162
  ]
163
- messages.extend(conversation_history[-10:]) # ์ตœ๊ทผ 10๊ฐœ์˜ ๋ฉ”์‹œ์ง€๋งŒ ํฌํ•จ
 
 
 
 
 
164
 
165
  logging.debug(f'Messages to be sent to the model: {messages}')
166
 
@@ -175,7 +178,8 @@ async def generate_response(message):
175
  if "์ฐธ๊ณ  ๋งํฌ:" not in full_response_text:
176
  full_response_text += "\n\n์ฐธ๊ณ  ๋งํฌ:\n" + "\n".join(links[:3]) # ์ƒ์œ„ 3๊ฐœ ๋งํฌ๋งŒ ํฌํ•จ
177
 
178
- # ๋Œ€ํ™” ํžˆ์Šคํ† ๋ฆฌ์— ์–ด์‹œ์Šคํ„ดํŠธ ์‘๋‹ต ์ถ”๊ฐ€
 
179
  conversation_history.append({"role": "assistant", "content": full_response_text})
180
 
181
  # ๋Œ€ํ™” ํžˆ์Šคํ† ๋ฆฌ ๊ธธ์ด ์ œํ•œ (์ตœ๊ทผ 20๊ฐœ ๋ฉ”์‹œ์ง€๋งŒ ์œ ์ง€)
 
153
  # ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์—์„œ ๋งํฌ ์ถ”์ถœ
154
  links = [item.split('\n')[1].split(': ')[1] for item in search_results.split('\n\n') if item.startswith('Title:')]
155
 
 
 
 
156
  # API ์š”์ฒญ์„ ์œ„ํ•œ ๋ฉ”์‹œ์ง€ ๊ตฌ์„ฑ
157
  messages = [
158
  {"role": "system", "content": f"{system_prefix} {system_message}"},
159
+ {"role": "user", "content": f"์‚ฌ์šฉ์ž ์งˆ๋ฌธ: {user_input}\n\n๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ:\n{search_results}"}
160
  ]
161
+
162
+ # ์ด์ „ ๋Œ€ํ™” ๊ธฐ๋ก ์ถ”๊ฐ€ (์ตœ๋Œ€ 5๊ฐœ์˜ ์ด์ „ ๋Œ€ํ™”๋งŒ ํฌํ•จ)
163
+ for i in range(min(len(conversation_history), 10), 0, -2):
164
+ messages.insert(1, conversation_history[-i])
165
+ if i > 1:
166
+ messages.insert(1, conversation_history[-i+1])
167
 
168
  logging.debug(f'Messages to be sent to the model: {messages}')
169
 
 
178
  if "์ฐธ๊ณ  ๋งํฌ:" not in full_response_text:
179
  full_response_text += "\n\n์ฐธ๊ณ  ๋งํฌ:\n" + "\n".join(links[:3]) # ์ƒ์œ„ 3๊ฐœ ๋งํฌ๋งŒ ํฌํ•จ
180
 
181
+ # ๋Œ€ํ™” ํžˆ์Šคํ† ๋ฆฌ์— ์‚ฌ์šฉ์ž ์ž…๋ ฅ๊ณผ ์–ด์‹œ์Šคํ„ดํŠธ ์‘๋‹ต ์ถ”๊ฐ€
182
+ conversation_history.append({"role": "user", "content": user_input})
183
  conversation_history.append({"role": "assistant", "content": full_response_text})
184
 
185
  # ๋Œ€ํ™” ํžˆ์Šคํ† ๋ฆฌ ๊ธธ์ด ์ œํ•œ (์ตœ๊ทผ 20๊ฐœ ๋ฉ”์‹œ์ง€๋งŒ ์œ ์ง€)