Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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๊ฐ ๋ฉ์์ง๋ง ์ ์ง)
|