一、实战一简历投递与 AI 岗位匹配度分析1.1 接口层 job_api.py投递详情job_router.get(/resume_submission_detail/{id}, summary简历投递详情) async def resume_submission_detail(id: int): res await JobService.resume_submission_detail(id) return {code: 1, message: OK, data: json.loads(res)}1.2 服务层详情接口让大模型当HR 专家打分resume_submission_detail会先聚合求职者全量档案基本信息、求职意向、工作/项目/教育经历、专业技能、优势、语言能力再连同职位 JD 一起塞进一个超长 prompt要求大模型以 JSON 输出匹配度 理由。staticmethod async def resume_submission_detail(id: int): resume_submission_record await ResumeSubmissionRecords.get_or_none(idid) #获取职位信息 job await Job.get_or_none(idresume_submission_record.job_id) #获取求职者信息 job_seeker await JobSeeker.get_or_none(idresume_submission_record.job_seeker_id) #获取求职者简历信息 resume_basic_info await ResumeBasicInfo.get_or_none(job_seeker_idjob_seeker.id) #获取求职意向信息 jobintention await JobIntention.get_or_none(job_seeker_idjob_seeker.id) #获取求职者的工作经历 (一对多) work_experiences await WorkExperience.filter(job_seeker_idjob_seeker.id) work_experience_list [] for work_experience in work_experiences: work_experience_data { 公司名称: work_experience.company_name, 所属行业: work_experience.industry, 职位名称: work_experience.position, 入职时间: work_experience.entry_time, 离职时间: work_experience.leave_time, 工作内容: work_experience.work_content, 工作业绩: work_experience.performance, 拥有技能列表: work_experience.skills, } work_experience_list.append(work_experience_data) #获取求职者项目经历 (一对多) project_experiences await ProjectExperience.filter(job_seeker_idjob_seeker.id) project_experience_list [] for project_experience in project_experiences: project_experience_data { 项目名称: project_experience.project_name, 项目角色: project_experience.project_role, 项目开始时间: project_experience.start_time, 项目结束时间: project_experience.end_time, 项目描述: project_experience.project_desc, 项目业绩: project_experience.project_performance, } project_experience_list.append(project_experience_data) #获取求职者教育经历 (一对多) education_experiences await EducationExperience.filter(job_seeker_idjob_seeker.id) education_experience_list [] for education_experience in education_experiences: education_experience_data { 学历名称: education_experience.education_name, 学制类型: education_experience.study_type, 学校名称: education_experience.school_name, 专业名称: education_experience.major_name, 入学时间: education_experience.entry_date, 毕业时间: education_experience.graduate_date, 在校经历: education_experience.school_experience, } education_experience_list.append(education_experience_data) #获取求职者的专业技能 ProfessionalSkill professional_skills await ProfessionalSkill.filter(job_seeker_idjob_seeker.id) professional_skill_list [] for professional_skill in professional_skills: professional_skill_data professional_skill.skill_desc #技能描述 professional_skill_list.append(professional_skill_data) #获取求职者的优势 AdvantageEvaluation advantage_evaluations await AdvantageEvaluation.filter(job_seeker_idjob_seeker.id) advantage_evaluation_list [] for advantage_evaluation in advantage_evaluations: advantage_evaluation_data advantage_evaluation.personal_advantage #优势描述 advantage_evaluation_list.append(advantage_evaluation_data) #获取求职者的语言 LanguageAbility language_abilitys await LanguageAbility.filter(job_seeker_idjob_seeker.id) language_ability_list [] for language_ability in language_abilitys: language_ability_data language_ability.language_desc #语言描述 language_ability_list.append(language_ability_data) prompt f ## 角色设定: 你是一个经验丰富的人力资源专家 ## 任务描述: 根据求职者简历内容和岗位的职位描述,分析岗位匹配度和理由 ## 输入数据: 1:岗位的职位描述: 1.1:职位名称: {job.job_name} 1.2:工作地点: {job.work_location} 1.3:最低薪资:{job.min_salary} 1.4:最高薪资:{job.max_salary} 1.5:经验要求:{job.exp_require} 1.6:学历要求:{job.edu_require} 1.7:性别要求:{job.gender_require} 1.8:职位描述:{job.job_desc} 1.9:任职要求:{job.duty_require} 2:求职者简历内容: 2.1:求职者性别(1-男2-女):{resume_basic_info.gender} 2.2:求职者出生日期:{resume_basic_info.birth_date} 2.3:求职者政治面貌(1-群众 2-党员 3-其他):{resume_basic_info.political_status} 2.4:求职者婚姻状况(1-未婚 2-已婚 3-保密):{resume_basic_info.marital_status} 2.5:求职者期望职位列表:{,.join([item[name] for item in jobintention.expect_position])} 2.6:求职者期望薪资:{jobintention.expect_salary} 2.7:求职者工作性质(1-全职 2-兼职 3-其他):{jobintention.work_type} 2.8:求职者期望城市列表:{jobintention.expect_city} 2.9:求职者期望行业列表:{jobintention.expect_industry} 2.10:求职者工作经历:{work_experience_list} 2.11:求职者项目经历:{project_experience_list} 2.12:求职者教育经历:{education_experience_list} 2.13:求职者专业技能:{professional_skill_list} 2.14:求职者优势:{advantage_evaluation_list} 2.15:求职者语言能力:{language_ability_list} ## 输出格式 以JSON格式输出,包含以下字段: job_matching_degree:岗位匹配度(0-100)百分比: matching_reason: 重要禁止输出任何思考、推理、标签直接输出JSON结果不要输出其他文字。 ## 输出示例: {{job_matching_degree: 80%, matching_reason: 求职者期望职位列表与岗位职位描述匹配度高:项目经历匹配}} client OpenAI( api_keyos.getenv(DASHSCOPE_API_KEY), base_urlhttps://ws-7msqefw8eteh9spo.cn-beijing.maas.aliyuncs.com/compatible-mode/v1 ) completions client.chat.completions.create( modelqwen-plus, messages[ {role: user, content: prompt}, ], ) res completions.choices[0].message.content return res二、实战二Function Calling 工具调用2.1 case5单工具天气查询入门def get_ai_response(messages: list): completion client.chat.completions.create( modelqwen-plus, messagesmessages, toolstools) return completion def get_current_weather(arguments): # 本地真实函数 weather_conditions [晴天, 多云, 雨天] location arguments[location] return f{location}今天是{random.choice(weather_conditions)}。 tools [{ type: function, function: { name: get_current_weather, description: 当你想查询指定城市的天气时非常有用。, parameters: { type: object, properties: {location: {type: string, description: 城市或县区比如北京市。}}, required: [location], }}}]核心交互流程——模型返回tool_calls时解析出函数名/参数/调用 ID本地执行后把结果以role:tool消息回传再调一次模型得到最终答案response get_ai_response(messages) messages.append(response.choices[0].message) if response.choices[0].message.tool_calls is None: print(不需要使用工具, response.choices[0].message.content) else: for tool_call in response.choices[0].message.tool_calls: tool_call_id tool_call.id name tool_call.function.name args tool_call.function.arguments function_mapping {get_current_weather: get_current_weather} result function_mapping[name](json.loads(args)) messages.append({ # 把工具结果回传给模型 role: tool, tool_call_id: tool_call_id, content: result}) completion get_ai_response(messages) # 第二次调用拿到自然语言答案 print(completion.choices[0].message.content)2.2 case6多工具 外部 API Redis 缓存case6 在 case5 基础上加了第二个工具academic_credential_verification学历验证调外部 HTTP 接口并用 Redis 缓存结果避免同一验证码重复请求。def academic_credential_verification(arguments): vcode arguments[vcode] key fboss:llm:academic_credential_verification:{vcode} redis_data redis_client.get(key) if redis_data is None: BASE_URL https://www.apimy.cn/api/xxw/bgcx params {key: os.getenv(MY_API_KEY), vcode: arguments[vcode]} response requests.get(BASE_URL, paramsparams, timeout30) response.raise_for_status() data response.json() return json.dumps(data, ensure_asciiFalse) else: return redis_data # 命中缓存直接返回 # 工具路由用字典把模型给的函数名映射到本地实现 function_mapping { get_current_weather: get_current_weather, academic_credential_verification: academic_credential_verification, }2.3 工具调用标准流程定义工具列表 tools描述有哪些函数、函数作用、入参 JSON Schema组装 messages 用户对话上下文请求 LLM传入tools、tool_choiceauto拿到模型返回判断返回是否存在tool_calls✅有解析函数名、参数本地 Python 代码执行对应工具函数❌无直接返回模型文本回答流程结束将工具执行结果组装成一条roletool的消息追加到 messages带上tool_call_id再次把更新后的 messages 请求大模型大模型结合工具返回结果输出最终自然语言回答流程结束可以循环多次一次对话中模型可以连续调用多个工具。