Update app.py
Browse files
app.py
CHANGED
|
@@ -122,14 +122,19 @@ def answer_abc_questions(selected, bg_info, wv, ps, dd):
|
|
| 122 |
|
| 123 |
|
| 124 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 职业详细介绍 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 125 |
-
def do_selected_career_detail(selected_career, bg_info, wv, ps, dd):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
prompt = f"""
|
| 127 |
你是一位专业的职业规划顾问。
|
| 128 |
学生最终选择的具体职业: {selected_career}
|
| 129 |
学生背景: {bg_info}
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
请写一份更详细的职业说明,至少包含:
|
| 134 |
1. 行业平均薪资(初级/中级/高级)
|
| 135 |
2. 工作环境(远程/混合/办公室,团队规模等)
|
|
@@ -167,9 +172,9 @@ def do_time_roadmap():
|
|
| 167 |
direction = user_profile.get("final_choice") or user_profile.get("selected_direction") or \
|
| 168 |
user_profile.get("forward_direction_choice") or user_profile.get("specific_career")
|
| 169 |
bg_info = user_profile["bg_info"] or "未知专业"
|
| 170 |
-
wv = user_profile
|
| 171 |
-
ps = user_profile
|
| 172 |
-
dd = user_profile
|
| 173 |
|
| 174 |
prompt_roadmap = f"""
|
| 175 |
学生信息:
|
|
@@ -341,15 +346,61 @@ def recommend_3directions():
|
|
| 341 |
return f"多方向推荐出错: {str(e)}"
|
| 342 |
|
| 343 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 生成系统提示 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 345 |
def generate_system_prompt():
|
| 346 |
mode = user_profile["mode"]
|
| 347 |
sc = user_profile["specific_career"]
|
| 348 |
bg = user_profile["bg_info"]
|
| 349 |
-
wv = user_profile
|
| 350 |
-
ps = user_profile
|
| 351 |
-
dd = user_profile
|
| 352 |
-
fwd = user_profile
|
| 353 |
|
| 354 |
if mode == "是":
|
| 355 |
return f"""
|
|
@@ -429,8 +480,15 @@ def predict(message, history):
|
|
| 429 |
user_profile["mode"] = ans
|
| 430 |
if "是" in ans:
|
| 431 |
in_backward_flow = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
else:
|
| 433 |
in_forward_flow = True
|
|
|
|
|
|
|
| 434 |
else:
|
| 435 |
user_profile[key] = message.strip()
|
| 436 |
|
|
@@ -443,71 +501,37 @@ def predict(message, history):
|
|
| 443 |
mode = user_profile.get("mode") or ""
|
| 444 |
|
| 445 |
# ~~~~~~~~~ Backward模式 ~~~~~~~~~
|
| 446 |
-
if
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
5. 日常工作节奏
|
| 476 |
-
6. 行业前景
|
| 477 |
-
用分段Markdown格式,字数不少于300字。
|
| 478 |
-
"""
|
| 479 |
-
msgs = [
|
| 480 |
-
{"role": "system", "content": "你是一位专业职业顾问,会为用户的目标职业提供详细分析。"},
|
| 481 |
-
{"role": "user", "content": career_detail_prompt}
|
| 482 |
-
]
|
| 483 |
-
resp = client.chat.completions.create(
|
| 484 |
-
model=model_default,
|
| 485 |
-
messages=msgs,
|
| 486 |
-
max_tokens=token_default,
|
| 487 |
-
temperature=temp_default,
|
| 488 |
-
top_p=top_p_default,
|
| 489 |
-
stream=False
|
| 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 答疑
|
| 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,12 +550,8 @@ def predict(message, history):
|
|
| 526 |
roadmap_offered = True
|
| 527 |
return abc_text + "\n\n以上是你所选的A/B/C专项信息。需要一个时间轴式职业路线图吗?如需,则回复【要】,否则回复【不要】。"
|
| 528 |
|
| 529 |
-
# 处理是否需要时间轴路线图
|
| 530 |
-
elif job_chosen and
|
| 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"]:
|
| 537 |
roadmap_done = True
|
|
@@ -542,7 +562,7 @@ def predict(message, history):
|
|
| 542 |
backward_done = True
|
| 543 |
return "好的,不生成时间轴,本次规划结束。"
|
| 544 |
|
| 545 |
-
# 最终收尾
|
| 546 |
if backward_done:
|
| 547 |
try:
|
| 548 |
api_key = os.environ.get("API_TOKEN")
|
|
|
|
| 122 |
|
| 123 |
|
| 124 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 职业详细介绍 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 125 |
+
def do_selected_career_detail(selected_career, bg_info, wv=None, ps=None, dd=None):
|
| 126 |
+
# 对于Backward模式,某些参数可能为None
|
| 127 |
+
wv_text = f"工作意义: {wv}" if wv else ""
|
| 128 |
+
ps_text = f"性格: {ps}" if ps else ""
|
| 129 |
+
dd_text = f"理想工作: {dd}" if dd else ""
|
| 130 |
+
|
| 131 |
prompt = f"""
|
| 132 |
你是一位专业的职业规划顾问。
|
| 133 |
学生最终选择的具体职业: {selected_career}
|
| 134 |
学生背景: {bg_info}
|
| 135 |
+
{wv_text}
|
| 136 |
+
{ps_text}
|
| 137 |
+
{dd_text}
|
| 138 |
请写一份更详细的职业说明,至少包含:
|
| 139 |
1. 行业平均薪资(初级/中级/高级)
|
| 140 |
2. 工作环境(远程/混合/办公室,团队规模等)
|
|
|
|
| 172 |
direction = user_profile.get("final_choice") or user_profile.get("selected_direction") or \
|
| 173 |
user_profile.get("forward_direction_choice") or user_profile.get("specific_career")
|
| 174 |
bg_info = user_profile["bg_info"] or "未知专业"
|
| 175 |
+
wv = user_profile.get("work_value", "暂无")
|
| 176 |
+
ps = user_profile.get("personality_summary", "暂无")
|
| 177 |
+
dd = user_profile.get("dream_day", "暂无")
|
| 178 |
|
| 179 |
prompt_roadmap = f"""
|
| 180 |
学生信息:
|
|
|
|
| 346 |
return f"多方向推荐出错: {str(e)}"
|
| 347 |
|
| 348 |
|
| 349 |
+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Backward模式专用:生成职业分析 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 350 |
+
def generate_backward_career_analysis():
|
| 351 |
+
career = user_profile.get("specific_career") or "未指定职业"
|
| 352 |
+
bg_info = user_profile.get("bg_info") or "未知背景"
|
| 353 |
+
|
| 354 |
+
prompt = f"""
|
| 355 |
+
你是一位专业的职业规划顾问,使用Backward Design方法帮助学生达成职业目标。
|
| 356 |
+
目标职业: {career}
|
| 357 |
+
学生背景: {bg_info}
|
| 358 |
+
|
| 359 |
+
请提供一份详细的职业分析报告,包括以下内容:
|
| 360 |
+
1. 该职业的基本介绍和行业现状
|
| 361 |
+
2. 该领域排名前列的组织或公司
|
| 362 |
+
3. 从业所需的核心技能和能力
|
| 363 |
+
4. 典型的职业发展路径
|
| 364 |
+
5. 针对学生背景的具体建议:
|
| 365 |
+
- 学术课程建议
|
| 366 |
+
- 技能培养重点
|
| 367 |
+
- 实习和实践经验积累方向
|
| 368 |
+
- 专业证书和资格认证
|
| 369 |
+
|
| 370 |
+
请使用Markdown格式,保持专业性和具体性。
|
| 371 |
+
"""
|
| 372 |
+
try:
|
| 373 |
+
api_key = os.environ.get("API_TOKEN")
|
| 374 |
+
if not api_key:
|
| 375 |
+
return "错误:API_TOKEN 未设置"
|
| 376 |
+
client = OpenAI(api_key=api_key)
|
| 377 |
+
|
| 378 |
+
msgs = [
|
| 379 |
+
{"role": "system", "content": "你是一位专业职业顾问,擅长分析特定职业的要求和发展路径。"},
|
| 380 |
+
{"role": "user", "content": prompt}
|
| 381 |
+
]
|
| 382 |
+
resp = client.chat.completions.create(
|
| 383 |
+
model=model_default,
|
| 384 |
+
messages=msgs,
|
| 385 |
+
max_tokens=token_default,
|
| 386 |
+
temperature=temp_default,
|
| 387 |
+
top_p=top_p_default,
|
| 388 |
+
stream=False
|
| 389 |
+
)
|
| 390 |
+
return resp.choices[0].message.content
|
| 391 |
+
except Exception as e:
|
| 392 |
+
return f"生成职业分析时出错: {str(e)}"
|
| 393 |
+
|
| 394 |
+
|
| 395 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 生成系统提示 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 396 |
def generate_system_prompt():
|
| 397 |
mode = user_profile["mode"]
|
| 398 |
sc = user_profile["specific_career"]
|
| 399 |
bg = user_profile["bg_info"]
|
| 400 |
+
wv = user_profile.get("work_value")
|
| 401 |
+
ps = user_profile.get("personality_summary")
|
| 402 |
+
dd = user_profile.get("dream_day")
|
| 403 |
+
fwd = user_profile.get("forward_direction_choice")
|
| 404 |
|
| 405 |
if mode == "是":
|
| 406 |
return f"""
|
|
|
|
| 480 |
user_profile["mode"] = ans
|
| 481 |
if "是" in ans:
|
| 482 |
in_backward_flow = True
|
| 483 |
+
# 重置Forward模式标记,确保不会混淆
|
| 484 |
+
in_forward_flow = False
|
| 485 |
+
direction_chosen = False
|
| 486 |
+
jobs_recommended = False
|
| 487 |
+
job_chosen = False
|
| 488 |
else:
|
| 489 |
in_forward_flow = True
|
| 490 |
+
# 重置Backward模式标记,确保不会混淆
|
| 491 |
+
in_backward_flow = False
|
| 492 |
else:
|
| 493 |
user_profile[key] = message.strip()
|
| 494 |
|
|
|
|
| 501 |
mode = user_profile.get("mode") or ""
|
| 502 |
|
| 503 |
# ~~~~~~~~~ Backward模式 ~~~~~~~~~
|
| 504 |
+
if "是" in mode and in_backward_flow:
|
| 505 |
+
# 处理Backward模式的额外问题
|
| 506 |
+
if backward_index > 0 and backward_index <= len(backward_additional_questions):
|
| 507 |
+
prev_key = backward_additional_questions[backward_index - 1][0]
|
| 508 |
+
user_profile[prev_key] = message.strip()
|
| 509 |
+
|
| 510 |
+
if backward_index < len(backward_additional_questions):
|
| 511 |
+
k, prompt_text = backward_additional_questions[backward_index]
|
| 512 |
+
backward_index += 1
|
| 513 |
+
return prompt_text
|
| 514 |
+
|
| 515 |
+
# 已收集完Backward模式的所有基本信息,但尚未提供职业分析
|
| 516 |
+
elif not job_chosen:
|
| 517 |
+
# 设置职业选择状态
|
| 518 |
+
user_profile["final_choice"] = user_profile.get("specific_career")
|
| 519 |
+
job_chosen = True
|
| 520 |
+
|
| 521 |
+
# 生成职业分析报告
|
| 522 |
+
career_analysis = generate_backward_career_analysis()
|
| 523 |
+
|
| 524 |
+
# 询问是否需要A/B/C专项信息
|
| 525 |
+
post_career_detail_asked = True
|
| 526 |
+
|
| 527 |
+
return career_analysis + "\n\n我还可以针对以下三方面提供更深入的分析建议:" \
|
| 528 |
+
"\n- A:专业/选课 & 求职方向" \
|
| 529 |
+
"\n- B:本校资源利用建议" \
|
| 530 |
+
"\n- C:实习 & networking 积累" \
|
| 531 |
+
"\n如果你想查看其中一个或多个,请输入 A / B / C / AB / BC / AC / ABC" \
|
| 532 |
+
"\n如果都不需要,请回复'不需要'。"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 533 |
|
| 534 |
+
# 处理 A/B/C 答疑
|
| 535 |
elif post_career_detail_asked and not post_career_detail_done:
|
| 536 |
user_choice = message.strip().lower()
|
| 537 |
if user_choice in ["不需要", "no", "n"]:
|
|
|
|
| 550 |
roadmap_offered = True
|
| 551 |
return abc_text + "\n\n以上是你所选的A/B/C专项信息。需要一个时间轴式职业路线图吗?如需,则回复【要】,否则回复【不要】。"
|
| 552 |
|
| 553 |
+
# 处理是否需要时间轴路线图
|
| 554 |
+
elif job_chosen and roadmap_offered and not roadmap_done:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
ans = message.strip().lower()
|
| 556 |
if ans in ["要", "yes", "y"]:
|
| 557 |
roadmap_done = True
|
|
|
|
| 562 |
backward_done = True
|
| 563 |
return "好的,不生成时间轴,本次规划结束。"
|
| 564 |
|
| 565 |
+
# 最终收尾
|
| 566 |
if backward_done:
|
| 567 |
try:
|
| 568 |
api_key = os.environ.get("API_TOKEN")
|