prompt_utils.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from typing import Dict
  2. def format_agent_profile(profile: Dict) -> str:
  3. fields = [
  4. ('name', '名字'),
  5. ('gender', '性别'),
  6. ('age', '年龄'),
  7. ('region', '所在地'),
  8. ('previous_location', '之前所在地'),
  9. ('education', '学历'),
  10. ('occupation', '职业'),
  11. ('work_experience', '工作经历'),
  12. ('family_members', '家庭成员'),
  13. ('family_occupation', '家庭成员职业')
  14. ]
  15. strings_to_join = []
  16. for field in fields:
  17. if not profile.get(field[0], None):
  18. continue
  19. cur_string = f"- {field[1]}:{profile[field[0]]}"
  20. strings_to_join.append(cur_string)
  21. return "\n".join(strings_to_join)
  22. def format_user_profile(profile: Dict) -> str:
  23. """
  24. :param profile:
  25. :return: formatted string.
  26. example:
  27. - 微信昵称:{nickname}
  28. - 姓名:{name}
  29. - 头像:{avatar}
  30. - 偏好的称呼:{preferred_nickname}
  31. - 年龄:{age}
  32. - 地区:{region}
  33. - 健康状况:{health_conditions}
  34. - 用药信息:{medications}
  35. - 兴趣爱好:{interests}
  36. """
  37. fields = [
  38. ('nickname', '微信昵称'),
  39. ('name', '姓名'),
  40. ('avatar', '头像'),
  41. ('preferred_nickname', '偏好的称呼'),
  42. ('age', '年龄'),
  43. ('region', '地区'),
  44. ('health_conditions', '健康状况'),
  45. ('medications', '用药信息'),
  46. ('interests', '兴趣爱好')
  47. ]
  48. strings_to_join = []
  49. for field in fields:
  50. if not profile.get(field[0], None):
  51. continue
  52. if isinstance(profile[field[0]], list):
  53. value = ','.join(profile[field[0]])
  54. else:
  55. value = profile[field[0]]
  56. cur_string = f"- {field[1]}:{value}"
  57. strings_to_join.append(cur_string)
  58. return "\n".join(strings_to_join)