Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -240,88 +240,88 @@ def get_model_response(messages):
|
|
240 |
return response.choices[0].message["content"]
|
241 |
|
242 |
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
#
|
248 |
-
|
249 |
-
|
250 |
-
#
|
251 |
-
|
252 |
-
|
253 |
-
#
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
#
|
258 |
-
|
259 |
-
|
260 |
-
#
|
261 |
-
|
262 |
-
|
263 |
-
#
|
264 |
-
|
265 |
-
#
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
#
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
#
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
def agent_respond(message, chat_history):
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
|
326 |
|
327 |
import os
|
|
|
240 |
return response.choices[0].message["content"]
|
241 |
|
242 |
|
243 |
+
تابع اصلی برای مدیریت مکالمه
|
244 |
+
def agent_respond(message):
|
245 |
+
global job_description, job_description_confirmed
|
246 |
+
|
247 |
+
# بهروزرسانی حافظه با پیام کاربر
|
248 |
+
memory.chat_memory.add_user_message(message)
|
249 |
+
|
250 |
+
# آمادهسازی پیامها برای LLM
|
251 |
+
messages = memory.chat_memory.messages.copy()
|
252 |
+
|
253 |
+
# اضافه کردن Prompt به عنوان پیام سیستم
|
254 |
+
system_prompt = prompt.format(chat_history=get_chat_history_string(memory.chat_memory))
|
255 |
+
messages.insert(0, SystemMessage(content=system_prompt))
|
256 |
+
|
257 |
+
# تولید پاسخ دستیار
|
258 |
+
response = llm(messages=messages)
|
259 |
+
|
260 |
+
# افزودن پاسخ دستیار به حافظه
|
261 |
+
memory.chat_memory.add_ai_message(response.content)
|
262 |
+
|
263 |
+
# بررسی اینکه آیا باید متن شغلی تولید شود
|
264 |
+
if not job_description_confirmed and "متن شغلی" in response.content.lower():
|
265 |
+
# تولید متن شغلی بر اساس مکالمه
|
266 |
+
jd_prompt = f"""
|
267 |
+
بر اساس مکالمه تا کنون، یک متن شغلی دقیق و حرفهای برای موقعیت مورد نظر بنویسید. وظایف، مسئولیتها، مهارتها و هر جزئیات مرتبط دیگری که کارفرما ارائه داده است را شامل کنید.
|
268 |
+
مکالمه:
|
269 |
+
{get_chat_history_string(memory.chat_memory)}
|
270 |
+
"""
|
271 |
+
|
272 |
+
# اضافه کردن Prompt به عنوان پیام سیستم
|
273 |
+
jd_messages = [
|
274 |
+
SystemMessage(content=jd_prompt)
|
275 |
+
]
|
276 |
+
|
277 |
+
jd_response = llm(messages=jd_messages)
|
278 |
+
job_description = jd_response.content
|
279 |
+
|
280 |
+
# ارائه متن شغلی به کارفرما
|
281 |
+
confirmation_message = f"متن شغلی پیشنهادی به شرح زیر است:\n\n{job_description}\n\nلطفاً آن را بررسی کرده و بگویید آیا نیاز به تغییر دارد."
|
282 |
+
memory.chat_memory.add_ai_message(confirmation_message)
|
283 |
+
return confirmation_message
|
284 |
+
|
285 |
+
# بررسی بازخورد کارفرما درباره متن شغلی
|
286 |
+
if job_description and not job_description_confirmed:
|
287 |
+
if any(word in message.lower() for word in ["تغییر", "ویرایش", "بهروزرسانی", "اصلاح"]):
|
288 |
+
# بهروزرسانی متن شغلی بر اساس بازخورد کارفرما
|
289 |
+
update_prompt = f"""
|
290 |
+
کارفرما بازخورد زیر را درباره متن شغلی ارائه داده است:
|
291 |
+
"{message}"
|
292 |
+
لطفاً متن شغلی را بر این اساس بهروزرسانی کنید.
|
293 |
+
متن شغلی اصلی:
|
294 |
+
{job_description}
|
295 |
+
"""
|
296 |
+
|
297 |
+
# اضافه کردن Prompt به عنوان پیام سیستم
|
298 |
+
update_messages = [
|
299 |
+
SystemMessage(content=update_prompt)
|
300 |
+
]
|
301 |
+
|
302 |
+
update_response = llm(messages=update_messages)
|
303 |
+
job_description = update_response.content
|
304 |
+
|
305 |
+
# ارائه متن شغلی بهروزشده
|
306 |
+
updated_message = f"متن شغلی بهروزرسانیشده به شرح زیر است:\n\n{job_description}\n\nآیا این مورد رضایتبخش است؟"
|
307 |
+
memory.chat_memory.add_ai_message(updated_message)
|
308 |
+
return updated_message
|
309 |
+
elif any(word in message.lower() for word in ["بله", "موافقم", "رضایتبخش است", "خوب است"]):
|
310 |
+
job_description_confirmed = True
|
311 |
+
final_message = "عالی! متن شغلی نهایی شد. از زمانی که اختصاص دادید متشکرم."
|
312 |
+
memory.chat_memory.add_ai_message(final_message)
|
313 |
+
return final_message
|
314 |
+
|
315 |
+
return response.content
|
316 |
+
|
317 |
+
|
318 |
+
|
319 |
+
# def agent_respond(message, chat_history):
|
320 |
+
# messages = [{"role": "user", "content": message}]
|
321 |
+
# bot_response = get_model_response(messages)
|
322 |
+
# chat_history.append((message, bot_response))
|
323 |
+
# audio_response = synthesize_speech(bot_response)
|
324 |
+
# return chat_history, "", audio_response
|
325 |
|
326 |
|
327 |
import os
|