pycityagent 2.0.0a96__cp39-cp39-macosx_11_0_arm64.whl → 2.0.0a97__cp39-cp39-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,9 +13,10 @@ from pycityagent.llm import LLM
13
13
  from pycityagent.memory import Memory
14
14
  from pycityagent.workflow.block import Block
15
15
  from pycityagent.workflow.prompt import FormatPrompt
16
-
16
+ from .utils import clean_json_response
17
17
  from .dispatcher import BlockDispatcher
18
18
 
19
+
19
20
  logger = logging.getLogger("pycityagent")
20
21
 
21
22
 
@@ -166,10 +167,11 @@ class PlaceSelectionBlock(Block):
166
167
  )
167
168
  levelOneType = await self.llm.atext_request(self.typeSelectionPrompt.to_dialog(), response_format={"type": "json_object"}) # type: ignore
168
169
  try:
170
+ levelOneType = clean_json_response(levelOneType)
169
171
  levelOneType = json.loads(levelOneType)["place_type"]
170
172
  sub_category = poi_cate[levelOneType]
171
173
  except Exception as e:
172
- logger.warning(f"Wrong type of poi, raw response: {levelOneType}")
174
+ logger.warning(f"Level One Type Selection: wrong type of poi, raw response: {levelOneType}")
173
175
  levelOneType = random.choice(list(poi_cate.keys()))
174
176
  sub_category = poi_cate[levelOneType]
175
177
  self.secondTypeSelectionPrompt.format(
@@ -177,9 +179,10 @@ class PlaceSelectionBlock(Block):
177
179
  )
178
180
  levelTwoType = await self.llm.atext_request(self.secondTypeSelectionPrompt.to_dialog(), response_format={"type": "json_object"}) # type: ignore
179
181
  try:
182
+ levelTwoType = clean_json_response(levelTwoType)
180
183
  levelTwoType = json.loads(levelTwoType)["place_type"]
181
184
  except Exception as e:
182
- logger.warning(f"Wrong type of poi, raw response: {levelTwoType}")
185
+ logger.warning(f"Level Two Type Selection: wrong type of poi, raw response: {levelTwoType}")
183
186
  levelTwoType = random.choice(sub_category)
184
187
  center = await self.memory.status.get("position")
185
188
  center = (center["xy_position"]["x"], center["xy_position"]["y"])
@@ -260,19 +263,18 @@ class MoveBlock(Block):
260
263
  self.placeAnalysisPrompt = FormatPrompt(PLACE_ANALYSIS_PROMPT)
261
264
 
262
265
  async def forward(self, step, context):
263
- # 这里应该添加移动的具体逻辑
264
266
  agent_id = await self.memory.status.get("id")
265
267
  self.placeAnalysisPrompt.format(
266
268
  plan=context["plan"], intention=step["intention"]
267
269
  )
268
270
  response = await self.llm.atext_request(self.placeAnalysisPrompt.to_dialog(), response_format={"type": "json_object"}) # type: ignore
269
271
  try:
272
+ response = clean_json_response(response)
270
273
  response = json.loads(response)["place_type"]
271
274
  except Exception as e:
272
- logger.warning(f"Wrong type of poi, raw response: {response}")
275
+ logger.warning(f"Place Analysis: wrong type of place, raw response: {response}")
273
276
  response = "home"
274
277
  if response == "home":
275
- # 返回到家
276
278
  home = await self.memory.status.get("home")
277
279
  home = home["aoi_position"]["aoi_id"]
278
280
  nowPlace = await self.memory.status.get("position")
@@ -8,6 +8,7 @@ from pycityagent.llm import LLM
8
8
  from pycityagent.memory import Memory
9
9
  from pycityagent.workflow.block import Block
10
10
  from pycityagent.workflow.prompt import FormatPrompt
11
+ from .utils import clean_json_response
11
12
 
12
13
  logger = logging.getLogger("pycityagent")
13
14
 
@@ -126,7 +127,7 @@ class NeedsBlock(Block):
126
127
  now_time=await self.simulator.get_time(format_time=True),
127
128
  )
128
129
  response = await self.llm.atext_request(self.initial_prompt.to_dialog(), response_format={"type": "json_object"})
129
- response = self.clean_json_response(response)
130
+ response = clean_json_response(response)
130
131
  retry = 3
131
132
  while retry > 0:
132
133
  try:
@@ -309,7 +310,7 @@ class NeedsBlock(Block):
309
310
  while retry > 0:
310
311
  response = await self.llm.atext_request(self.evaluation_prompt.to_dialog(), response_format={"type": "json_object"})
311
312
  try:
312
- new_satisfaction = json.loads(self.clean_json_response(response)) # type: ignore
313
+ new_satisfaction = json.loads(clean_json_response(response)) # type: ignore
313
314
  # 更新所有需求的数值
314
315
  for need_type, new_value in new_satisfaction.items():
315
316
  if need_type in [
@@ -330,11 +331,6 @@ class NeedsBlock(Block):
330
331
  logger.warning(f"Original response: {response}")
331
332
  retry -= 1
332
333
 
333
- def clean_json_response(self, response: str) -> str:
334
- """清理LLM响应中的特殊字符"""
335
- response = response.replace("```json", "").replace("```", "")
336
- return response.strip()
337
-
338
334
  async def forward(self):
339
335
  await self.initialize()
340
336
 
@@ -10,7 +10,7 @@ from pycityagent.llm import LLM
10
10
  from pycityagent.memory import Memory
11
11
  from pycityagent.workflow import Block
12
12
  from pycityagent.workflow.prompt import FormatPrompt
13
-
13
+ from .utils import clean_json_response
14
14
  logger = logging.getLogger("pycityagent")
15
15
 
16
16
  GUIDANCE_SELECTION_PROMPT = """As an intelligent agent's decision system, please select the most suitable option from the following choices to satisfy the current need.
@@ -203,7 +203,7 @@ class PlanBlock(Block):
203
203
  retry = 3
204
204
  while retry > 0:
205
205
  try:
206
- result = json.loads(self.clean_json_response(response)) # type: ignore
206
+ result = json.loads(clean_json_response(response)) # type: ignore
207
207
  if "selected_option" not in result or "evaluation" not in result:
208
208
  raise ValueError("Invalid guidance selection format")
209
209
  if (
@@ -255,7 +255,7 @@ class PlanBlock(Block):
255
255
  retry = 3
256
256
  while retry > 0:
257
257
  try:
258
- result = json.loads(self.clean_json_response(response)) # type: ignore
258
+ result = json.loads(clean_json_response(response)) # type: ignore
259
259
  if (
260
260
  "plan" not in result
261
261
  or "target" not in result["plan"]
@@ -316,8 +316,3 @@ Execution Steps: \n{formated_steps}
316
316
  "current_step", steps[0] if steps else {"intention": "", "type": ""}
317
317
  )
318
318
  await self.memory.status.update("execution_context", {"plan": formated_plan})
319
-
320
- def clean_json_response(self, response: str) -> str:
321
- """Clean special characters in LLM response"""
322
- response = response.replace("```json", "").replace("```", "")
323
- return response.strip()
@@ -57,6 +57,6 @@ def extract_dict_from_string(input_string):
57
57
 
58
58
 
59
59
  def clean_json_response(response: str) -> str:
60
- """清理LLM响应中的特殊字符"""
60
+ """remove the special characters in the response"""
61
61
  response = response.replace("```json", "").replace("```", "")
62
- return response.strip()
62
+ return response.strip()
@@ -374,7 +374,7 @@ class AgentSimulation:
374
374
  await simulation.pause_simulator()
375
375
  elif step.type == WorkflowType.RESUME:
376
376
  await simulation.resume_simulator()
377
- elif step.type == WorkflowType.FUNCTION:
377
+ else:
378
378
  _func = cast(Callable, step.func)
379
379
  await _func(simulation)
380
380
  logger.info("Simulation finished")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pycityagent
3
- Version: 2.0.0a96
3
+ Version: 2.0.0a97
4
4
  Summary: LLM-based city environment agent building library
5
5
  Author-email: Yuwei Yan <pinkgranite86@gmail.com>, Junbo Yan <yanjb20thu@gmali.com>, Jun Zhang <zhangjun990222@gmali.com>
6
6
  License: MIT License
@@ -1,3 +1,9 @@
1
+ pycityagent-2.0.0a97.dist-info/RECORD,,
2
+ pycityagent-2.0.0a97.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
3
+ pycityagent-2.0.0a97.dist-info/WHEEL,sha256=md3JO_ifs5j508p3TDNMgtQVtnQblpGEt_Wo4W56l8Y,107
4
+ pycityagent-2.0.0a97.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
5
+ pycityagent-2.0.0a97.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
6
+ pycityagent-2.0.0a97.dist-info/METADATA,sha256=M8Yf50T1rDcPjB8_SoCuFSONew2E-mMI-D-Y2aomCbo,8657
1
7
  pycityagent/pycityagent-sim,sha256=_xsIrY1raLYagebaymahAZc2YSustRmQM2jm1B4p27U,36972738
2
8
  pycityagent/__init__.py,sha256=PUKWTXc-xdMG7px8oTNclodsILUgypANj2Z647sY63k,808
3
9
  pycityagent/pycityagent-ui,sha256=Ur95yZygIaZ5l_CDqP9394M5GQ66iV5PkcNPYFWqzvk,41225346
@@ -18,7 +24,7 @@ pycityagent/memory/utils.py,sha256=oJWLdPeJy_jcdKcDTo9JAH9kDZhqjoQhhv_zT9qWC0w,8
18
24
  pycityagent/memory/const.py,sha256=Wgsx0oztDrJDEpI9Dr6XeI6GXrABcP0UTOuEvMp1AD8,934
19
25
  pycityagent/memory/faiss_query.py,sha256=KPeyzIjD0dzkxr-TlOeCiIlkdh1WAyyipCAXUEt97Lk,17350
20
26
  pycityagent/memory/state.py,sha256=JFCBuK1AS-HqscvdGS9ATF9AUU8t29_2leDY_6iO2_4,5158
21
- pycityagent/simulation/simulation.py,sha256=GrD5VWaEvrKrBFwhEKUUfQfk2rweTEZnROaBZJXSni0,47134
27
+ pycityagent/simulation/simulation.py,sha256=YPRzB7wCL-K85W3hgvBWukefyEgZXZCi4egH6rZa6XA,47099
22
28
  pycityagent/simulation/__init__.py,sha256=u1WpgwVxPboXWMxrUQKMXJNmTKQYAeCaqZv9HmSxESY,118
23
29
  pycityagent/simulation/agentgroup.py,sha256=DYx68TckA5ox9x_GHID-3Gg19qABY-NR9QAO2BKKfMc,36814
24
30
  pycityagent/simulation/storage/pg.py,sha256=xRshSOGttW-p0re0fNBOjOpb-nQ5msIE2LsdT79_E_Y,8425
@@ -81,21 +87,15 @@ pycityagent/cityagent/societyagent.py,sha256=z1i7yPRz7Uupw5oGpMlFwyDi-8R4wHSCjgh
81
87
  pycityagent/cityagent/message_intercept.py,sha256=Am0u-hGFOBcvcNXE_WJos5iwh2QoJLihdSIz3sr_U9Y,4439
82
88
  pycityagent/cityagent/governmentagent.py,sha256=P3ufIfM5ldh2KC9y_y1ONowsV3FsFF5LWe0iQ3MVmgA,3067
83
89
  pycityagent/cityagent/blocks/dispatcher.py,sha256=gd3lyggvtkCq9Ou_icgua60H0UjHTzwHoynLl_iZoes,2939
84
- pycityagent/cityagent/blocks/needs_block.py,sha256=PDReR1GjF3qafR06Wfw_mizzBZ6xRQRq6KqgA9r8WOA,15321
90
+ pycityagent/cityagent/blocks/needs_block.py,sha256=1Mnr2vStBxSbmh2WByJdefOvTToKOENYDhyZFuL0KiM,15142
85
91
  pycityagent/cityagent/blocks/cognition_block.py,sha256=vy7wEvK72-sOieSSWidIXd5nKPLR-4f-ZYL7gyvje-0,15552
86
92
  pycityagent/cityagent/blocks/social_block.py,sha256=C1zMcN3RZBYewqw0MEYgtTf5Jzsol1Up3Ew9ovTSm1Y,15169
87
93
  pycityagent/cityagent/blocks/__init__.py,sha256=Tmy1CyQ8s3Iltp4xYWNg73Y28UWQv_LNWgMzgzquQT0,420
88
94
  pycityagent/cityagent/blocks/economy_block.py,sha256=w1rbTb4CqqXD9BDQuOAtCmrJ4KJjJYiQ5hJHEmCs6CA,20924
89
- pycityagent/cityagent/blocks/utils.py,sha256=YQkthaMkSCnT-1yfOkioGDvi2c-NLc5B-08BBlW4z0k,1781
95
+ pycityagent/cityagent/blocks/utils.py,sha256=dNIQGv7Br3hWOFznW1JRrFVeGw2vn3QRiPq732we5kQ,1792
90
96
  pycityagent/cityagent/blocks/other_block.py,sha256=-H2umOQ-l7_9SjP-SHu7J4oHDh4V-r649_4kGS9Qrng,4447
91
- pycityagent/cityagent/blocks/plan_block.py,sha256=-3ww7WPzEoDHXJp_WRudllL9GphAQw_-nR426OUEiGY,11897
92
- pycityagent/cityagent/blocks/mobility_block.py,sha256=rrWzJO6mCMxUFfl1txOqq9BY7FmQ3LE3-Kr0d-4jnCc,16669
97
+ pycityagent/cityagent/blocks/plan_block.py,sha256=3TfXg6Iqa9Z_fh22KV2ZLNffNFglIV22vgCfGmorNe4,11710
98
+ pycityagent/cityagent/blocks/mobility_block.py,sha256=bUoExMdxlMzbnWHe1hx6bkR2Jjc1CZglux8RAXrWaRE,16876
93
99
  pycityagent/survey/models.py,sha256=g3xni4GcA1Py3vlGt6z4ltutjgQ4G0uINYAM8vKRJAw,5225
94
100
  pycityagent/survey/__init__.py,sha256=rxwou8U9KeFSP7rMzXtmtp2fVFZxK4Trzi-psx9LPIs,153
95
101
  pycityagent/survey/manager.py,sha256=QZEApC6tKe-g1waDa_O4Eg4CFkyL8KWa7tUGZnT_7WI,3397
96
- pycityagent-2.0.0a96.dist-info/RECORD,,
97
- pycityagent-2.0.0a96.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
98
- pycityagent-2.0.0a96.dist-info/WHEEL,sha256=md3JO_ifs5j508p3TDNMgtQVtnQblpGEt_Wo4W56l8Y,107
99
- pycityagent-2.0.0a96.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
100
- pycityagent-2.0.0a96.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
101
- pycityagent-2.0.0a96.dist-info/METADATA,sha256=DAlWpG0FCdi2l-ae2kPICBXklMtezwsG1H_lFKHpi2E,8657