Update app.py
Browse files
app.py
CHANGED
|
@@ -494,50 +494,48 @@ def predict(message, history):
|
|
| 494 |
post_career_detail_asked = False
|
| 495 |
post_career_detail_done = False
|
| 496 |
|
| 497 |
-
# ======================== 先处理基础问题 =========================
|
| 498 |
-
if
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
|
|
|
|
|
|
| 515 |
if current_q_index < len(questions):
|
| 516 |
nxt = questions[current_q_index][1]
|
| 517 |
current_q_index += 1
|
| 518 |
return nxt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 519 |
|
| 520 |
# ======================== 分模式处理 =========================
|
| 521 |
-
mode = user_profile.get("mode") or ""
|
| 522 |
-
|
| 523 |
# ~~~~~~~~~ Backward模式 ~~~~~~~~~
|
| 524 |
-
if
|
| 525 |
-
#
|
| 526 |
-
if
|
| 527 |
-
|
| 528 |
-
user_profile[
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
k, prompt_text = backward_additional_questions[backward_index]
|
| 532 |
-
backward_index += 1
|
| 533 |
-
return prompt_text
|
| 534 |
-
|
| 535 |
-
# 已收集完Backward模式的所有基本信息,但尚未提供职业分析
|
| 536 |
-
elif not backward_analysis_given:
|
| 537 |
# 生成职业分析报告
|
| 538 |
career_analysis = generate_backward_career_analysis()
|
| 539 |
backward_analysis_given = True
|
| 540 |
-
backward_job_chosen = True
|
| 541 |
|
| 542 |
# 询问是否需要A/B/C专项信息
|
| 543 |
post_career_detail_asked = True
|
|
@@ -603,23 +601,13 @@ def predict(message, history):
|
|
| 603 |
return resp.choices[0].message.content
|
| 604 |
except Exception as e:
|
| 605 |
return f"发生错误: {str(e)}"
|
| 606 |
-
|
| 607 |
# ~~~~~~~~~ Forward模式 ~~~~~~~~~
|
| 608 |
-
|
| 609 |
# 前期处理:收集信息和推荐大方向
|
| 610 |
-
if
|
| 611 |
-
# 收集
|
| 612 |
-
if
|
| 613 |
-
prev_key = forward_additional_questions[forward_index - 1][0]
|
| 614 |
-
user_profile[prev_key] = message.strip()
|
| 615 |
-
|
| 616 |
-
if forward_index < len(forward_additional_questions):
|
| 617 |
-
k, prompt_text = forward_additional_questions[forward_index]
|
| 618 |
-
forward_index += 1
|
| 619 |
-
return prompt_text
|
| 620 |
-
|
| 621 |
-
# 问完 4个问题 -> 推荐3方向
|
| 622 |
-
elif not forward_recommendation_given:
|
| 623 |
forward_recommendation_given = True
|
| 624 |
return recommend_3directions()
|
| 625 |
|
|
@@ -699,7 +687,7 @@ def predict(message, history):
|
|
| 699 |
else:
|
| 700 |
return "请回复1/2/3选择具体职业,或输入'换'来重新推荐"
|
| 701 |
|
| 702 |
-
# 处理 A/B/C 答疑
|
| 703 |
elif post_career_detail_asked and not post_career_detail_done:
|
| 704 |
user_choice = message.strip().lower()
|
| 705 |
if user_choice in ["不需要", "no", "n"]:
|
|
|
|
| 494 |
post_career_detail_asked = False
|
| 495 |
post_career_detail_done = False
|
| 496 |
|
| 497 |
+
# ======================== 先处理第一个基础问题(选择模式) =========================
|
| 498 |
+
if current_q_index == 1: # 正在等待用户回答第一个问题
|
| 499 |
+
ans = message.strip()
|
| 500 |
+
user_profile["mode"] = ans
|
| 501 |
+
|
| 502 |
+
# 严格判断用户输入
|
| 503 |
+
if "是" in ans:
|
| 504 |
+
in_backward_flow = True
|
| 505 |
+
in_forward_flow = False
|
| 506 |
+
# 设置下一个问题为Backward模式的第一个问题
|
| 507 |
+
questions = backward_additional_questions[:]
|
| 508 |
+
current_q_index = 0
|
| 509 |
+
else: # "否"或其他输入
|
| 510 |
+
in_forward_flow = True
|
| 511 |
+
in_backward_flow = False
|
| 512 |
+
# 设置下一个问题为Forward模式的第一个问题
|
| 513 |
+
questions = forward_additional_questions[:]
|
| 514 |
+
current_q_index = 0
|
| 515 |
+
|
| 516 |
+
# 如果还在基本问题中,就继续提问
|
| 517 |
if current_q_index < len(questions):
|
| 518 |
nxt = questions[current_q_index][1]
|
| 519 |
current_q_index += 1
|
| 520 |
return nxt
|
| 521 |
+
|
| 522 |
+
# 收集上一个问题的答案
|
| 523 |
+
if current_q_index > 0 and current_q_index <= len(questions):
|
| 524 |
+
key = questions[current_q_index - 1][0]
|
| 525 |
+
user_profile[key] = message.strip()
|
| 526 |
|
| 527 |
# ======================== 分模式处理 =========================
|
|
|
|
|
|
|
| 528 |
# ~~~~~~~~~ Backward模式 ~~~~~~~~~
|
| 529 |
+
if in_backward_flow:
|
| 530 |
+
# 已收集完Backward模式的所有基本问题,但尚未提供职业分析
|
| 531 |
+
if not backward_analysis_given:
|
| 532 |
+
# 设置职业选择状态
|
| 533 |
+
user_profile["final_choice"] = user_profile.get("specific_career")
|
| 534 |
+
backward_job_chosen = True
|
| 535 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
# 生成职业分析报告
|
| 537 |
career_analysis = generate_backward_career_analysis()
|
| 538 |
backward_analysis_given = True
|
|
|
|
| 539 |
|
| 540 |
# 询问是否需要A/B/C专项信息
|
| 541 |
post_career_detail_asked = True
|
|
|
|
| 601 |
return resp.choices[0].message.content
|
| 602 |
except Exception as e:
|
| 603 |
return f"发生错误: {str(e)}"
|
| 604 |
+
|
| 605 |
# ~~~~~~~~~ Forward模式 ~~~~~~~~~
|
| 606 |
+
elif in_forward_flow:
|
| 607 |
# 前期处理:收集信息和推荐大方向
|
| 608 |
+
if not direction_chosen:
|
| 609 |
+
# 收集完4个基础问题后,推荐3方向
|
| 610 |
+
if not forward_recommendation_given:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 611 |
forward_recommendation_given = True
|
| 612 |
return recommend_3directions()
|
| 613 |
|
|
|
|
| 687 |
else:
|
| 688 |
return "请回复1/2/3选择具体职业,或输入'换'来重新推荐"
|
| 689 |
|
| 690 |
+
# 处理 A/B/C 答疑 (与Backward模式共用这部分逻辑)
|
| 691 |
elif post_career_detail_asked and not post_career_detail_done:
|
| 692 |
user_choice = message.strip().lower()
|
| 693 |
if user_choice in ["不需要", "no", "n"]:
|