cdcvd commited on
Commit
4ccaf3c
·
verified ·
1 Parent(s): 9ffdb83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -82
app.py CHANGED
@@ -240,88 +240,88 @@ def get_model_response(messages):
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
 
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