prompt_utils.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. ('preferred_nickname', '希望对其的称呼'),
  40. ('name', '姓名'),
  41. ('avatar', '头像'),
  42. ('gender', '性别'),
  43. ('age', '年龄'),
  44. ('region', '地区'),
  45. ('health_conditions', '健康状况'),
  46. ('interests', '兴趣爱好'),
  47. ('interaction_frequency', '联系频率'),
  48. ('flexible_params', '动态特征'),
  49. ]
  50. strings_to_join = []
  51. for field in fields:
  52. value = profile.get(field[0], None)
  53. if not value:
  54. continue
  55. if isinstance(value, list):
  56. value = ','.join(value)
  57. elif isinstance(value, dict):
  58. value = ';'.join(f"{k}: {v}" for k, v in value.items())
  59. else:
  60. value = profile[field[0]]
  61. cur_string = f"- {field[1]}:{value}"
  62. strings_to_join.append(cur_string)
  63. return "\n".join(strings_to_join)