Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add mobility agents on mobility integrations #235

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 17 additions & 31 deletions integrations/mobility-integrations/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# 🚗 uAgent Mobility Integrations Examples 🚴

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

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.

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.

3. `geocode`: This agent takes an address as input and returns latitude and longitude of the given address.

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.

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.

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.

## Getting Started 🚀

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

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

Expand All @@ -31,32 +39,10 @@ Before running the agents, you need to obtain the required API keys:
4. Give your project a name and click "OK" to create the new project.
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.

### Step 2: Set Environment Variables 🌐

Create a `.env` file in the `mobility-integrations` directory and export the obtained API keys as environment variables:

```bash
export OPENCHARGEMAP_API_KEY="{GET THE API KEY}"
export GEOAPI_API_KEY="{GET THE API KEY}"
```

### Step 3: Install Dependencies ⚙️

To use the environment variables from the `.env` file and install the project dependencies:

```bash
source .env
poetry install
```

### Step 4: Run the Project 🏃

To run the project and its agents:

```bash
cd src
poetry shell
python main.py
```
#### GOOGLE_MAPS_API_KEY 🗺️

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

This file was deleted.

2 changes: 1 addition & 1 deletion integrations/mobility-integrations/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "Mobility Integrations",
"description": "This contains examples of mobility integrations using two agents: `ev_charger` and `geoapi_car_parking`",
"description": "This contains examples of mobility integrations using few agents: `ev_charger` , `car_service` ,`car_wash`, `restaurants`, `geocode` and `geoapi_car_parking`",
"categories": ["Mobility", "Geocoding"]
}
13 changes: 0 additions & 13 deletions integrations/mobility-integrations/pyproject.toml

This file was deleted.

Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from ai_engine import UAgentResponse, UAgentResponseType, BookingRequest


def booking_proto():
protocol = Protocol("BookingProtocol")

@protocol.on_message(model=BookingRequest, replies={UAgentResponse})
async def booking_handler(ctx: Context, sender: str, msg: BookingRequest):
ctx.logger.info(f"Received booking request from {sender}")
try:
option = ctx.storage.get(msg.request_id)
await ctx.send(
sender,
UAgentResponse(
message=f"Thanks for choosing an option - {option[msg.user_response]}.",
type=UAgentResponseType.FINAL,
request_id=msg.request_id
)
)
except Exception as exc:
ctx.logger.error(exc)
await ctx.send(
sender,
UAgentResponse(
message=str(exc),
type=UAgentResponseType.ERROR
)
)

return protocol
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Here we demonstrate how we can create a DeltaV compatible agent responsible for getting Car Service from Static Data.
# After running this agent, it can be registered to DeltaV on Agentverse's Services tab. For registration,
# you will have to use the agent's address.
#
# third party modules used in this example
import json
import uuid

from ai_engine import KeyValue, UAgentResponse, UAgentResponseType
from pydantic import Field

# modules from booking_protocol.py
from booking_protocol import booking_proto
from car_service_data import CAMBRIDGE_CAR_SERVICE, MUNICH_CAR_SERVICE, PRAGUE_CAR_SERVICE, STUTTGART_CAR_SERVICE


class CarServiceRequest(Model):
latitude: float = Field(
description="Describes the latitude where the user wants a Car Service Center. this shouldn't be the user "
"location, but location of the place user specified.")
longitude: float = Field(
description="Describes the longitude where the user wants a Car Service Center. this shouldn't be the user "
"location, but the location of the place the user specified.")
miles_radius: float = Field(
description="Distance in miles, the maximum distance b/w car service center and the location provided by user.")


car_service_center_protocol = Protocol("Car Service Center")


def get_data(latitude, longitude, miles_radius) -> list or None:
"""
Function to get the data from Car Service Center json
Args:
latitude (float): The latitude coordinate.
longitude (float): The longitude coordinate.
miles_radius (float): The radius in miles for searching Car Service Center.
Return:
list or None: A list of Car Service Center data.
"""
car_service_json = []
if int(latitude) == 50 and int(longitude) == 14:
car_service_json = PRAGUE_CAR_SERVICE
elif int(latitude) == 48 and int(longitude) == 11:
car_service_json = MUNICH_CAR_SERVICE
elif int(latitude) == 52 and int(longitude) == 0:
car_service_json = CAMBRIDGE_CAR_SERVICE
else:
car_service_json = STUTTGART_CAR_SERVICE
response = car_service_json
return [
car_service
for car_service in response
if car_service["distance"] <= miles_radius
]


