pycityagent 1.1.5__py3-none-any.whl → 1.1.7__py3-none-any.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.
- pycityagent/__init__.py +4 -0
- pycityagent/ac/ac.py +2 -0
- pycityagent/ac/action.py +7 -0
- pycityagent/ac/hub_actions.py +2 -0
- pycityagent/ac/sim_actions.py +2 -0
- pycityagent/agent.py +41 -25
- pycityagent/agent_citizen.py +40 -28
- pycityagent/agent_func.py +30 -9
- pycityagent/brain/__init__.py +1 -1
- pycityagent/brain/brain.py +3 -2
- pycityagent/brain/brainfc.py +1 -0
- pycityagent/brain/memory.py +4 -0
- pycityagent/brain/scheduler.py +3 -0
- pycityagent/brain/sence.py +15 -11
- pycityagent/brain/static.py +1 -1
- pycityagent/cc/cc.py +2 -0
- pycityagent/hubconnector/__init__.py +2 -0
- pycityagent/hubconnector/hubconnector.py +2 -0
- pycityagent/image/__init__.py +2 -0
- pycityagent/image/image.py +4 -0
- pycityagent/simulator.py +40 -9
- pycityagent/st/__init__.py +1 -1
- pycityagent/st/st.py +2 -0
- pycityagent/urbanllm/__init__.py +2 -0
- pycityagent/urbanllm/urbanllm.py +2 -0
- {pycityagent-1.1.5.dist-info → pycityagent-1.1.7.dist-info}/METADATA +1 -1
- pycityagent-1.1.7.dist-info/RECORD +53 -0
- pycityagent/ac/controled.py +0 -13
- pycityagent/ac/converse.py +0 -31
- pycityagent/ac/idle.py +0 -17
- pycityagent/ac/shop.py +0 -80
- pycityagent/ac/trip.py +0 -37
- pycityagent-1.1.5.dist-info/RECORD +0 -58
- {pycityagent-1.1.5.dist-info → pycityagent-1.1.7.dist-info}/LICENSE +0 -0
- {pycityagent-1.1.5.dist-info → pycityagent-1.1.7.dist-info}/WHEEL +0 -0
- {pycityagent-1.1.5.dist-info → pycityagent-1.1.7.dist-info}/top_level.txt +0 -0
pycityagent/__init__.py
CHANGED
pycityagent/ac/ac.py
CHANGED
pycityagent/ac/action.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
"""Action类及其定义"""
|
2
|
+
|
1
3
|
from abc import ABC, abstractclassmethod
|
2
4
|
from typing import Callable, Any
|
3
5
|
|
@@ -15,6 +17,9 @@ class ActionType:
|
|
15
17
|
Hub = 2
|
16
18
|
Comp = 3
|
17
19
|
class Action:
|
20
|
+
"""
|
21
|
+
- Action
|
22
|
+
"""
|
18
23
|
def __init__(self, agent, type:ActionType, source: str = None, before:Callable[[list], Any] = None) -> None:
|
19
24
|
'''
|
20
25
|
默认初始化
|
@@ -47,9 +52,11 @@ class Action:
|
|
47
52
|
'''接口函数'''
|
48
53
|
|
49
54
|
class SimAction(Action):
|
55
|
+
"""SimAction: 模拟器关联Action"""
|
50
56
|
def __init__(self, agent, source: str = None, before: Callable[[list], Any] = None) -> None:
|
51
57
|
super().__init__(agent, ActionType.Sim, source, before)
|
52
58
|
|
53
59
|
class HubAction(Action):
|
60
|
+
"""HubAction: Apphub关联Action"""
|
54
61
|
def __init__(self, agent, source: str = None, before: Callable[[list], Any] = None) -> None:
|
55
62
|
super().__init__(agent, ActionType.Hub, source, before)
|
pycityagent/ac/hub_actions.py
CHANGED
pycityagent/ac/sim_actions.py
CHANGED
pycityagent/agent.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
"""智能体模板类及其定义"""
|
2
|
+
|
1
3
|
from abc import ABC, abstractmethod
|
2
4
|
from typing import Optional, Union, Callable
|
3
5
|
import PIL.Image as Image
|
@@ -26,7 +28,8 @@ class AgentType:
|
|
26
28
|
|
27
29
|
class Template:
|
28
30
|
"""
|
29
|
-
|
31
|
+
- 模板基类
|
32
|
+
- The basic template class
|
30
33
|
"""
|
31
34
|
def __init__(self, name, server, type:AgentType, soul:UrbanLLM=None, simulator=None) -> None:
|
32
35
|
self._name = name
|
@@ -61,7 +64,8 @@ class Template:
|
|
61
64
|
|
62
65
|
class Agent(Template):
|
63
66
|
"""
|
64
|
-
|
67
|
+
- 智能体基类
|
68
|
+
- Agent base class
|
65
69
|
"""
|
66
70
|
def __init__(
|
67
71
|
self,
|
@@ -71,41 +75,51 @@ class Agent(Template):
|
|
71
75
|
soul:UrbanLLM=None,
|
72
76
|
simulator=None
|
73
77
|
) -> None:
|
78
|
+
"""
|
79
|
+
初始化 Init
|
80
|
+
|
81
|
+
Args:
|
82
|
+
- name (str): 智能体名称; name of your agent
|
83
|
+
- server (str): 模拟器grpc服务地址; server address of simulator
|
84
|
+
- type (AgentType): 智能体类型; type of agent
|
85
|
+
- soul (UrbanLLM): 基础模型模块; base model
|
86
|
+
- simulator (Simulator): 模拟器对象; simulator
|
87
|
+
"""
|
74
88
|
super().__init__(name, server, type, soul, simulator)
|
75
89
|
|
76
90
|
self._hub_connector = None
|
77
91
|
"""
|
78
|
-
HubConnector: 用于和AppHub对接——可以通过Agent.connectToHub进行绑定
|
79
|
-
HubConnector: the connection between agent and AppHub, you can use 'Agent.connectToHub' to create the connection
|
92
|
+
- HubConnector: 用于和AppHub对接——可以通过Agent.connectToHub进行绑定
|
93
|
+
- HubConnector: the connection between agent and AppHub, you can use 'Agent.connectToHub' to create the connection
|
80
94
|
"""
|
81
95
|
|
82
96
|
self._brain = Brain(self)
|
83
97
|
"""
|
84
|
-
Agent的大脑
|
85
|
-
The Agent's Brain
|
98
|
+
- Agent的大脑
|
99
|
+
- The Agent's Brain
|
86
100
|
"""
|
87
101
|
|
88
102
|
self._cc = CommandController(self)
|
89
103
|
"""
|
90
|
-
Agent的命令控制器
|
91
|
-
The Agent's CommondController
|
104
|
+
- Agent的命令控制器
|
105
|
+
- The Agent's CommondController
|
92
106
|
"""
|
93
107
|
|
94
108
|
self._st = StateTransformer()
|
95
109
|
"""
|
96
|
-
与Agent关联的状态转移器
|
97
|
-
The related StateTransformer
|
110
|
+
- 与Agent关联的状态转移器
|
111
|
+
- The related StateTransformer
|
98
112
|
"""
|
99
113
|
|
100
114
|
self._ac = ActionController(self)
|
101
115
|
"""
|
102
|
-
Agent的行为控制器
|
103
|
-
The Agent's ActionController
|
116
|
+
- Agent的行为控制器
|
117
|
+
- The Agent's ActionController
|
104
118
|
"""
|
105
119
|
|
106
120
|
self._step_with_action = True
|
107
121
|
"""
|
108
|
-
Step函数是否包含action执行 —— 当有自定义action需求(特指包含没有指定source的Action)时可置该选项为False并通过自定义方法执行action操作
|
122
|
+
- Step函数是否包含action执行 —— 当有自定义action需求(特指包含没有指定source的Action)时可置该选项为False并通过自定义方法执行action操作
|
109
123
|
"""
|
110
124
|
|
111
125
|
def ConnectToHub(self, config:dict):
|
@@ -154,36 +168,36 @@ class Agent(Template):
|
|
154
168
|
|
155
169
|
def enable_streetview(self):
|
156
170
|
"""
|
157
|
-
开启街景相关功能
|
158
|
-
Enable Streetview function
|
171
|
+
- 开启街景相关功能
|
172
|
+
- Enable Streetview function
|
159
173
|
"""
|
160
174
|
self._brain.Sence.enable_streeview = True
|
161
175
|
|
162
176
|
def disable_streetview(self):
|
163
177
|
"""
|
164
|
-
关闭街景相关功能
|
165
|
-
Disable Streetview function
|
178
|
+
- 关闭街景相关功能
|
179
|
+
- Disable Streetview function
|
166
180
|
"""
|
167
181
|
self._brain.Sence.enable_streeview = False
|
168
182
|
|
169
183
|
def enable_user_interaction(self):
|
170
184
|
"""
|
171
|
-
开启用户交互功能(即在OpenCity控制台中与Agent进行交互)
|
172
|
-
Enable User Interaction function. The User Interaction function is the ability to interact with the related agent in OpenCity website console.
|
185
|
+
- 开启用户交互功能(即在OpenCity控制台中与Agent进行交互)
|
186
|
+
- Enable User Interaction function. The User Interaction function is the ability to interact with the related agent in OpenCity website console.
|
173
187
|
"""
|
174
188
|
self._brain.Memory.Working.enable_user_interaction = True
|
175
189
|
|
176
190
|
def disable_user_interaction(self):
|
177
191
|
"""
|
178
|
-
关闭用户交互功能
|
179
|
-
Disable User Interaction function
|
192
|
+
- 关闭用户交互功能
|
193
|
+
- Disable User Interaction function
|
180
194
|
"""
|
181
195
|
self._brain.Memory.Working.enable_user_interaction = False
|
182
196
|
|
183
197
|
def set_step_with_action(self, flag:bool = None):
|
184
198
|
"""
|
185
|
-
默认情况置反step_with_action属性: 即True->False, False->True
|
186
|
-
否则根据传入的flag进行设置
|
199
|
+
- 默认情况置反step_with_action属性: 即True->False, False->True
|
200
|
+
- 否则根据传入的flag进行设置
|
187
201
|
"""
|
188
202
|
if flag != None:
|
189
203
|
self._step_with_action = flag
|
@@ -191,12 +205,13 @@ class Agent(Template):
|
|
191
205
|
self._step_with_action = not self._step_with_action
|
192
206
|
|
193
207
|
|
194
|
-
def sence_config(self, sence_content:Optional[list]=None, sence_radius:int=None):
|
208
|
+
def sence_config(self, sence_content:Optional[list[str]]=None, sence_radius:int=None):
|
195
209
|
'''
|
196
210
|
感知配置
|
211
|
+
Sence config
|
197
212
|
|
198
213
|
Args:
|
199
|
-
-
|
214
|
+
- sence_content: 配置选项——包含需要感知的数据类型
|
200
215
|
- time: 时间
|
201
216
|
- poi: 感兴趣地点
|
202
217
|
- position: 可达地点
|
@@ -205,6 +220,7 @@ class Agent(Template):
|
|
205
220
|
- streetview: 街景
|
206
221
|
- user_message: 用户交互信息
|
207
222
|
- agent_message: 智能体交互信息
|
223
|
+
- sence_radius (int): 感知半径(m); sence radius
|
208
224
|
'''
|
209
225
|
if sence_content != None:
|
210
226
|
self._brain._sence.set_sence(sence_content)
|
pycityagent/agent_citizen.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
"""CitizenAgent: 城市居民智能体类及其定义"""
|
2
|
+
|
1
3
|
from pycityagent.urbanllm import UrbanLLM
|
2
4
|
from .urbanllm import UrbanLLM
|
3
5
|
from .agent import Agent, AgentType
|
@@ -5,8 +7,8 @@ from .image.image import CitizenImage
|
|
5
7
|
|
6
8
|
class CitizenAgent(Agent):
|
7
9
|
"""
|
8
|
-
Citizen Agent
|
9
|
-
城市居民智能体
|
10
|
+
- Citizen Agent
|
11
|
+
- 城市居民智能体
|
10
12
|
"""
|
11
13
|
|
12
14
|
def __init__(
|
@@ -21,34 +23,41 @@ class CitizenAgent(Agent):
|
|
21
23
|
) -> None:
|
22
24
|
super().__init__(name, server, AgentType.Citizen, soul, simulator)
|
23
25
|
self._id = id
|
26
|
+
"""
|
27
|
+
- 智能体ID
|
28
|
+
- Agent's id
|
29
|
+
"""
|
30
|
+
|
24
31
|
self.base = base
|
25
32
|
"""
|
26
|
-
Agent/Person的基本属性, Agent指被代理的Person, Person指模拟器中的背景人
|
27
|
-
The base attributes of Agent/Person. Agent is the Person being represented. Persons are background persons in simulator
|
33
|
+
- Agent/Person的基本属性, Agent指被代理的Person, Person指模拟器中的背景人
|
34
|
+
- The base attributes of Agent/Person. Agent is the Person being represented. Persons are background persons in simulator
|
28
35
|
- https://cityproto.sim.fiblab.net/#city.agent.v2.Agent
|
29
36
|
"""
|
37
|
+
|
30
38
|
self.motion = motion
|
31
39
|
"""
|
32
|
-
Agent/Person的运动信息
|
33
|
-
The motion information of Agent/Person
|
40
|
+
- Agent/Person的运动信息
|
41
|
+
- The motion information of Agent/Person
|
34
42
|
- https://cityproto.sim.fiblab.net/#city.agent.v2.AgentMotion
|
35
43
|
"""
|
36
44
|
|
37
45
|
self._image = CitizenImage(self)
|
38
46
|
"""
|
39
|
-
Agent画像
|
40
|
-
The Agent's Image
|
47
|
+
- Agent画像
|
48
|
+
- The Agent's Image
|
41
49
|
"""
|
42
50
|
|
43
51
|
self.Scheduler.schedule_init()
|
44
52
|
"""
|
45
|
-
行程初始化
|
53
|
+
- 行程初始化
|
54
|
+
- Schedule Init
|
46
55
|
"""
|
47
56
|
|
48
57
|
def Bind(self):
|
49
58
|
"""
|
50
|
-
将智能体绑定到AppHub
|
51
|
-
Bind Agent with AppHub
|
59
|
+
- 将智能体绑定到AppHub
|
60
|
+
- Bind Agent with AppHub
|
52
61
|
"""
|
53
62
|
if self._hub_connector == None:
|
54
63
|
print("ERROR: connect with apphub first")
|
@@ -58,37 +67,36 @@ class CitizenAgent(Agent):
|
|
58
67
|
|
59
68
|
def enable_economy_behavior(self):
|
60
69
|
"""
|
61
|
-
开启经济模拟相关功能(例如购物)
|
62
|
-
Enable Economy function. Shopping for instance.
|
70
|
+
- 开启经济模拟相关功能(例如购物)
|
71
|
+
- Enable Economy function. Shopping for instance.
|
63
72
|
"""
|
64
73
|
self.Brain.Memory.Working.enable_economy = True
|
65
74
|
|
66
75
|
def disable_economy_behavior(self):
|
67
76
|
"""
|
68
|
-
关闭经济模拟相关功能
|
69
|
-
Disable Economy function
|
77
|
+
- 关闭经济模拟相关功能
|
78
|
+
- Disable Economy function
|
70
79
|
"""
|
71
80
|
self.Brain.Memory.Working.enable_economy = False
|
72
81
|
|
73
82
|
def enable_social_behavior(self):
|
74
83
|
"""
|
75
|
-
开启社交相关功能
|
76
|
-
Enable Social function
|
84
|
+
- 开启社交相关功能
|
85
|
+
- Enable Social function
|
77
86
|
"""
|
78
87
|
self.Brain.Memory.Working.enable_social = True
|
79
88
|
|
80
89
|
def diable_social_behavior(self):
|
81
90
|
"""
|
82
|
-
关闭社交相关功能
|
83
|
-
Disable Social function
|
91
|
+
- 关闭社交相关功能
|
92
|
+
- Disable Social function
|
84
93
|
"""
|
85
94
|
self.Brain.Memory.Working.enable_social = False
|
86
95
|
|
87
96
|
async def Pause(self):
|
88
97
|
"""
|
89
|
-
暂停Agent行为使Agent进入'pause'状态
|
90
|
-
Pause the Agent, making the agent 'pause'
|
91
|
-
|
98
|
+
- 暂停Agent行为使Agent进入'pause'状态
|
99
|
+
- Pause the Agent, making the agent 'pause'
|
92
100
|
"""
|
93
101
|
req = {'person_id': self.base['id'], 'schedules': []}
|
94
102
|
await self._client.person_service.SetSchedule(req)
|
@@ -97,8 +105,8 @@ class CitizenAgent(Agent):
|
|
97
105
|
|
98
106
|
async def Active(self):
|
99
107
|
"""
|
100
|
-
恢复Agent行为
|
101
|
-
Recover from 'pause'
|
108
|
+
- 恢复Agent行为
|
109
|
+
- Recover from 'pause'
|
102
110
|
"""
|
103
111
|
self._st.pause_back()
|
104
112
|
|
@@ -133,8 +141,8 @@ class CitizenAgent(Agent):
|
|
133
141
|
|
134
142
|
def show_yourself(self):
|
135
143
|
"""
|
136
|
-
Log信息输出
|
137
|
-
Pring log message
|
144
|
+
- Log信息输出
|
145
|
+
- Pring log message
|
138
146
|
"""
|
139
147
|
print(f"【State Message】: {self.state}")
|
140
148
|
motion_message = ''''''
|
@@ -149,10 +157,14 @@ class CitizenAgent(Agent):
|
|
149
157
|
|
150
158
|
@property
|
151
159
|
def Image(self):
|
152
|
-
"""
|
160
|
+
"""
|
161
|
+
- The Agent's Image
|
162
|
+
"""
|
153
163
|
return self._image
|
154
164
|
|
155
165
|
@property
|
156
166
|
def Scheduler(self):
|
157
|
-
"""
|
167
|
+
"""
|
168
|
+
- The Agent's Scheduler
|
169
|
+
"""
|
158
170
|
return self._brain.Memory.Working.scheduler
|
pycityagent/agent_func.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
"""FuncAgent: 功能性智能体及其定义"""
|
2
|
+
|
1
3
|
from pycityagent.urbanllm import UrbanLLM
|
2
4
|
from .urbanllm import UrbanLLM
|
3
5
|
from .agent import Agent, AgentType
|
@@ -18,16 +20,33 @@ class FuncAgent(Agent):
|
|
18
20
|
soul:UrbanLLM=None,
|
19
21
|
simulator=None,
|
20
22
|
) -> None:
|
23
|
+
"""
|
24
|
+
初始化 Init
|
25
|
+
|
26
|
+
Args:
|
27
|
+
- name (str): 智能体名称; name of your agent
|
28
|
+
- id (int): 智能体Id; id of your agent
|
29
|
+
- server (str): 模拟器grpc服务地址; server address of simulator
|
30
|
+
- soul (UrbanLLM): 基础模型模块; base model
|
31
|
+
- simulator (Simulator): 模拟器对象; simulator
|
32
|
+
"""
|
33
|
+
|
21
34
|
super().__init__(name, server, AgentType.Func, soul, simulator)
|
22
35
|
self._id = id
|
36
|
+
"""
|
37
|
+
- 智能体Id
|
38
|
+
- Agent's id
|
39
|
+
"""
|
40
|
+
|
23
41
|
self._image = Image(self)
|
24
42
|
"""
|
25
|
-
Func Agent画像——支持自定义内容
|
43
|
+
- Func Agent画像——支持自定义内容
|
26
44
|
"""
|
27
45
|
|
28
46
|
self.motion = {'id': id, 'position': {}, 'direction': 0}
|
29
47
|
"""
|
30
48
|
Func Agent状态信息——与agent的sence高度相关
|
49
|
+
Keys:
|
31
50
|
- id (int): 即agent id
|
32
51
|
- position (https://cityproto.sim.fiblab.net/#city.geo.v2.Position): 即agent当前的位置描述信息
|
33
52
|
- lane_position (dict): 当position中包含该key时表示agent当前位于lane上——与aoi_position不可同时存在
|
@@ -49,8 +68,8 @@ class FuncAgent(Agent):
|
|
49
68
|
|
50
69
|
async def init_position_aoi(self, aoi_id:int):
|
51
70
|
"""
|
52
|
-
将agent的位置初始化到指定aoi
|
53
|
-
根据指定aoi设置aoi_position, longlat_position以及xy_position
|
71
|
+
- 将agent的位置初始化到指定aoi
|
72
|
+
- 根据指定aoi设置aoi_position, longlat_position以及xy_position
|
54
73
|
"""
|
55
74
|
if aoi_id in self._simulator.map.aois:
|
56
75
|
aoi = self._simulator.map.aois[aoi_id]
|
@@ -64,8 +83,8 @@ class FuncAgent(Agent):
|
|
64
83
|
|
65
84
|
def Bind(self):
|
66
85
|
"""
|
67
|
-
将智能体绑定到AppHub
|
68
|
-
Bind the Agent with AppHub
|
86
|
+
- 将智能体绑定到AppHub
|
87
|
+
- Bind the Agent with AppHub
|
69
88
|
"""
|
70
89
|
if self._hub_connector == None:
|
71
90
|
print("ERROR: connect with apphub first")
|
@@ -74,7 +93,7 @@ class FuncAgent(Agent):
|
|
74
93
|
|
75
94
|
def set_image(self, image: Image):
|
76
95
|
"""
|
77
|
-
设置image——支持自由扩展Image
|
96
|
+
- 设置image——支持自由扩展Image
|
78
97
|
"""
|
79
98
|
self._image = image
|
80
99
|
|
@@ -104,12 +123,14 @@ class FuncAgent(Agent):
|
|
104
123
|
|
105
124
|
def show_yourself(self):
|
106
125
|
"""
|
107
|
-
Log信息输出
|
108
|
-
Pring log message
|
126
|
+
- Log信息输出
|
127
|
+
- Pring log message
|
109
128
|
"""
|
110
129
|
pass
|
111
130
|
|
112
131
|
@property
|
113
132
|
def Image(self):
|
114
|
-
"""
|
133
|
+
"""
|
134
|
+
- The Agent's Image
|
135
|
+
"""
|
115
136
|
return self._image
|
pycityagent/brain/__init__.py
CHANGED
pycityagent/brain/brain.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
"""大脑类"""
|
1
2
|
from abc import ABC, abstractmethod
|
2
3
|
from typing import Optional
|
3
4
|
from .scheduler import Scheduler
|
@@ -6,8 +7,8 @@ from .memory import MemoryController
|
|
6
7
|
|
7
8
|
class Brain:
|
8
9
|
"""
|
9
|
-
|
10
|
-
Brain
|
10
|
+
大脑类
|
11
|
+
Brain Class
|
11
12
|
"""
|
12
13
|
def __init__(self, agent) -> None:
|
13
14
|
self._agent = agent
|
pycityagent/brain/brainfc.py
CHANGED
pycityagent/brain/memory.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
"""记忆相关类与定义"""
|
2
|
+
|
1
3
|
from typing import Any, Optional
|
2
4
|
from abc import ABC, abstractmethod
|
3
5
|
from enum import Enum
|
@@ -61,10 +63,12 @@ class Memory(BrainFunction):
|
|
61
63
|
"""
|
62
64
|
|
63
65
|
class WMemory(Memory):
|
66
|
+
"""WMemory: Working Memory工作记忆类"""
|
64
67
|
def __init__(self, agent) -> None:
|
65
68
|
super().__init__(agent, MemoryType.WM)
|
66
69
|
|
67
70
|
class LTMemory(Memory):
|
71
|
+
"""LTMemory: Long-Term Memory长时记忆类"""
|
68
72
|
def __init__(self, agent) -> None:
|
69
73
|
super().__init__(agent, MemoryType.LTM)
|
70
74
|
|
pycityagent/brain/scheduler.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
"""规划器相关类及定义"""
|
2
|
+
|
1
3
|
from enum import Enum
|
2
4
|
import random
|
3
5
|
import time as Time
|
@@ -21,6 +23,7 @@ class ScheduleType(Enum):
|
|
21
23
|
OTHER = 3
|
22
24
|
|
23
25
|
class Schedule:
|
26
|
+
"""Schedule基类——为多种Schedule提供基础模板"""
|
24
27
|
def __init__(self, type) -> None:
|
25
28
|
'''默认初始化'''
|
26
29
|
self.type = type
|
pycityagent/brain/sence.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
"""大脑感知相关类及其定义"""
|
2
|
+
|
1
3
|
from typing import Optional, Union
|
2
4
|
from datetime import datetime
|
3
5
|
import math
|
@@ -58,7 +60,7 @@ def get_xy_in_lane(nodes, distance, direction:str='front'):
|
|
58
60
|
# 顺道路方向前进
|
59
61
|
if distance == 0:
|
60
62
|
return [nodes[0]['x'], nodes[0]['y']]
|
61
|
-
key_index = 0
|
63
|
+
key_index = 0 # first node
|
62
64
|
for i in range(1, len(nodes)):
|
63
65
|
x1, y1 = nodes[i-1]['x'], nodes[i-1]['y']
|
64
66
|
x2, y2 = nodes[i]['x'], nodes[i]['y']
|
@@ -68,12 +70,14 @@ def get_xy_in_lane(nodes, distance, direction:str='front'):
|
|
68
70
|
break;
|
69
71
|
key_index += 1
|
70
72
|
if remain_s < 0.5:
|
71
|
-
return [nodes[
|
73
|
+
return [nodes[key_index]['x'], nodes[key_index]['y']]
|
72
74
|
longlat = point_on_line_given_distance(nodes[key_index], nodes[key_index+1], remain_s)
|
73
75
|
return longlat
|
74
76
|
else:
|
75
77
|
# 逆道路方向前进
|
76
|
-
|
78
|
+
if distance == 0:
|
79
|
+
return [nodes[-1]['x'], nodes[-1]['y']]
|
80
|
+
key_index = len(nodes)-1 # last node
|
77
81
|
for i in range(len(nodes)-1, 0, -1):
|
78
82
|
x1, y1 = nodes[i]['x'], nodes[i]['y']
|
79
83
|
x2, y2 = nodes[i-1]['x'], nodes[i-1]['y']
|
@@ -83,7 +87,7 @@ def get_xy_in_lane(nodes, distance, direction:str='front'):
|
|
83
87
|
break;
|
84
88
|
key_index -= 1
|
85
89
|
if remain_s < 0.5:
|
86
|
-
return [nodes[
|
90
|
+
return [nodes[key_index]['x'], nodes[key_index]['y']]
|
87
91
|
longlat = point_on_line_given_distance(nodes[key_index], nodes[key_index-1], remain_s)
|
88
92
|
return longlat
|
89
93
|
|
@@ -335,7 +339,7 @@ class Sence(BrainFunction):
|
|
335
339
|
else:
|
336
340
|
# agent in lane
|
337
341
|
lane_id = self._agent.motion['position']['lane_position']['lane_id'] # 所在lane_id
|
338
|
-
lane = copy.deepcopy(self.
|
342
|
+
lane = copy.deepcopy(self._agent._simulator.map.get_lane(lane_id)) # 获取lane信息
|
339
343
|
agent_s = self._agent.motion['position']['lane_position']['s'] # 所处位置——用s距离表示
|
340
344
|
nodes = lane['center_line']['nodes']
|
341
345
|
if agent_s == 0:
|
@@ -374,7 +378,7 @@ class Sence(BrainFunction):
|
|
374
378
|
tmp_s = agent_s - radius_
|
375
379
|
tmp_s = tmp_s if tmp_s >= 0 else 0
|
376
380
|
x, y = get_xy_in_lane(nodes, tmp_s, 'back')
|
377
|
-
longlat = self._agent._simulator.map.
|
381
|
+
longlat = self._agent._simulator.map.xy2lnglat(x=x, y=y)
|
378
382
|
type = self._lane_type_mapping.get(lane['type'], 'unspecified')
|
379
383
|
positions += [{'lane_id': lane_id,
|
380
384
|
's': tmp_s,
|
@@ -391,7 +395,7 @@ class Sence(BrainFunction):
|
|
391
395
|
tmp_s = radius_
|
392
396
|
tmp_s = tmp_s if tmp_s <= suc_lane_['length'] else suc_lane_['length']
|
393
397
|
x, y = get_xy_in_lane(suc_lane_nodes, tmp_s)
|
394
|
-
longlat = self._agent._simulator.map.
|
398
|
+
longlat = self._agent._simulator.map.xy2lnglat(x=x, y=y)
|
395
399
|
type = self._lane_type_mapping.get(lane['type'], 'unspecified')
|
396
400
|
positions += [{'lane_id': suc_lane_id,
|
397
401
|
's': tmp_s,
|
@@ -403,9 +407,9 @@ class Sence(BrainFunction):
|
|
403
407
|
neg_s = agent_s - radius_
|
404
408
|
neg_s = neg_s if neg_s >= 0 else 0
|
405
409
|
x, y = get_xy_in_lane(nodes, neg_s, 'back')
|
406
|
-
longlat = self._agent._simulator.map.
|
410
|
+
longlat = self._agent._simulator.map.xy2lnglat(x=x, y=y)
|
407
411
|
type = self._lane_type_mapping.get(lane['type'], 'unspecified')
|
408
|
-
positions += [{'
|
412
|
+
positions += [{'lane_id': lane_id,
|
409
413
|
's': neg_s,
|
410
414
|
'xy': (x, y),
|
411
415
|
'longlat': longlat,
|
@@ -414,9 +418,9 @@ class Sence(BrainFunction):
|
|
414
418
|
pos_s = agent_s + radius_
|
415
419
|
pos_s = pos_s if pos_s <= lane['length'] else lane['length']
|
416
420
|
x, y = get_xy_in_lane(nodes, pos_s)
|
417
|
-
longlat = self._agent._simulator.map.
|
421
|
+
longlat = self._agent._simulator.map.xy2lnglat(x=x, y=y)
|
418
422
|
type = self._lane_type_mapping.get(lane['type'], 'unspecified')
|
419
|
-
positions += [{'
|
423
|
+
positions += [{'lane_id': lane_id,
|
420
424
|
's': neg_s,
|
421
425
|
'xy': (x, y),
|
422
426
|
'longlat': longlat,
|
pycityagent/brain/static.py
CHANGED
pycityagent/cc/cc.py
CHANGED
pycityagent/image/__init__.py
CHANGED
pycityagent/image/image.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
"""智能体画像类及其定义"""
|
2
|
+
|
1
3
|
from typing import Optional
|
2
4
|
import json
|
3
5
|
from abc import ABC, abstractclassmethod
|
@@ -99,6 +101,7 @@ class CitizenImage(Image):
|
|
99
101
|
print("Not Implemented")
|
100
102
|
|
101
103
|
class Scratch:
|
104
|
+
"""智能体基础信息"""
|
102
105
|
def __init__(self, scratch: Optional[dict]=None) -> None:
|
103
106
|
if scratch != None:
|
104
107
|
self.forward(scratch)
|
@@ -127,6 +130,7 @@ class Scratch:
|
|
127
130
|
return text
|
128
131
|
|
129
132
|
class CitizenScratch(Scratch):
|
133
|
+
"""CitizenAgent基础信息"""
|
130
134
|
def __init__(self, scratch:Optional[dict]=None) -> None:
|
131
135
|
super().__init__(scratch=scratch)
|
132
136
|
self.name = None
|
pycityagent/simulator.py
CHANGED
@@ -1,24 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
from pycitysim.sim import CityClient
|
1
|
+
"""Simulator: 城市模拟器类及其定义"""
|
2
|
+
|
4
3
|
from typing import Optional, Union
|
5
4
|
from datetime import datetime, timedelta
|
6
5
|
import asyncio
|
6
|
+
from pycitysim import *
|
7
|
+
from pycitysim.routing import RoutingClient
|
8
|
+
from pycitysim.sim import CityClient
|
7
9
|
from .agent_citizen import CitizenAgent
|
8
10
|
from .agent_func import FuncAgent
|
9
11
|
|
10
12
|
class SimPerceive:
|
11
13
|
"""
|
12
|
-
模拟器感知
|
13
|
-
Simulator Perceive
|
14
|
+
- 模拟器感知
|
15
|
+
- Simulator Perceive
|
14
16
|
"""
|
15
17
|
def __init__(self, simualtor) -> None:
|
16
18
|
self._simulator=simualtor
|
17
19
|
|
18
20
|
async def PerceiveAoisByIds(self, ids:Optional[list[int]]):
|
19
21
|
"""
|
20
|
-
Simulator视角下的AOI感知
|
21
|
-
Perceive AOI from Simulator
|
22
|
+
- Simulator视角下的AOI感知
|
23
|
+
- Perceive AOI from Simulator
|
22
24
|
|
23
25
|
Args:
|
24
26
|
- ids list[int]: list of aoi id
|
@@ -32,21 +34,50 @@ class SimPerceive:
|
|
32
34
|
|
33
35
|
class Simulator:
|
34
36
|
"""
|
35
|
-
|
36
|
-
Simulator
|
37
|
+
- 模拟器主类
|
38
|
+
- Simulator Class
|
37
39
|
"""
|
38
40
|
def __init__(self, config) -> None:
|
39
41
|
self.config = config
|
42
|
+
"""
|
43
|
+
- 模拟器配置
|
44
|
+
- simulator config
|
45
|
+
"""
|
46
|
+
|
40
47
|
self._client = CityClient(self.config['simulator']['server'], secure=True)
|
48
|
+
"""
|
49
|
+
- 模拟器grpc客户端
|
50
|
+
- grpc client of simulator
|
51
|
+
"""
|
52
|
+
|
41
53
|
self._perceive = SimPerceive(self)
|
54
|
+
"""
|
55
|
+
- 模拟器感知
|
56
|
+
- Perceive of simulator
|
57
|
+
"""
|
58
|
+
|
42
59
|
self.map = map.Map(
|
43
60
|
mongo_uri = "mongodb://sim:FiblabSim1001@mgo.db.fiblab.tech:8635/",
|
44
61
|
mongo_db = "srt",
|
45
62
|
mongo_coll = config['map_request']['mongo_coll'],
|
46
63
|
cache_dir = config['map_request']['cache_dir'],
|
47
64
|
)
|
65
|
+
"""
|
66
|
+
- 模拟器地图对象
|
67
|
+
- Simulator map object
|
68
|
+
"""
|
69
|
+
|
48
70
|
self.routing = RoutingClient(self.config['route_request']['server'])
|
71
|
+
"""
|
72
|
+
- 导航服务grpc客户端
|
73
|
+
- grpc client of routing service
|
74
|
+
"""
|
75
|
+
|
49
76
|
self.time = 0
|
77
|
+
"""
|
78
|
+
- 模拟城市当前时间
|
79
|
+
- The current time of simulator
|
80
|
+
"""
|
50
81
|
|
51
82
|
# * Agent相关
|
52
83
|
def FindAgentsByArea(self, req: dict, status=None):
|
pycityagent/st/__init__.py
CHANGED
pycityagent/st/st.py
CHANGED
pycityagent/urbanllm/__init__.py
CHANGED
pycityagent/urbanllm/urbanllm.py
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
pycityagent/__init__.py,sha256=6yaevzqXIKrV8oqWoVLCDpqmmRhXwneyx8jlBzIpyYM,236
|
2
|
+
pycityagent/agent.py,sha256=YTskUtvgwzZ1ssHHXr0XVH-QtrDc8UN5CqxxYL32-fU,8767
|
3
|
+
pycityagent/agent_citizen.py,sha256=jkr32fw54Pe14KMOBAbj98Jt8iS5SuYQLP8_zktSdC8,5213
|
4
|
+
pycityagent/agent_func.py,sha256=_SzHeKAkcjjok3CYja5ixX5fLKbOjgBihjSIyuyW6cI,4747
|
5
|
+
pycityagent/simulator.py,sha256=XQcIn3Kbvb63MyIT3NHybdhUxa-DWfSX2r23CSv2wkM,5810
|
6
|
+
pycityagent/ac/__init__.py,sha256=ya2NEJ_GagbNc52uFkmPjTGm9FoFy5pRrhXlm0SCt3s,330
|
7
|
+
pycityagent/ac/ac.py,sha256=K4LNrGOxGLH5_WOWCu9yZavbZdFAnzmAYA8rkz6kwjk,2267
|
8
|
+
pycityagent/ac/action.py,sha256=82HUiQzOCr1vE91ooq9ETWBvy_dapywNAiZXu0eMLa8,2095
|
9
|
+
pycityagent/ac/action_stream.py,sha256=cUqLWBVbluIhuvTVi6kh2GWXuE1tHERRRa29OtvMchA,783
|
10
|
+
pycityagent/ac/hub_actions.py,sha256=6irhXm5mbnfj--KTH8nsKGP4zG4moq_y4bFqqYH-Rqc,3258
|
11
|
+
pycityagent/ac/sim_actions.py,sha256=01M8ceSCSNKW5PwqJpvqVB2gAi0I1cvHqVAbbA9IEsk,3880
|
12
|
+
pycityagent/ac/citizen_actions/controled.py,sha256=co0YG7QMMpX-tpbbW_MasoPGm4RzDxkj3IkXFnsuxss,718
|
13
|
+
pycityagent/ac/citizen_actions/converse.py,sha256=ocMFvw-_sOUJmucgQjI87NNTZT9dj9svloiiU2zWDBE,1431
|
14
|
+
pycityagent/ac/citizen_actions/idle.py,sha256=zrKx8k6-YyT-4i-ZE8BuhsOJIJmCYGEO1WpUaPxWVWw,683
|
15
|
+
pycityagent/ac/citizen_actions/shop.py,sha256=lhrVelTVWF_9oAENStcX2YBgz6-fQaK3hL1OL9cl8uY,4273
|
16
|
+
pycityagent/ac/citizen_actions/trip.py,sha256=n_XiKqfYlexoxS4q-tMjf2LhIw9xyUFiQI5vSZjsUrw,1772
|
17
|
+
pycityagent/brain/__init__.py,sha256=9K8nPU-xoAyN--1eRdttRUyf-Swu5MXSmEzdSSJj6YM,359
|
18
|
+
pycityagent/brain/brain.py,sha256=G1Q98qZ6MH1SquC3BubgJqVvIBY-Vf7elgo7zzPEGwI,1079
|
19
|
+
pycityagent/brain/brainfc.py,sha256=E1N9Kdjjmo7S_kgvv8pr_gFDbQvRmXxEn1BVn85hd1s,280
|
20
|
+
pycityagent/brain/memory.py,sha256=UBZFeUYBnQ_03_QYgJhgdWRy4n5MnISopw8-Brk-sag,22067
|
21
|
+
pycityagent/brain/scheduler.py,sha256=b8MRikIJn1meTiIYi0gb6C607QnlpQkNc-Q_E0K2_Ks,18593
|
22
|
+
pycityagent/brain/sence.py,sha256=VTaaGx4JrS1HS-88vbplzzUMSAcw6Ui525eIXPt8MJM,28861
|
23
|
+
pycityagent/brain/static.py,sha256=fdBjHKacNiDCKhvQkc9WgEYYSO0peMC5lb8CcXl9iNc,29101
|
24
|
+
pycityagent/brain/persistence/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
25
|
+
pycityagent/brain/persistence/social.py,sha256=6hJi14sFm4LOU1JlnX8Vq_jFv7VII1uHDM9lrt7-JDA,27
|
26
|
+
pycityagent/brain/persistence/spatial.py,sha256=KShHehHOpvUnqxr12Y1FJF4RgyPjD3QNlWw136-zGR0,549
|
27
|
+
pycityagent/brain/reason/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
28
|
+
pycityagent/brain/reason/shop.py,sha256=jd0p6MDCNTPxo5j8glopiB501l8AuGP1vFlfDcxX69A,777
|
29
|
+
pycityagent/brain/reason/social.py,sha256=6QceFlzrA8FNwKzEvVS2aivSr12rkMbyOFO4mlACCfk,6493
|
30
|
+
pycityagent/brain/reason/trip.py,sha256=Slop2IxwZ9KE8ZqMOfYbMAgZ2hUcs4LuesxecoSliPc,1543
|
31
|
+
pycityagent/brain/reason/user.py,sha256=m1CQrG_Y-guB0WNeF1pR1HmzyPVrX4qAnuMIRl9-5ig,6412
|
32
|
+
pycityagent/brain/retrive/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
|
+
pycityagent/brain/retrive/social.py,sha256=EfF_9VCPTnDHBd2c5OmH3L4--07Ctps5HJBpSO3hUAA,135
|
34
|
+
pycityagent/cc/__init__.py,sha256=rE3JxxIB36tfYVUbtX9ZZ-TKL2lUhbiOJC1PsWqpIOI,148
|
35
|
+
pycityagent/cc/cc.py,sha256=3o17yEKbnkbFHFVvzsVrjDCEsw7MYj8x6t-_VpMDmmQ,4164
|
36
|
+
pycityagent/cc/conve.py,sha256=sRhZleIGeAV2m6mWoevwUMx2wD0xLVF5qnCld6pDC2E,150
|
37
|
+
pycityagent/cc/idle.py,sha256=RbqwG4BdSpLdZ-_13mLMbUs20q8r5drKB4wNIGWPOZw,474
|
38
|
+
pycityagent/cc/shop.py,sha256=9c8XTcUZBV90N_0MF3Gi9jlUS0LqNR3vIazEkK8tA28,149
|
39
|
+
pycityagent/cc/trip.py,sha256=ayTUnED7Kq6qiwEfCO_u-Hz6rRFNzBI25dZGUSV5dJY,312
|
40
|
+
pycityagent/cc/user.py,sha256=nS9NFfZypvXf-vLzqnYzLc6ek-CS8WALtEb00s1nREI,285
|
41
|
+
pycityagent/hubconnector/__init__.py,sha256=5dJc5993RPZ2gi4zaNdynt_a8rVVFskYVqE706AsV7M,76
|
42
|
+
pycityagent/hubconnector/hubconnector.py,sha256=6h2nNV3gCLznTP8lkHCEjdd0tANgO-rOrL5eJITTZvk,4908
|
43
|
+
pycityagent/image/__init__.py,sha256=u_kDcScyo66FQs98aXo64h-aNBC1YqdEgB7hMhXtU2E,101
|
44
|
+
pycityagent/image/image.py,sha256=ymOkow9rvWQ7oq4rynVFmHEPqp0BbxMRJLmkRX1nVyA,5501
|
45
|
+
pycityagent/st/__init__.py,sha256=LN9UMUUI_tZKAW-cUHszpRA8MjP4KL3RM0YQJY1ugVs,108
|
46
|
+
pycityagent/st/st.py,sha256=PxNsy_BEZng2mOETKCK0ira98p4LjGluM17W3QZ_9Xw,5210
|
47
|
+
pycityagent/urbanllm/__init__.py,sha256=ew7bS1-jaRf_MDTkDxvTup9a9-9FLqL0SLoloxrNDkU,85
|
48
|
+
pycityagent/urbanllm/urbanllm.py,sha256=MbDxCFxlJ-FP1o51Ig-LW3eE6qsbXW52YWuY5_x-hgA,5221
|
49
|
+
pycityagent-1.1.7.dist-info/LICENSE,sha256=Yo9QmwLDFU3VoOc0W8aYSCa5Yj5sJyqM3FEcbC2jMQQ,1063
|
50
|
+
pycityagent-1.1.7.dist-info/METADATA,sha256=5R4Vr3loJ52F87RSnxqrmP8si_Jm7Dg-R6echuRAVRM,7768
|
51
|
+
pycityagent-1.1.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
52
|
+
pycityagent-1.1.7.dist-info/top_level.txt,sha256=mf70CsOn3eVJBwHQ_TjCesoc-elD0Bj2WLsi5APRjlU,12
|
53
|
+
pycityagent-1.1.7.dist-info/RECORD,,
|
pycityagent/ac/controled.py
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
import time
|
2
|
-
from .action import Action
|
3
|
-
from pycitysim.apphub import AgentMessage
|
4
|
-
|
5
|
-
class ControledAction(Action):
|
6
|
-
'''Converse行为控制器'''
|
7
|
-
def __init__(self, agent) -> None:
|
8
|
-
super().__init__(agent)
|
9
|
-
|
10
|
-
async def Forward(self):
|
11
|
-
req = {'person_id': self._agent._id, 'schedules': []}
|
12
|
-
await self._agent._client.person_service.SetSchedule(req)
|
13
|
-
self._agent.Hub.Update([AgentMessage(self._agent.Hub._agent_id, int(time.time()*1000), '我已理解您的意思,正在修改我的行程', None, None)])
|
pycityagent/ac/converse.py
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
import time
|
2
|
-
from .action import Action
|
3
|
-
from pycitysim.apphub import AgentMessage
|
4
|
-
|
5
|
-
class ConverseAction(Action):
|
6
|
-
'''Converse行为控制器'''
|
7
|
-
def __init__(self, agent) -> None:
|
8
|
-
super().__init__(agent)
|
9
|
-
|
10
|
-
async def Forward(self):
|
11
|
-
target_agent_ids = self._agent.Brain.Memory.Working.Reason['agent_message_handle_resp'][0]
|
12
|
-
if len(target_agent_ids) == 0:
|
13
|
-
return
|
14
|
-
messages = self._agent.Brain.Memory.Working.Reason['agent_message_handle_resp'][1]
|
15
|
-
req = {'messages': []}
|
16
|
-
if len(target_agent_ids) != len(messages):
|
17
|
-
print("Warning: the number of target agent and message are not aligned, only sends matched messages")
|
18
|
-
rng = min(len(target_agent_ids), len(messages))
|
19
|
-
for i in range(rng):
|
20
|
-
dic = {}
|
21
|
-
dic['from'] = self._agent._id
|
22
|
-
dic['to'] = target_agent_ids[i]
|
23
|
-
dic['message'] = messages[i]
|
24
|
-
req['messages'].append(dic)
|
25
|
-
# * 发送至模拟器
|
26
|
-
await self._agent._client.social_service.Send(req=req)
|
27
|
-
|
28
|
-
# * 发送至AppHub
|
29
|
-
if self._agent.Hub != None and messages[0] != 'End':
|
30
|
-
# * 将信息中的第一条不同至pop
|
31
|
-
self._agent.Hub.Update(pop=messages[0])
|
pycityagent/ac/idle.py
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
import time
|
2
|
-
from .action import Action
|
3
|
-
from pycitysim.apphub import AgentMessage
|
4
|
-
|
5
|
-
class IdleAction(Action):
|
6
|
-
'''idle行为控制器'''
|
7
|
-
def __init__(self, agent) -> None:
|
8
|
-
super().__init__(agent)
|
9
|
-
|
10
|
-
async def Forward(self):
|
11
|
-
if len(self._agent.base['schedules']) > 0:
|
12
|
-
req = {'person_id': self._agent._id, 'schedules': []}
|
13
|
-
await self._agent._client.person_service.SetSchedule(req)
|
14
|
-
if self._agent.Hub != None:
|
15
|
-
self._agent.Hub.Update()
|
16
|
-
|
17
|
-
|
pycityagent/ac/shop.py
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
from .action import Action
|
2
|
-
from pycitysim.apphub import AgentMessage
|
3
|
-
import time
|
4
|
-
|
5
|
-
def encap_msg(msg, role='user', **kwargs):
|
6
|
-
dialog = {'role': role, 'content': msg}
|
7
|
-
dialog.update(kwargs)
|
8
|
-
return dialog
|
9
|
-
|
10
|
-
class ShopAction(Action):
|
11
|
-
'''Shop行为控制器'''
|
12
|
-
def __init__(self, agent) -> None:
|
13
|
-
super().__init__(agent)
|
14
|
-
|
15
|
-
async def Forward(self):
|
16
|
-
# * 与模拟器对接 - 暂时没有
|
17
|
-
# * 与AppHub对接
|
18
|
-
profile = self._agent.Image.get_profile()
|
19
|
-
self.consumption(profile)
|
20
|
-
|
21
|
-
def consumption(self, profile, mall_info):
|
22
|
-
dialogs = []
|
23
|
-
system_prompt = f'''
|
24
|
-
你是一个在北京工作和生活的人。
|
25
|
-
{profile}
|
26
|
-
现在是2024年1月。
|
27
|
-
你需要为下一周的基本生活购买必需品。
|
28
|
-
'''
|
29
|
-
dialogs.append(encap_msg(system_prompt, 'system'))
|
30
|
-
actions_format = ['''{{'商品': 购买的商品的列表,'购买量': 每个商品的购买量,一个列表, '解释': '这种购买方式的原因'}}''']
|
31
|
-
actions_candidates = ['''【食品】
|
32
|
-
米:10元/公斤
|
33
|
-
面粉:7.5元/公斤
|
34
|
-
新鲜蔬菜(如菠菜):7元/500克
|
35
|
-
水果(如苹果):15元/公斤
|
36
|
-
猪肉:30元/公斤
|
37
|
-
鸡肉:20元/公斤
|
38
|
-
鸡蛋:1.5元/个
|
39
|
-
牛奶:10元/升''',
|
40
|
-
'''【清洁用品】
|
41
|
-
洗衣液:30元/瓶
|
42
|
-
洗洁精:20元/瓶
|
43
|
-
垃圾袋:0.3元/个''',
|
44
|
-
'''【个人护理用品】
|
45
|
-
牙膏:10元/支
|
46
|
-
洗发水:30元/瓶
|
47
|
-
沐浴露:35元/瓶
|
48
|
-
面巾纸:5元/包''',
|
49
|
-
'''【其他】
|
50
|
-
矿泉水:1.7元/瓶
|
51
|
-
面包:8元/个
|
52
|
-
辣条:3元/包''']
|
53
|
-
|
54
|
-
user_prompt = f'''
|
55
|
-
首先确定你的消费预算。以如下格式回答,不要有冗余的文本!
|
56
|
-
{{'消费预算': 一个代表购买必需品需要消耗的钱的数量的数字}}
|
57
|
-
'''
|
58
|
-
dialogs.append(encap_msg(user_prompt))
|
59
|
-
# * 对接一:确定消费预算
|
60
|
-
self._agent.Hub.Update([AgentMessage(self._agent.Hub._agent_id, int(time.time()*1000), '我正在确定消费预算......', None, None)])
|
61
|
-
msg = self._agent._soul.text_request(dialogs)
|
62
|
-
self._agent.Hub.Update([AgentMessage(self._agent.Hub._agent_id, int(time.time()*1000), f'我的消费预算是: {msg}'), None, None])
|
63
|
-
|
64
|
-
dialogs.append(encap_msg(msg, 'assistant'))
|
65
|
-
|
66
|
-
# * 对接二:购物选择
|
67
|
-
for cand in actions_candidates:
|
68
|
-
user_prompt = f'''
|
69
|
-
购物中心里有
|
70
|
-
{cand}
|
71
|
-
你要买哪些商品,以如下格式回答,不要有冗余的文本!
|
72
|
-
{actions_format[0]}
|
73
|
-
'''
|
74
|
-
self._agent.Hub.Update([AgentMessage(self._agent.Hub._agent_id, int(time.time()*1000), f'我看到了\n {cand}', None, None)])
|
75
|
-
dialogs.append(encap_msg(user_prompt))
|
76
|
-
msg = self._agent._soul.text_request(dialogs)
|
77
|
-
self._agent.Hub.Update([AgentMessage(self._agent.Hub._agent_id, int(time.time()*1000), f'我的购买选择是: {msg}', None, None)])
|
78
|
-
dialogs.append(encap_msg(msg, 'assistant'))
|
79
|
-
|
80
|
-
self._agent.Hub.Update([AgentMessage(self._agent.Hub._agent_id, int(time.time()*1000), '购物完成', None, None)])
|
pycityagent/ac/trip.py
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
import time
|
2
|
-
from .action import Action
|
3
|
-
from pycitysim.apphub import AgentMessage
|
4
|
-
|
5
|
-
class TripAction(Action):
|
6
|
-
'''Trip行为控制器'''
|
7
|
-
def __init__(self, agent) -> None:
|
8
|
-
super().__init__(agent)
|
9
|
-
|
10
|
-
async def Forward(self):
|
11
|
-
now = self._agent.Scheduler.now
|
12
|
-
if now.is_set:
|
13
|
-
'''之前已经将schedule同步至模拟器了'''
|
14
|
-
if self._agent.Hub != None:
|
15
|
-
self._agent.Hub.Update(streetview=self._agent.Brain.Sence.sence_buffer['streetview'])
|
16
|
-
else:
|
17
|
-
'''同步schedule至模拟器'''
|
18
|
-
self._agent.Scheduler.now.is_set = True
|
19
|
-
departure_time = now.time
|
20
|
-
mode = now.mode
|
21
|
-
aoi_id = now.target_id_aoi
|
22
|
-
poi_id = now.target_id_poi
|
23
|
-
end = {'aoi_position': {'aoi_id': aoi_id, 'poi_id': poi_id}}
|
24
|
-
activity = now.description
|
25
|
-
trips = [{'mode': mode, 'end': end, 'departure_time': departure_time, 'activity': activity}]
|
26
|
-
set_schedule = [{'trips': trips, 'loop_count': 1, 'departure_time': departure_time}]
|
27
|
-
|
28
|
-
# * 与模拟器对接
|
29
|
-
req = {'person_id': self._agent._id, 'schedules': set_schedule}
|
30
|
-
await self._agent._client.person_service.SetSchedule(req)
|
31
|
-
|
32
|
-
# * 与AppHub对接
|
33
|
-
if self._agent.Hub != None:
|
34
|
-
messages = [AgentMessage(self._agent.Hub._agent_id, int(time.time()*1000), f'已到达出发时间, {activity}', None, None)]
|
35
|
-
self._agent.Hub.Update(messages)
|
36
|
-
|
37
|
-
|
@@ -1,58 +0,0 @@
|
|
1
|
-
pycityagent/__init__.py,sha256=UWAMvcctp49-8QaRHr2wuR4mLPNvUQ9ocQaXPVLHonI,186
|
2
|
-
pycityagent/agent.py,sha256=FxbQiP1IDhuBQuUI8IQeY8eFbr18NQxCiBefWICGnQc,8165
|
3
|
-
pycityagent/agent_citizen.py,sha256=AnU9LTP1vGccO7MIxcCYwT40S5Wd9XexO77xjb_oNDc,4972
|
4
|
-
pycityagent/agent_func.py,sha256=_9-68KECa0yi867XsXECT8goAw6VogPtb6ba4lNmHJY,4212
|
5
|
-
pycityagent/simulator.py,sha256=f8IATajGMuUHaHQV_152tFQQAMv2aVWbusrVpjx3LZI,5194
|
6
|
-
pycityagent/ac/__init__.py,sha256=ya2NEJ_GagbNc52uFkmPjTGm9FoFy5pRrhXlm0SCt3s,330
|
7
|
-
pycityagent/ac/ac.py,sha256=hln8_Dv05tBLcSXd2yso09Z5hsZkvqYBxk6o-sZKia8,2229
|
8
|
-
pycityagent/ac/action.py,sha256=MoJ-czSY8AIPDxUzD8-rLrbZIcomovmHvEkMLCTNOTw,1954
|
9
|
-
pycityagent/ac/action_stream.py,sha256=cUqLWBVbluIhuvTVi6kh2GWXuE1tHERRRa29OtvMchA,783
|
10
|
-
pycityagent/ac/controled.py,sha256=Q9wLPK0HgUO6w551c6gZNPNwtZMWojG3867m7Oy0cVM,539
|
11
|
-
pycityagent/ac/converse.py,sha256=IotnC3kwCcCk8-oOuIJOeYBPCVR9lItjci18TX1GGR0,1252
|
12
|
-
pycityagent/ac/hub_actions.py,sha256=iMyGjG5ul2whGllOfGJArvMYAXDCCy4pVmZB4HIWuHU,3226
|
13
|
-
pycityagent/ac/idle.py,sha256=TU67IWSN_DM1aCdMf6xkXX5uSTPgFIUCVwvxAxN03e0,504
|
14
|
-
pycityagent/ac/shop.py,sha256=i9nReY47wgVOMcmi_wp0W9M_dNoXmHpyEo93mC1K6ok,4095
|
15
|
-
pycityagent/ac/sim_actions.py,sha256=dpOnhwwsbdYmNGhTWMHzj38qrZd_h99zJraFj6vkljg,3845
|
16
|
-
pycityagent/ac/trip.py,sha256=AGdSgqw5CVFVyu_DPnaOY-fK6fTZsOCiA9aVUIAS9VU,1527
|
17
|
-
pycityagent/ac/citizen_actions/controled.py,sha256=co0YG7QMMpX-tpbbW_MasoPGm4RzDxkj3IkXFnsuxss,718
|
18
|
-
pycityagent/ac/citizen_actions/converse.py,sha256=ocMFvw-_sOUJmucgQjI87NNTZT9dj9svloiiU2zWDBE,1431
|
19
|
-
pycityagent/ac/citizen_actions/idle.py,sha256=zrKx8k6-YyT-4i-ZE8BuhsOJIJmCYGEO1WpUaPxWVWw,683
|
20
|
-
pycityagent/ac/citizen_actions/shop.py,sha256=lhrVelTVWF_9oAENStcX2YBgz6-fQaK3hL1OL9cl8uY,4273
|
21
|
-
pycityagent/ac/citizen_actions/trip.py,sha256=n_XiKqfYlexoxS4q-tMjf2LhIw9xyUFiQI5vSZjsUrw,1772
|
22
|
-
pycityagent/brain/__init__.py,sha256=lTW3TBpCTnuJaTWcaeb6j5QQChGBgmWvmSWOBeZp_AQ,373
|
23
|
-
pycityagent/brain/brain.py,sha256=WlIcp79ZbiWL47ubdVeXtUvQmzb0Rzluwq3tT2LjHBo,1067
|
24
|
-
pycityagent/brain/brainfc.py,sha256=XoiNUQgP4P7ui9dRZWTfzyzBVTDYZf10XqM7kot0Dbg,252
|
25
|
-
pycityagent/brain/memory.py,sha256=MhTO8qzhogi-vA12eN3Y3H8gdflYf01XQmIM92N-RaI,21934
|
26
|
-
pycityagent/brain/scheduler.py,sha256=56T78XrIdZb7qdlKPkNB-ibKH36ooEqHyHcp2jlID90,18492
|
27
|
-
pycityagent/brain/sence.py,sha256=taHdFT1o6ckK36WLOkyFMdRh72EJHkeBtb90cL4S6Mw,28683
|
28
|
-
pycityagent/brain/static.py,sha256=vvPaJGKqTBqNe_N3LTFdDjgjjdeZb5niFrYUhGBsGD4,29081
|
29
|
-
pycityagent/brain/persistence/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
30
|
-
pycityagent/brain/persistence/social.py,sha256=6hJi14sFm4LOU1JlnX8Vq_jFv7VII1uHDM9lrt7-JDA,27
|
31
|
-
pycityagent/brain/persistence/spatial.py,sha256=KShHehHOpvUnqxr12Y1FJF4RgyPjD3QNlWw136-zGR0,549
|
32
|
-
pycityagent/brain/reason/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
|
-
pycityagent/brain/reason/shop.py,sha256=jd0p6MDCNTPxo5j8glopiB501l8AuGP1vFlfDcxX69A,777
|
34
|
-
pycityagent/brain/reason/social.py,sha256=6QceFlzrA8FNwKzEvVS2aivSr12rkMbyOFO4mlACCfk,6493
|
35
|
-
pycityagent/brain/reason/trip.py,sha256=Slop2IxwZ9KE8ZqMOfYbMAgZ2hUcs4LuesxecoSliPc,1543
|
36
|
-
pycityagent/brain/reason/user.py,sha256=m1CQrG_Y-guB0WNeF1pR1HmzyPVrX4qAnuMIRl9-5ig,6412
|
37
|
-
pycityagent/brain/retrive/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
38
|
-
pycityagent/brain/retrive/social.py,sha256=EfF_9VCPTnDHBd2c5OmH3L4--07Ctps5HJBpSO3hUAA,135
|
39
|
-
pycityagent/cc/__init__.py,sha256=rE3JxxIB36tfYVUbtX9ZZ-TKL2lUhbiOJC1PsWqpIOI,148
|
40
|
-
pycityagent/cc/cc.py,sha256=p96ZzNKb6KxUNqPWEi1B7Rf0374oM5nJPwGWdaBYZ6k,4135
|
41
|
-
pycityagent/cc/conve.py,sha256=sRhZleIGeAV2m6mWoevwUMx2wD0xLVF5qnCld6pDC2E,150
|
42
|
-
pycityagent/cc/idle.py,sha256=RbqwG4BdSpLdZ-_13mLMbUs20q8r5drKB4wNIGWPOZw,474
|
43
|
-
pycityagent/cc/shop.py,sha256=9c8XTcUZBV90N_0MF3Gi9jlUS0LqNR3vIazEkK8tA28,149
|
44
|
-
pycityagent/cc/trip.py,sha256=ayTUnED7Kq6qiwEfCO_u-Hz6rRFNzBI25dZGUSV5dJY,312
|
45
|
-
pycityagent/cc/user.py,sha256=nS9NFfZypvXf-vLzqnYzLc6ek-CS8WALtEb00s1nREI,285
|
46
|
-
pycityagent/hubconnector/__init__.py,sha256=O11GJiILTibDUgJiAZxfIZ0kckKvToPUYijd06RQ0iQ,53
|
47
|
-
pycityagent/hubconnector/hubconnector.py,sha256=Mbaz9y13O_ZT1dlU5Y-fEuTCaVznzc000ECnqnUxkho,4879
|
48
|
-
pycityagent/image/__init__.py,sha256=PIKazmxiXLVbSwXIvau3zAvpynyDgukOdNKzh3Iy5ww,78
|
49
|
-
pycityagent/image/image.py,sha256=KyOBoX8I1KSi82lBCBku-NXgXX4gIFHi2cGEe7yQ-lI,5396
|
50
|
-
pycityagent/st/__init__.py,sha256=YzsQXrgqRvmoQ4dWqAztAriKd8wvnQVe0FOpX_oZmiY,109
|
51
|
-
pycityagent/st/st.py,sha256=z6yDo7ADOjostLg0mLmQ0oa_VysaCXFm4MnzC2H9nsI,5154
|
52
|
-
pycityagent/urbanllm/__init__.py,sha256=D24mYFXdIEL2vbvB7Cp_BGgJvg-tvEnCgtEAAGaqGDY,56
|
53
|
-
pycityagent/urbanllm/urbanllm.py,sha256=z6mJyvFbu4cotxLuen0ODZUIpba9SOUwNg3HEbrGylI,5176
|
54
|
-
pycityagent-1.1.5.dist-info/LICENSE,sha256=Yo9QmwLDFU3VoOc0W8aYSCa5Yj5sJyqM3FEcbC2jMQQ,1063
|
55
|
-
pycityagent-1.1.5.dist-info/METADATA,sha256=zBD0UWeliRWImn4hPEDfTNNlyymcJOfsWQ7bscUJlgs,7768
|
56
|
-
pycityagent-1.1.5.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
57
|
-
pycityagent-1.1.5.dist-info/top_level.txt,sha256=mf70CsOn3eVJBwHQ_TjCesoc-elD0Bj2WLsi5APRjlU,12
|
58
|
-
pycityagent-1.1.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|