Stone164 commited on
Commit
042413b
·
verified ·
1 Parent(s): 44a2029

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -19
app.py CHANGED
@@ -443,31 +443,32 @@ def predict(message, history):
443
  mode = user_profile.get("mode") or ""
444
 
445
  # ~~~~~~~~~ Backward模式 ~~~~~~~~~
446
- if mode == "是":
447
  if in_backward_flow and not backward_done:
 
448
  if backward_index > 0 and backward_index <= len(backward_additional_questions):
449
  prev_key = backward_additional_questions[backward_index - 1][0]
450
  user_profile[prev_key] = message.strip()
451
 
 
452
  if backward_index < len(backward_additional_questions):
453
  k, prompt_text = backward_additional_questions[backward_index]
454
  backward_index += 1
455
  return prompt_text
456
  else:
457
- # 修改这里,不要直接设置backward_done为True
458
- # 而是需要生成职业详情并询问是否需要A/B/C专项信息
459
  try:
460
  api_key = os.environ.get("API_TOKEN")
461
  if not api_key:
462
  return "错误:API_TOKEN 未设置"
463
  client = OpenAI(api_key=api_key)
464
 
465
- # 生成职业详情
466
  career_detail_prompt = f"""
467
  你是一位专业的职业规划顾问。
468
  学生目标职业: {user_profile.get('specific_career') or '未知'}
469
  学生背景: {user_profile.get('bg_info') or '未知'}
470
- 请写一份详细的职业说明,至少包含:
471
  1. 行业平均薪资(初级/中级/高级)
472
  2. 工作环境(远程/混合/办公室,团队规模等)
473
  3. 晋升难度(需要什么资历或条件)
@@ -490,24 +491,23 @@ def predict(message, history):
490
  )
491
  detail_msg = resp.choices[0].message.content
492
 
493
- # 设置状态,与Forward模式保持一致
494
  user_profile["final_choice"] = user_profile.get("specific_career")
495
- job_chosen = True
496
- forward_deep_dive_done = True
497
  post_career_detail_asked = True
498
 
499
  # 返回职业详情并询问A/B/C
500
  return detail_msg + "\n\n我还可以针对以下三方面提供更深入的分析建议:" \
501
- "\n- A:专业/选课 & 求职方向" \
502
- "\n- B:本校资源利用建议" \
503
- "\n- C:实习 & networking 积累" \
504
- "\n如果你想查看其中一个或多个,请输入 A / B / C / AB / BC / AC / ABC" \
505
- "\n如果都不需要,请回复'不需要'。"
506
 
507
  except Exception as e:
508
  return f"生成职业详情时出错: {str(e)}"
509
 
510
- # 处理 A/B/C 答疑 (复用Forward模式的逻辑)
511
  elif post_career_detail_asked and not post_career_detail_done:
512
  user_choice = message.strip().lower()
513
  if user_choice in ["不需要", "no", "n"]:
@@ -526,11 +526,7 @@ def predict(message, history):
526
  roadmap_offered = True
527
  return abc_text + "\n\n以上是你所选的A/B/C专项信息。需要一个时间轴式职业路线图吗?如需,则回复【要】,否则回复【不要】。"
528
 
529
- # 处理是否需要时间轴路线图 (复用Forward模式的逻辑)
530
- elif job_chosen and not roadmap_offered and not roadmap_done:
531
- roadmap_offered = True
532
- return "需要一个时间轴式职业路线图吗?如需,则回复【要】,否则回复【不要】。"
533
-
534
  elif roadmap_offered and not roadmap_done:
535
  ans = message.strip().lower()
536
  if ans in ["要", "yes", "y"]:
 
443
  mode = user_profile.get("mode") or ""
444
 
445
  # ~~~~~~~~~ Backward模式 ~~~~~~~~~
446
+ if "是" in mode: # 使用"是"而不是精确匹配,以防用户回复"是的"等
447
  if in_backward_flow and not backward_done:
448
+ # 处理上一个问题的回答
449
  if backward_index > 0 and backward_index <= len(backward_additional_questions):
450
  prev_key = backward_additional_questions[backward_index - 1][0]
451
  user_profile[prev_key] = message.strip()
452
 
453
+ # 提出下一个问题
454
  if backward_index < len(backward_additional_questions):
455
  k, prompt_text = backward_additional_questions[backward_index]
456
  backward_index += 1
457
  return prompt_text
458
  else:
459
+ # 所有问题都已回答完毕
 
460
  try:
461
  api_key = os.environ.get("API_TOKEN")
462
  if not api_key:
463
  return "错误:API_TOKEN 未设置"
464
  client = OpenAI(api_key=api_key)
465
 
466
+ # 生成职业详情
467
  career_detail_prompt = f"""
468
  你是一位专业的职业规划顾问。
469
  学生目标职业: {user_profile.get('specific_career') or '未知'}
470
  学生背景: {user_profile.get('bg_info') or '未知'}
471
+ 为这位想要从事 {user_profile.get('specific_career')} 职业的学生写一份详细的职业说明,至少包含:
472
  1. 行业平均薪资(初级/中级/高级)
473
  2. 工作环境(远程/混合/办公室,团队规模等)
474
  3. 晋升难度(需要什么资历或条件)
 
491
  )
492
  detail_msg = resp.choices[0].message.content
493
 
494
+ # 设置状态
495
  user_profile["final_choice"] = user_profile.get("specific_career")
496
+ job_chosen = True # 直接标记为已选择职业
 
497
  post_career_detail_asked = True
498
 
499
  # 返回职业详情并询问A/B/C
500
  return detail_msg + "\n\n我还可以针对以下三方面提供更深入的分析建议:" \
501
+ "\n- A:专业/选课 & 求职方向" \
502
+ "\n- B:本校资源利用建议" \
503
+ "\n- C:实习 & networking 积累" \
504
+ "\n如果你想查看其中一个或多个,请输入 A / B / C / AB / BC / AC / ABC" \
505
+ "\n如果都不需要,请回复'不需要'。"
506
 
507
  except Exception as e:
508
  return f"生成职业详情时出错: {str(e)}"
509
 
510
+ # 处理 A/B/C 答疑
511
  elif post_career_detail_asked and not post_career_detail_done:
512
  user_choice = message.strip().lower()
513
  if user_choice in ["不需要", "no", "n"]:
 
526
  roadmap_offered = True
527
  return abc_text + "\n\n以上是你所选的A/B/C专项信息。需要一个时间轴式职业路线图吗?如需,则回复【要】,否则回复【不要】。"
528
 
529
+ # 处理是否需要时间轴路线图
 
 
 
 
530
  elif roadmap_offered and not roadmap_done:
531
  ans = message.strip().lower()
532
  if ans in ["要", "yes", "y"]: