Skip to content

Commit 46731f8

Browse files
pratrivedipratrivedi
and
pratrivedi
authored
Feat/add mobility agents on mobility integrations (#235)
Co-authored-by: pratrivedi <[email protected]>
1 parent 23c98bd commit 46731f8

23 files changed

+1356
-2062
lines changed
+17-31
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
# 🚗 uAgent Mobility Integrations Examples 🚴
22

3-
This repository contains examples of mobility integrations using two agents: `ev_charger` and `geoapi_car_parking`.
3+
This repository contains examples of mobility integrations using these agents: `ev_charger`, `car_wash`, `car_service`, `restaurant`, `gecode` and `geoapi_car_parking`.
44

55
1. `ev_charger`: This agent takes latitude, longitude, and a miles radius as input and returns available EV chargers in that region within the given radius. It utilizes the [OpenChargeMap](https://openchargemap.org/site/develop/api) API to retrieve the desired results.
66

77
2. `geoapi_car_parking`: This agent takes latitude, longitude, and a miles radius as input and returns available parking spaces within that radius. The agent leverages [Geoapify](https://www.geoapify.com/) to fetch the desired results.
88

9+
3. `geocode`: This agent takes an address as input and returns latitude and longitude of the given address.
10+
11+
4. `car_wash`: This agent takes latitude, longitude, and a miles radius as input and returns available Car wash in that region within the given radius. It utilizes the mock data from `car_wash_data.py` to retrieve the desired results.
12+
13+
5. `car_service`: This agent takes latitude, longitude, and a miles radius as input and returns available Car services in that region within the given radius. It utilizes the mock data from `car_service_data.py` to retrieve the desired results.
14+
15+
6. `restaurant`: This agent takes latitude, longitude, and a miles radius as input and returns available Restaurants in that region within the given radius. It utilizes the mock data from `restaurant_data.py` to retrieve the desired results.
16+
917
## Getting Started 🚀
1018

1119
To use these agents, follow the steps below:
@@ -18,8 +26,8 @@ Before running the agents, you need to obtain the required API keys:
1826

1927
1. Visit the OpenChargeMap API website: https://openchargemap.org/site/develop/api.
2028
2. If you don't have an account, create one by signing up.
21-
3. Once you are logged in, click on the MY PROFILE > my apps at the top.
22-
4. Click on REGISTER AN APPLICATION button.
29+
3. Once you are logged in, click on MY PROFILE > my apps at the top.
30+
4. Click on the REGISTER AN APPLICATION button.
2331
5. Fill out the required information in the form, including the purpose of using the API, and submit the request.
2432
6. Once approved, you will see your `OPENCHARGEMAP_API_KEY` under MY API KEYS.
2533

@@ -31,32 +39,10 @@ Before running the agents, you need to obtain the required API keys:
3139
4. Give your project a name and click "OK" to create the new project.
3240
5. Your `GEOAPI_API_KEY` will be generated. Copy this key and keep it secure, as it will be used to access Geoapify Projects and other services.
3341

34-
### Step 2: Set Environment Variables 🌐
35-
36-
Create a `.env` file in the `mobility-integrations` directory and export the obtained API keys as environment variables:
37-
38-
```bash
39-
export OPENCHARGEMAP_API_KEY="{GET THE API KEY}"
40-
export GEOAPI_API_KEY="{GET THE API KEY}"
41-
```
42-
43-
### Step 3: Install Dependencies ⚙️
44-
45-
To use the environment variables from the `.env` file and install the project dependencies:
46-
47-
```bash
48-
source .env
49-
poetry install
50-
```
51-
52-
### Step 4: Run the Project 🏃
53-
54-
To run the project and its agents:
55-
56-
```bash
57-
cd src
58-
poetry shell
59-
python main.py
60-
```
42+
#### GOOGLE_MAPS_API_KEY 🗺️
6143

62-
Now you have the agents up and running to perform mobility integrations using the provided APIs. Happy integrating! 🎉
44+
1. Go to the Google Cloud Console: https://console.cloud.google.com/.
45+
2. Create a new project or select an existing project from the top right corner.
46+
3. In the left navigation, click on the "API & Services" > "Credentials" section.
47+
4. Create a new API Key and restrict it to the Google Maps APIs you plan to use (e.g., Maps JavaScript API).
48+
5. Copy your `GOOGLE_MAPS_API_KEY` and make sure to keep it secure.

integrations/mobility-integrations/poetry.lock

-1,790
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"title": "Mobility Integrations",
3-
"description": "This contains examples of mobility integrations using two agents: `ev_charger` and `geoapi_car_parking`",
3+
"description": "This contains examples of mobility integrations using few agents: `ev_charger` , `car_service` ,`car_wash`, `restaurants`, `geocode` and `geoapi_car_parking`",
44
"categories": ["Mobility", "Geocoding"]
55
}

integrations/mobility-integrations/pyproject.toml

-13
This file was deleted.

integrations/mobility-integrations/src/__init__.py

Whitespace-only changes.

integrations/mobility-integrations/src/agents/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from ai_engine import UAgentResponse, UAgentResponseType, BookingRequest
2+
3+
4+
def booking_proto():
5+
protocol = Protocol("BookingProtocol")
6+
7+
@protocol.on_message(model=BookingRequest, replies={UAgentResponse})
8+
async def booking_handler(ctx: Context, sender: str, msg: BookingRequest):
9+
ctx.logger.info(f"Received booking request from {sender}")
10+
try:
11+
option = ctx.storage.get(msg.request_id)
12+
await ctx.send(
13+
sender,
14+
UAgentResponse(
15+
message=f"Thanks for choosing an option - {option[msg.user_response]}.",
16+
type=UAgentResponseType.FINAL,
17+
request_id=msg.request_id
18+
)
19+
)
20+
except Exception as exc:
21+
ctx.logger.error(exc)
22+
await ctx.send(
23+
sender,
24+
UAgentResponse(
25+
message=str(exc),
26+
type=UAgentResponseType.ERROR
27+
)
28+
)
29+
30+
return protocol
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Here we demonstrate how we can create a DeltaV compatible agent responsible for getting Car Service from Static Data.
2+
# After running this agent, it can be registered to DeltaV on Agentverse's Services tab. For registration,
3+
# you will have to use the agent's address.
4+
#
5+
# third party modules used in this example
6+
import json
7+
import uuid
8+
9+
from ai_engine import KeyValue, UAgentResponse, UAgentResponseType
10+
from pydantic import Field
11+
12+
# modules from booking_protocol.py
13+
from booking_protocol import booking_proto
14+
from car_service_data import CAMBRIDGE_CAR_SERVICE, MUNICH_CAR_SERVICE, PRAGUE_CAR_SERVICE, STUTTGART_CAR_SERVICE
15+
16+
17+
class CarServiceRequest(Model):
18+
latitude: float = Field(
19+
description="Describes the latitude where the user wants a Car Service Center. this shouldn't be the user "
20+
"location, but location of the place user specified.")
21+
longitude: float = Field(
22+
description="Describes the longitude where the user wants a Car Service Center. this shouldn't be the user "
23+
"location, but the location of the place the user specified.")
24+
miles_radius: float = Field(
25+
description="Distance in miles, the maximum distance b/w car service center and the location provided by user.")
26+
27+
28+
car_service_center_protocol = Protocol("Car Service Center")
29+
30+
31+
def get_data(latitude, longitude, miles_radius) -> list or None:
32+
"""
33+
Function to get the data from Car Service Center json
34+
Args:
35+
latitude (float): The latitude coordinate.
36+
longitude (float): The longitude coordinate.
37+
miles_radius (float): The radius in miles for searching Car Service Center.
38+
Return:
39+
list or None: A list of Car Service Center data.
40+
"""
41+
car_service_json = []
42+
if int(latitude) == 50 and int(longitude) == 14:
43+
car_service_json = PRAGUE_CAR_SERVICE
44+
elif int(latitude) == 48 and int(longitude) == 11:
45+
car_service_json = MUNICH_CAR_SERVICE
46+
elif int(latitude) == 52 and int(longitude) == 0:
47+
car_service_json = CAMBRIDGE_CAR_SERVICE
48+
else:
49+
car_service_json = STUTTGART_CAR_SERVICE
50+
response = car_service_json
51+
return [
52+
car_service
53+
for car_service in response
54+
if car_service["distance"] <= miles_radius
55+
]
56+
57+
58+
@car_service_center_protocol.on_message(model=CarServiceRequest, replies=UAgentResponse)
59+
async def on_message(ctx: Context, sender: str, msg: CarServiceRequest):
60+
ctx.logger.info(f"Received message from {sender}")
61+
try:
62+
data = get_data(msg.latitude, msg.longitude, msg.miles_radius)
63+
request_id = str(uuid.uuid4())
64+
options = []
65+
ctx_storage = {}
66+
for idx, o in enumerate(data):
67+
option = f"""This is Car Service Center: {o['name']} which is located {o['distance']} miles away from your location """
68+
options.append(KeyValue(key=idx, value=option))
69+
ctx_storage[idx] = option
70+
ctx.storage.set(request_id, ctx_storage)
71+
if options:
72+
await ctx.send(
73+
sender,
74+
UAgentResponse(
75+
options=options,
76+
type=UAgentResponseType.SELECT_FROM_OPTIONS,
77+
request_id=request_id
78+
)
79+
)
80+
else:
81+
await ctx.send(
82+
sender,
83+
UAgentResponse(
84+
message="No car service center are available for this context",
85+
type=UAgentResponseType.FINAL,
86+
request_id=request_id
87+
)
88+
)
89+
except Exception as exc:
90+
ctx.logger.error(exc)
91+
await ctx.send(
92+
sender,
93+
UAgentResponse(
94+
message=str(exc),
95+
type=UAgentResponseType.ERROR
96+
)
97+
)
98+
99+
100+
agent.include(car_service_center_protocol)
101+
agent.include(booking_proto())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
CAMBRIDGE_CAR_SERVICE = [
2+
{
3+
"name": "Halfords Autocentre",
4+
"car_service_slot": "4",
5+
"status": "reserved",
6+
"latitude": 52.212930,
7+
"longitude": 0.156800,
8+
"distance": 1
9+
},
10+
{
11+
"name": "National Tyres and Autocare",
12+
"car_service_slot": "2",
13+
"status": "free",
14+
"latitude": 52.214740,
15+
"longitude": 0.126480,
16+
"distance": 1
17+
},
18+
{
19+
"name": "Formula One Autocentres",
20+
"car_service_slot": "1",
21+
"status": "reserved",
22+
"latitude": 52.208320,
23+
"longitude": 0.134310,
24+
"distance": 2
25+
},
26+
{
27+
"name": "Rapid Fit",
28+
"car_service_slot": "5",
29+
"status": "free",
30+
"latitude": 52.211210,
31+
"longitude": 0.147250,
32+
"distance": 3
33+
},
34+
{
35+
"name": "Cambridge Garage",
36+
"car_service_slot": "4",
37+
"status": "free",
38+
"latitude": 52.205840,
39+
"longitude": 0.163650,
40+
"distance": 4
41+
}
42+
]
43+
MUNICH_CAR_SERVICE = [
44+
{
45+
"name": "Autohaus Bader GmbH",
46+
"car_service_slot": "4",
47+
"status": "reserved",
48+
"latitude": 48.190000,
49+
"longitude": 11.518410,
50+
"distance": 1
51+
},
52+
{
53+
"name": "BMW AG Niederlassung München",
54+
"car_service_slot": "2",
55+
"status": "free",
56+
"latitude": 48.188019,
57+
"longitude": 11.574240,
58+
"distance": 1
59+
},
60+
{
61+
"name": "Audi Zentrum München",
62+
"car_service_slot": "1",
63+
"status": "reserved",
64+
"latitude": 48.118580,
65+
"longitude": 11.540230,
66+
"distance": 2
67+
},
68+
{
69+
"name": "Mercedes-Benz Niederlassung München",
70+
"car_service_slot": "5",
71+
"status": "free",
72+
"latitude": 48.141230,
73+
"longitude": 11.412370,
74+
"distance": 3
75+
},
76+
{
77+
"name": "Volkswagen Zentrum München",
78+
"car_service_slot": "4",
79+
"status": "free",
80+
"latitude": 48.141230,
81+
"longitude": 11.412370,
82+
"distance": 4
83+
}
84+
]
85+
PRAGUE_CAR_SERVICE = [
86+
{
87+
"name": "Autohaus Bader GmbH",
88+
"car_service_slot": "4",
89+
"status": "reserved",
90+
"latitude": 48.190000,
91+
"longitude": 11.518410,
92+
"distance": 1
93+
},
94+
{
95+
"name": "BMW AG Niederlassung München",
96+
"car_service_slot": "2",
97+
"status": "free",
98+
"latitude": 48.188019,
99+
"longitude": 11.574240,
100+
"distance": 1
101+
},
102+
{
103+
"name": "Audi Zentrum München",
104+
"car_service_slot": "1",
105+
"status": "reserved",
106+
"latitude": 48.118580,
107+
"longitude": 11.540230,
108+
"distance": 2
109+
},
110+
{
111+
"name": "Mercedes-Benz Niederlassung München",
112+
"car_service_slot": "5",
113+
"status": "free",
114+
"latitude": 48.141230,
115+
"longitude": 11.412370,
116+
"distance": 3
117+
},
118+
{
119+
"name": "Volkswagen Zentrum München",
120+
"car_service_slot": "4",
121+
"status": "free",
122+
"latitude": 48.141230,
123+
"longitude": 11.412370,
124+
"distance": 4
125+
}
126+
]
127+
STUTTGART_CAR_SERVICE = [
128+
{
129+
"name": "A.T.U Auto-Teile-Unger",
130+
"car_service_slot": "4",
131+
"status": "reserved",
132+
"latitude": 48.783333,
133+
"longitude": 9.183333,
134+
"distance": 1
135+
},
136+
{
137+
"name": "Pneuhage Reifendienste",
138+
"car_service_slot": "2",
139+
"status": "free",
140+
"latitude": 48.755749,
141+
"longitude": 9.190182,
142+
"distance": 1
143+
},
144+
{
145+
"name": "Reifen Wagner GmbH",
146+
"car_service_slot": "1",
147+
"status": "reserved",
148+
"latitude": 48.838140,
149+
"longitude": 9.190880,
150+
"distance": 2
151+
},
152+
{
153+
"name": "Pneuhage Reifendienste",
154+
"car_service_slot": "5",
155+
"status": "free",
156+
"latitude": 48.726530,
157+
"longitude": 9.145400,
158+
"distance": 3
159+
},
160+
{
161+
"name": "Kfz-Werkstatt Lueg GmbH",
162+
"car_service_slot": "4",
163+
"status": "free",
164+
"latitude": 48.767830,
165+
"longitude": 9.169160,
166+
"distance": 4
167+
}
168+
]

0 commit comments

Comments
 (0)