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
- Returns
159
- -------
160
- Dict[str, str]
161
- - country : 始终为 "India"
162
- - city : 随机城市
 
163
  """
164
  gc = GeonamesCache()
165
 
166
- # ---- 固定国家为印度 ----
167
- country_code = "IN"
168
  countries = gc.get_countries()
169
- country = countries[country_code]
 
170
 
171
- # ---- 过滤出印度的所有城市 ----
172
- cities = gc.get_cities()
173
- in_cities_list = [
174
- city for city in cities.values()
175
- if city["countrycode"] == country_code
176
- ]
177
 
178
- # ---- 若意外无数据,兼底处理 ----
179
- if not in_cities_list:
180
- return {"country": country["name"], "city": "Mumbai"}
 
 
 
 
 
 
 
 
 
 
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=0.8)
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=0.8)
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=0.8)
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.2)
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