Name | pycityagent JSON |
Version |
1.1.11
JSON |
| download |
home_page | None |
Summary | LLM-based城市模拟器agent构建库 |
upload_time | 2024-10-02 10:55:29 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT License Copyright (c) 2024 FIBLAB Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
agent
city
llm
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Pycityagent
# Table of Contents
* [Introduction](#Introduction)
* [The Whole Framework of CityAgent](#The-Whole-Framework-of-CityAgent)
* [The Workflow of CityAgent](#The-Workflow-of-CityAgent)
* [Hands On - By An Easy Demo](#Hands-On---By-An-Easy-Demo)
<!-- TOC -->
## Introduction
### Framework of CityAgent
- ![framwork](./static/framework.png)
### Workflow of CityAgent
- ![workflow](./static/workflow_1.png)
## Hands On - By An Easy Demo
### Apply for your App
- You first need to register your account in the [Opencity website](https://opencity.fiblab.net/)
- Login to the console, create your own app.
- Get your app_id and app_secret
- ![app](./static/app.png)
### Get your Config
- There are three parts of a config file: **llm_request**, **citysim_request** and **apphub_request**
```yaml
llm_request:
text_request:
request_type: openai / qwen
api_key: xxx
model: xxx
(api_base): xxx (this is an optional config, if you use opanai and want to use your own backend LLM model, default to "https://api.openai.com/v1")
img_understand_request:
request_type: openai / qwen
api_key: xxx
model: xxx ('gpt-4-turbo' if you use openai)
(api_base): same as text_request
img_generate_request:
request_type: qwen
api_key: xxx
model: xxx
citysim_request:
simulator:
server: https://api-opencity-2x.fiblab.net:58081
map_request:
mongo_coll: map_beijing_extend_20240205
cache_dir: ./cache
route_request:
server: http://api-opencity-2x.fiblab.net:58082
streetview_request:
engine: baidumap / googlemap
mapAK: baidumap api-key (if you use baidumap engine)
proxy: googlemap proxy (if you use googlemap engine)
apphub_request:
hub_url: https://api-opencity-2x.fiblab.net:58080
app_id: your APP ID
app_secret: your APP Secret
profile_image: the profile image of your agent
```
- Forget about **citysim_request**, let's focus on the other two.
#### LLM_REQUEST
- As you can see, the whole CityAgent is based on the LLM, by now, there are three different parts of config items: **text_request**, **img_understand_request** and **img_generate_request**
- **text_request**
- By now, we support [**qwen**](https://tongyi.aliyun.com/) and [**openai**](https://openai.com/)
- `Notice: Our environments are basically conducted with qwen. If you prefer to use openai, then you may encounter hardships. AND fell free to issue us.`
- Get your **api_key** and chooce your **model**
- If you want to use your backend models, set the **api_base** (only available when using **openai**)
- default value: "https://api.openai.com/v1"
- **img_understand_request**
- By now, we support **qwen** and **openai**
- If choose **openai**, then the **model** has to be '**gpt-4-turbo**'
- If you want to use your backend models, set the **api_base** (only available when using **openai**)
- default value: "https://api.openai.com/v1"
- **img_generate_request**
- By now, only [**qwen**] is supported
#### CITYSIM_REQUEST
- Most of the configuration options in this part are determined, such as **simulator.server**, **map_request.mongo_coll**, **route_request.server**
- **map_request.cache_dir**: used for storing map data your machine, you can justify the target dir as you wish (**create the dir first**)
- **streetview_request**: used for obtaining streetview images, by now, we support baidumap engine and googlemap engine
- if you choose baidumap engine, you need to get a baidumap api-key
``` yaml
streetview_request:
engine: baidumap
mapAK: xxxx
```
- if you choose googlemap engine, you need to provide your proxy address, for example:
``` yaml
streetview_request:
engine: googlemap
proxy:
http: http://xxxx
https: https://xxxx
```
#### APPHUB_REQUEST
- Used for creating the connection between backend server and client.
- Put your **app_id** and **app_secret** here.
- Create your account and apply in [Opencity website](https://opencity.fiblab.net/)
### Installation
#### PyPI Installation
- Install from **pip** easily.
```shell
pip install pycityagent
```
#### Install from source code
- Clone this repo
- Install required packages
``` shell
pip install -r requirements.txt
```
- Install **libGL.so.1**, if you ara using Linux with a suitable package manager: (apt for instance)
``` shell
apt-get install libgl1
```
### CODE and RUN
- Check the **example** folder and copy files from it (`Remember replace the config file`)
- Look at the Demo: (A citizen Agent demo)
```python
import yaml
from pycityagent.simulator import Simulator
from pycityagent.urbanllm import LLMConfig, UrbanLLM
import asyncio
import time
async def main():
# load your config
with open('config_template.yaml', 'r') as file:
config = yaml.safe_load(file)
# get the simulator object
smi = Simulator(config['citysim_request'])
# get the person by person_id, return agent
agent = await smi.GetCitizenAgent("name_of_agent", 8)
# Help you build unique agent by scratch/profile
agent.Image.load_scratch('scratch_template.json')
# Load Memory and assist the agent to understand "Opencity"
agent.Brain.Memory.Spatial.MemoryLoad('spatial_knowledge_template.json')
agent.Brain.Memory.Social.MemoryLoad('social_background_template.json')
# Connect to apphub so you can interact with your agent in front end
agent.ConnectToHub(config['apphub_request'])
agent.Bind()
# Creat the soul (a LLM processor actually)
llmConfig = LLMConfig(config['llm_request'])
soul = UrbanLLM(llmConfig)
# Add the soul to your agent
agent.add_soul(soul)
# Start and have fun with it!!!
while True:
await agent.Run()
time.sleep(1)
if __name__ == '__main__':
asyncio.run(main())
```
### Congratulations
- Following this "Hands On" guide, you have easily created an agent by your hand!
- You can observe your AGENT in your console or in the [Opencity website](https://opencity.fiblab.net/).
- HAVE FUN WITH IT!
Raw data
{
"_id": null,
"home_page": null,
"name": "pycityagent",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "agent, city, LLM",
"author": null,
"author_email": "Yuwei Yan <pinkgranite86@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/38/d3/671bf7d29f6e90359cc5199503ca8c79dea1de38f7ffd0234aef9eaf6c63/pycityagent-1.1.11.tar.gz",
"platform": null,
"description": "# Pycityagent\n\n# Table of Contents\n* [Introduction](#Introduction)\n\t* [The Whole Framework of CityAgent](#The-Whole-Framework-of-CityAgent)\n\t* [The Workflow of CityAgent](#The-Workflow-of-CityAgent)\n* [Hands On - By An Easy Demo](#Hands-On---By-An-Easy-Demo)\n\n<!-- TOC -->\n\n## Introduction\n### Framework of CityAgent\n- ![framwork](./static/framework.png)\n\n### Workflow of CityAgent\n- ![workflow](./static/workflow_1.png)\n\n## Hands On - By An Easy Demo\n### Apply for your App\n- You first need to register your account in the [Opencity website](https://opencity.fiblab.net/)\n- Login to the console, create your own app.\n- Get your app_id and app_secret\n - ![app](./static/app.png)\n\n### Get your Config\n- There are three parts of a config file: **llm_request**, **citysim_request** and **apphub_request**\n```yaml\nllm_request:\n text_request:\n request_type: openai / qwen\n api_key: xxx\n model: xxx\n (api_base): xxx (this is an optional config, if you use opanai and want to use your own backend LLM model, default to \"https://api.openai.com/v1\")\n img_understand_request:\n request_type: openai / qwen\n api_key: xxx\n model: xxx ('gpt-4-turbo' if you use openai)\n (api_base): same as text_request\n img_generate_request:\n request_type: qwen\n api_key: xxx\n model: xxx\n\ncitysim_request:\n simulator: \n server: https://api-opencity-2x.fiblab.net:58081\n map_request:\n mongo_coll: map_beijing_extend_20240205\n cache_dir: ./cache\n route_request: \n server: http://api-opencity-2x.fiblab.net:58082\n streetview_request:\n engine: baidumap / googlemap\n mapAK: baidumap api-key (if you use baidumap engine)\n proxy: googlemap proxy (if you use googlemap engine)\n\napphub_request:\n hub_url: https://api-opencity-2x.fiblab.net:58080\n app_id: your APP ID\n app_secret: your APP Secret\n profile_image: the profile image of your agent\n```\n- Forget about **citysim_request**, let's focus on the other two.\n\n#### LLM_REQUEST\n- As you can see, the whole CityAgent is based on the LLM, by now, there are three different parts of config items: **text_request**, **img_understand_request** and **img_generate_request**\n- **text_request**\n - By now, we support [**qwen**](https://tongyi.aliyun.com/) and [**openai**](https://openai.com/)\n - `Notice: Our environments are basically conducted with qwen. If you prefer to use openai, then you may encounter hardships. AND fell free to issue us.`\n - Get your **api_key** and chooce your **model**\n - If you want to use your backend models, set the **api_base** (only available when using **openai**)\n - default value: \"https://api.openai.com/v1\"\n- **img_understand_request**\n - By now, we support **qwen** and **openai**\n - If choose **openai**, then the **model** has to be '**gpt-4-turbo**'\n - If you want to use your backend models, set the **api_base** (only available when using **openai**)\n - default value: \"https://api.openai.com/v1\"\n- **img_generate_request**\n - By now, only [**qwen**] is supported\n\n#### CITYSIM_REQUEST\n- Most of the configuration options in this part are determined, such as **simulator.server**, **map_request.mongo_coll**, **route_request.server**\n- **map_request.cache_dir**: used for storing map data your machine, you can justify the target dir as you wish (**create the dir first**)\n- **streetview_request**: used for obtaining streetview images, by now, we support baidumap engine and googlemap engine\n - if you choose baidumap engine, you need to get a baidumap api-key\n ``` yaml\n streetview_request:\n engine: baidumap\n mapAK: xxxx\n ```\n - if you choose googlemap engine, you need to provide your proxy address, for example:\n ``` yaml\n streetview_request:\n engine: googlemap\n proxy: \n http: http://xxxx\n https: https://xxxx\n ```\n\n#### APPHUB_REQUEST\n- Used for creating the connection between backend server and client.\n- Put your **app_id** and **app_secret** here.\n - Create your account and apply in [Opencity website](https://opencity.fiblab.net/)\n\n### Installation\n#### PyPI Installation\n - Install from **pip** easily.\n ```shell\n pip install pycityagent\n ```\n\n#### Install from source code\n- Clone this repo\n- Install required packages\n ``` shell\n pip install -r requirements.txt\n ```\n- Install **libGL.so.1**, if you ara using Linux with a suitable package manager: (apt for instance)\n ``` shell\n apt-get install libgl1\n ```\n\n### CODE and RUN\n- Check the **example** folder and copy files from it (`Remember replace the config file`)\n- Look at the Demo: (A citizen Agent demo)\n```python\nimport yaml\nfrom pycityagent.simulator import Simulator\nfrom pycityagent.urbanllm import LLMConfig, UrbanLLM\nimport asyncio\nimport time\n\nasync def main():\n # load your config\n with open('config_template.yaml', 'r') as file:\n config = yaml.safe_load(file)\n \n # get the simulator object\n smi = Simulator(config['citysim_request'])\n \n # get the person by person_id, return agent\n agent = await smi.GetCitizenAgent(\"name_of_agent\", 8)\n\n # Help you build unique agent by scratch/profile\n agent.Image.load_scratch('scratch_template.json')\n\n # Load Memory and assist the agent to understand \"Opencity\"\n agent.Brain.Memory.Spatial.MemoryLoad('spatial_knowledge_template.json')\n agent.Brain.Memory.Social.MemoryLoad('social_background_template.json')\n\n # Connect to apphub so you can interact with your agent in front end\n agent.ConnectToHub(config['apphub_request'])\n agent.Bind()\n\n # Creat the soul (a LLM processor actually)\n llmConfig = LLMConfig(config['llm_request'])\n soul = UrbanLLM(llmConfig)\n\n # Add the soul to your agent\n agent.add_soul(soul)\n \n # Start and have fun with it!!!\n while True:\n await agent.Run()\n time.sleep(1)\n\nif __name__ == '__main__':\n asyncio.run(main())\n```\n\n### Congratulations\n- Following this \"Hands On\" guide, you have easily created an agent by your hand! \n- You can observe your AGENT in your console or in the [Opencity website](https://opencity.fiblab.net/).\n- HAVE FUN WITH IT!\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 FIBLAB Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "LLM-based\u57ce\u5e02\u6a21\u62df\u5668agent\u6784\u5efa\u5e93",
"version": "1.1.11",
"project_urls": {
"Homepage": "https://github.com/tsinghua-fib-lab/pycityagent",
"Issues": "https://github.com/tsinghua-fib-lab/pycityagent/issues",
"Repository": "https://github.com/tsinghua-fib-lab/pycityagent.git"
},
"split_keywords": [
"agent",
" city",
" llm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c12d590ca471c45efc93d4682c4cbd62b4f480635cfa764c0545488af31d1d52",
"md5": "f35f90bed9aff4135f71aeec93942f59",
"sha256": "150c40229a87ff69f1c8287828b1b16aefdba521de0626e3961b7938cf253aa4"
},
"downloads": -1,
"filename": "pycityagent-1.1.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f35f90bed9aff4135f71aeec93942f59",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 78945,
"upload_time": "2024-10-02T10:55:27",
"upload_time_iso_8601": "2024-10-02T10:55:27.485960Z",
"url": "https://files.pythonhosted.org/packages/c1/2d/590ca471c45efc93d4682c4cbd62b4f480635cfa764c0545488af31d1d52/pycityagent-1.1.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "38d3671bf7d29f6e90359cc5199503ca8c79dea1de38f7ffd0234aef9eaf6c63",
"md5": "0d62f872f8a9d591967c1a490f32aef9",
"sha256": "88fe01fd832865c3f81870653662afe36bffd70bb66e9afa4c4605ad26bf4c71"
},
"downloads": -1,
"filename": "pycityagent-1.1.11.tar.gz",
"has_sig": false,
"md5_digest": "0d62f872f8a9d591967c1a490f32aef9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 65487,
"upload_time": "2024-10-02T10:55:29",
"upload_time_iso_8601": "2024-10-02T10:55:29.125546Z",
"url": "https://files.pythonhosted.org/packages/38/d3/671bf7d29f6e90359cc5199503ca8c79dea1de38f7ffd0234aef9eaf6c63/pycityagent-1.1.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-02 10:55:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "tsinghua-fib-lab",
"github_project": "pycityagent",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "pycityagent"
}