@car_service_center_protocol.on_message(model=CarServiceRequest, replies=UAgentResponse)
async def on_message(ctx: Context, sender: str, msg: CarServiceRequest):
ctx.logger.info(f"Received message from {sender}")
try:
data = get_data(msg.latitude, msg.longitude, msg.miles_radius)
request_id = str(uuid.uuid4())
options = []
ctx_storage = {}
for idx, o in enumerate(data):
option = f"""This is Car Service Center: {o['name']} which is located {o['distance']} miles away from your location """
options.append(KeyValue(key=idx, value=option))
ctx_storage[idx] = option
ctx.storage.set(request_id, ctx_storage)
if options:
await ctx.send(
sender,
UAgentResponse(
options=options,
type=UAgentResponseType.SELECT_FROM_OPTIONS,
request_id=request_id
)
)
else:
await ctx.send(
sender,
UAgentResponse(
message="No car service center are available for this context",
type=UAgentResponseType.FINAL,
request_id=request_id
)
)
except Exception as exc:
ctx.logger.error(exc)
await ctx.send(
sender,
UAgentResponse(
message=str(exc),
type=UAgentResponseType.ERROR
)
)


agent.include(car_service_center_protocol)
agent.include(booking_proto())
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
CAMBRIDGE_CAR_SERVICE = [
{
"name": "Halfords Autocentre",
"car_service_slot": "4",
"status": "reserved",
"latitude": 52.212930,
"longitude": 0.156800,
"distance": 1
},
{
"name": "National Tyres and Autocare",
"car_service_slot": "2",
"status": "free",
"latitude": 52.214740,
"longitude": 0.126480,
"distance": 1
},
{
"name": "Formula One Autocentres",
"car_service_slot": "1",
"status": "reserved",
"latitude": 52.208320,
"longitude": 0.134310,
"distance": 2
},
{
"name": "Rapid Fit",
"car_service_slot": "5",
"status": "free",
"latitude": 52.211210,
"longitude": 0.147250,
"distance": 3
},
{
"name": "Cambridge Garage",
"car_service_slot": "4",
"status": "free",
"latitude": 52.205840,
"longitude": 0.163650,
"distance": 4
}
]
MUNICH_CAR_SERVICE = [
{
"name": "Autohaus Bader GmbH",
"car_service_slot": "4",
"status": "reserved",
"latitude": 48.190000,
"longitude": 11.518410,
"distance": 1
},
{
"name": "BMW AG Niederlassung München",
"car_service_slot": "2",
"status": "free",
"latitude": 48.188019,
"longitude": 11.574240,
"distance": 1
},
{
"name": "Audi Zentrum München",
"car_service_slot": "1",
"status": "reserved",
"latitude": 48.118580,
"longitude": 11.540230,
"distance": 2
},
{
"name": "Mercedes-Benz Niederlassung München",
"car_service_slot": "5",
"status": "free",
"latitude": 48.141230,
"longitude": 11.412370,
"distance": 3
},
{
"name": "Volkswagen Zentrum München",
"car_service_slot": "4",
"status": "free",
"latitude": 48.141230,
"longitude": 11.412370,
"distance": 4
}
]
PRAGUE_CAR_SERVICE = [
{
"name": "Autohaus Bader GmbH",
"car_service_slot": "4",
"status": "reserved",
"latitude": 48.190000,
"longitude": 11.518410,
"distance": 1
},
{
"name": "BMW AG Niederlassung München",
"car_service_slot": "2",
"status": "free",
"latitude": 48.188019,
"longitude": 11.574240,
"distance": 1
},
{
"name": "Audi Zentrum München",
"car_service_slot": "1",
"status": "reserved",
"latitude": 48.118580,
"longitude": 11.540230,
"distance": 2
},
{
"name": "Mercedes-Benz Niederlassung München",
"car_service_slot": "5",
"status": "free",
"latitude": 48.141230,
"longitude": 11.412370,
"distance": 3
},
{
"name": "Volkswagen Zentrum München",
"car_service_slot": "4",
"status": "free",
"latitude": 48.141230,
"longitude": 11.412370,
"distance": 4
}
]
STUTTGART_CAR_SERVICE = [
{
"name": "A.T.U Auto-Teile-Unger",
"car_service_slot": "4",
"status": "reserved",
"latitude": 48.783333,
"longitude": 9.183333,
"distance": 1
},
{
"name": "Pneuhage Reifendienste",
"car_service_slot": "2",
"status": "free",
"latitude": 48.755749,
"longitude": 9.190182,
"distance": 1
},
{
"name": "Reifen Wagner GmbH",
"car_service_slot": "1",
"status": "reserved",
"latitude": 48.838140,
"longitude": 9.190880,
"distance": 2
},
{
"name": "Pneuhage Reifendienste",
"car_service_slot": "5",
"status": "free",
"latitude": 48.726530,
"longitude": 9.145400,
"distance": 3
},
{
"name": "Kfz-Werkstatt Lueg GmbH",
"car_service_slot": "4",
"status": "free",
"latitude": 48.767830,
"longitude": 9.169160,
"distance": 4
}
]
Loading
Loading