Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -118,34 +118,41 @@ async def generate_response(message):
|
|
118 |
{"role": "user", "content": f"์ฌ์ฉ์ ์ง๋ฌธ: {user_input}\n\n๊ฒ์ ๊ฒฐ๊ณผ:\n{search_results}"}
|
119 |
]
|
120 |
|
121 |
-
# ์ด์ ๋ํ ํ์คํ ๋ฆฌ ์ถ๊ฐ
|
122 |
-
|
|
|
|
|
|
|
123 |
|
124 |
logging.debug(f'Messages to be sent to the model: {messages}')
|
125 |
|
126 |
loop = asyncio.get_event_loop()
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
|
|
|
|
|
|
|
|
149 |
|
150 |
if __name__ == "__main__":
|
151 |
# Discord ํด๋ผ์ด์ธํธ ์คํ
|
|
|
118 |
{"role": "user", "content": f"์ฌ์ฉ์ ์ง๋ฌธ: {user_input}\n\n๊ฒ์ ๊ฒฐ๊ณผ:\n{search_results}"}
|
119 |
]
|
120 |
|
121 |
+
# ์ด์ ๋ํ ํ์คํ ๋ฆฌ ์ถ๊ฐ (์ต๋ 5๊ฐ๊น์ง๋ง)
|
122 |
+
for i in range(min(len(conversation_history), 10), 0, -2):
|
123 |
+
messages.append(conversation_history[-i])
|
124 |
+
if i > 1:
|
125 |
+
messages.append(conversation_history[-i+1])
|
126 |
|
127 |
logging.debug(f'Messages to be sent to the model: {messages}')
|
128 |
|
129 |
loop = asyncio.get_event_loop()
|
130 |
+
try:
|
131 |
+
response = await loop.run_in_executor(None, lambda: hf_client.chat_completion(
|
132 |
+
messages, max_tokens=1000, stream=True, temperature=0.7, top_p=0.85))
|
133 |
+
|
134 |
+
full_response = []
|
135 |
+
for part in response:
|
136 |
+
logging.debug(f'Part received from stream: {part}')
|
137 |
+
if part.choices and part.choices[0].delta and part.choices[0].delta.content:
|
138 |
+
full_response.append(part.choices[0].delta.content)
|
139 |
+
|
140 |
+
full_response_text = ''.join(full_response)
|
141 |
+
logging.debug(f'Full model response: {full_response_text}')
|
142 |
+
|
143 |
+
# ๋ํ ํ์คํ ๋ฆฌ ์
๋ฐ์ดํธ
|
144 |
+
conversation_history.append({"role": "user", "content": user_input})
|
145 |
+
conversation_history.append({"role": "assistant", "content": full_response_text})
|
146 |
+
|
147 |
+
# ๋ํ ํ์คํ ๋ฆฌ ๊ธธ์ด ์ ํ (์ต๊ทผ 10๊ฐ ๋ฉ์์ง๋ง ์ ์ง)
|
148 |
+
conversation_history = conversation_history[-10:]
|
149 |
+
|
150 |
+
logging.debug(f'Conversation history updated: {conversation_history}')
|
151 |
+
|
152 |
+
return f"{user_mention}, {full_response_text}"
|
153 |
+
except Exception as e:
|
154 |
+
logging.error(f"Error in generate_response: {e}")
|
155 |
+
return f"{user_mention}, ์ฃ์กํฉ๋๋ค. ์๋ต์ ์์ฑํ๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ค์ ์๋ํด ์ฃผ์ธ์."
|
156 |
|
157 |
if __name__ == "__main__":
|
158 |
# Discord ํด๋ผ์ด์ธํธ ์คํ
|