Spaces:
Running
Running
Yufan_Zhou commited on
Commit ·
5b5571e
1
Parent(s): 29b565d
Increase temperature for higher randomness in profile generation
Browse files
generate_user_profile_final/code/based_data.py
CHANGED
|
@@ -115,73 +115,41 @@ def generate_career_info(age: int) -> Dict[str, str]:
|
|
| 115 |
career_status = random.choice(occupations)
|
| 116 |
return {"status": career_status}
|
| 117 |
|
| 118 |
-
# def generate_location() -> Dict[str, str]:
|
| 119 |
-
# """生成真实的地理位置信息。
|
| 120 |
-
|
| 121 |
-
# 使用 GeoNames 数据库随机选择一个国家和城市。
|
| 122 |
-
|
| 123 |
-
# Returns:
|
| 124 |
-
# Dict[str, str]: 包含以下字段的字典:
|
| 125 |
-
# - country: 国家名称
|
| 126 |
-
# - city: 城市名称
|
| 127 |
-
# """
|
| 128 |
-
# gc = GeonamesCache()
|
| 129 |
-
|
| 130 |
-
# # 获取所有国家
|
| 131 |
-
# countries = gc.get_countries()
|
| 132 |
-
# country_code = random.choice(list(countries.keys()))
|
| 133 |
-
# country = countries[country_code]
|
| 134 |
-
|
| 135 |
-
# # 获取选国家的所有城市
|
| 136 |
-
# cities = gc.get_cities()
|
| 137 |
-
# country_cities = [city for city in cities.values() if city['countrycode'] == country_code]
|
| 138 |
-
|
| 139 |
-
# if not country_cities:
|
| 140 |
-
# return {
|
| 141 |
-
# "country": country['name'],
|
| 142 |
-
# "city": "Unknown City"
|
| 143 |
-
# }
|
| 144 |
-
|
| 145 |
-
# # 随机选择一个城市
|
| 146 |
-
# city_data = random.choice(country_cities)
|
| 147 |
-
|
| 148 |
-
# return {
|
| 149 |
-
# "country": country['name'],
|
| 150 |
-
# "city": city_data['name']
|
| 151 |
-
# }
|
| 152 |
-
|
| 153 |
-
|
| 154 |
def generate_location() -> Dict[str, str]:
|
| 155 |
-
"""
|
| 156 |
-
生成印度随机城市的地理位置信息。
|
| 157 |
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
| 163 |
"""
|
| 164 |
gc = GeonamesCache()
|
| 165 |
|
| 166 |
-
#
|
| 167 |
-
country_code = "IN"
|
| 168 |
countries = gc.get_countries()
|
| 169 |
-
|
|
|
|
| 170 |
|
| 171 |
-
#
|
| 172 |
-
cities
|
| 173 |
-
|
| 174 |
-
city for city in cities.values()
|
| 175 |
-
if city["countrycode"] == country_code
|
| 176 |
-
]
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
-
# ---- 随机选择一个城市 ----
|
| 183 |
-
city_data = random.choice(in_cities_list)
|
| 184 |
-
return {"country": country["name"], "city": city_data["name"]}
|
| 185 |
|
| 186 |
|
| 187 |
def generate_gender() -> str:
|
|
@@ -229,7 +197,7 @@ def generate_personal_values(age: int, gender: str, occupation: str, location: D
|
|
| 229 |
]
|
| 230 |
|
| 231 |
try:
|
| 232 |
-
response = get_completion(messages, temperature=
|
| 233 |
|
| 234 |
# 使用config.py中的解析函数
|
| 235 |
result = parse_gpt_response(
|
|
@@ -299,7 +267,7 @@ def generate_life_attitude(age: int = None, gender: str = None, occupation: str
|
|
| 299 |
]
|
| 300 |
|
| 301 |
try:
|
| 302 |
-
response = get_completion(messages, temperature=
|
| 303 |
|
| 304 |
# 使用config.py中的解析函数
|
| 305 |
result = parse_gpt_response(
|
|
@@ -383,7 +351,7 @@ def generate_personal_story(age: int, gender: str, occupation: str, location: Di
|
|
| 383 |
]
|
| 384 |
|
| 385 |
try:
|
| 386 |
-
response = get_completion(messages, temperature=
|
| 387 |
|
| 388 |
# 解析JSON响应,只获取个人故事
|
| 389 |
result = parse_gpt_response(
|
|
@@ -457,7 +425,7 @@ def generate_interests_and_hobbies(personal_story: Dict[str, Any]) -> Dict[str,
|
|
| 457 |
]
|
| 458 |
|
| 459 |
try:
|
| 460 |
-
response = get_completion(messages, temperature=0.
|
| 461 |
|
| 462 |
# 使用config.py中的解析函数
|
| 463 |
from config import parse_gpt_response
|
|
|
|
| 115 |
career_status = random.choice(occupations)
|
| 116 |
return {"status": career_status}
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
def generate_location() -> Dict[str, str]:
|
| 119 |
+
"""生成真实的地理位置信息。
|
|
|
|
| 120 |
|
| 121 |
+
使用 GeoNames 数据库随机选择一个国家和城市。
|
| 122 |
+
|
| 123 |
+
Returns:
|
| 124 |
+
Dict[str, str]: 包含以下字段的字典:
|
| 125 |
+
- country: 国家名称
|
| 126 |
+
- city: 城市名称
|
| 127 |
"""
|
| 128 |
gc = GeonamesCache()
|
| 129 |
|
| 130 |
+
# 获取所有国家
|
|
|
|
| 131 |
countries = gc.get_countries()
|
| 132 |
+
country_code = random.choice(list(countries.keys()))
|
| 133 |
+
country = countries[country_code]
|
| 134 |
|
| 135 |
+
# 获取选国家的所有城市
|
| 136 |
+
cities = gc.get_cities()
|
| 137 |
+
country_cities = [city for city in cities.values() if city['countrycode'] == country_code]
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
if not country_cities:
|
| 140 |
+
return {
|
| 141 |
+
"country": country['name'],
|
| 142 |
+
"city": "Unknown City"
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
# 随机选择一个城市
|
| 146 |
+
city_data = random.choice(country_cities)
|
| 147 |
+
|
| 148 |
+
return {
|
| 149 |
+
"country": country['name'],
|
| 150 |
+
"city": city_data['name']
|
| 151 |
+
}
|
| 152 |
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
|
| 155 |
def generate_gender() -> str:
|
|
|
|
| 197 |
]
|
| 198 |
|
| 199 |
try:
|
| 200 |
+
response = get_completion(messages, temperature=1.0)
|
| 201 |
|
| 202 |
# 使用config.py中的解析函数
|
| 203 |
result = parse_gpt_response(
|
|
|
|
| 267 |
]
|
| 268 |
|
| 269 |
try:
|
| 270 |
+
response = get_completion(messages, temperature=1.0)
|
| 271 |
|
| 272 |
# 使用config.py中的解析函数
|
| 273 |
result = parse_gpt_response(
|
|
|
|
| 351 |
]
|
| 352 |
|
| 353 |
try:
|
| 354 |
+
response = get_completion(messages, temperature=1.0)
|
| 355 |
|
| 356 |
# 解析JSON响应,只获取个人故事
|
| 357 |
result = parse_gpt_response(
|
|
|
|
| 425 |
]
|
| 426 |
|
| 427 |
try:
|
| 428 |
+
response = get_completion(messages, temperature=0.9)
|
| 429 |
|
| 430 |
# 使用config.py中的解析函数
|
| 431 |
from config import parse_gpt_response
|