Skip to content

Commit

Permalink
Adding mobility integrations (#239)
Browse files Browse the repository at this point in the history
Co-authored-by: pratrivedi <[email protected]>
Co-authored-by: josh <[email protected]>
  • Loading branch information
3 people authored Feb 23, 2024
1 parent 2a53106 commit 487c0a3
Show file tree
Hide file tree
Showing 25 changed files with 426 additions and 16 deletions.
3 changes: 2 additions & 1 deletion integrations/bert-base-uncased/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "Bert Base Uncased",
"description": "BERT base model (uncased) Pretrained model on English language using a masked language modeling (MLM) objective.",
"categories": ["Text Classification", "Hugging Face", "Text Generation"]
"categories": ["Text Classification", "Hugging Face", "Text Generation"],
"deltav": false
}
3 changes: 2 additions & 1 deletion integrations/blip-image-captioning-large/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "Blip Image Captioning Large",
"description": "BLIP integrations examples offer an easy-to-follow guide to setting up and using BLIP models",
"categories": ["Image Captioning", "Hugging Face"]
"categories": ["Image Captioning", "Hugging Face"],
"deltav": false
}
3 changes: 2 additions & 1 deletion integrations/business finder/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "Business Details Finder",
"description": "Business Finder integration that helps finding list of top 10 business according to category and city provided.",
"categories": ["Business Finder", "Business Details"]
"categories": ["Business Finder", "Business Details"],
"deltav": false
}
3 changes: 2 additions & 1 deletion integrations/distilgpt2/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "Distil Gpt 2",
"description": "DistilGPT2 integrations examples offer an easy-to-follow guide to setting up and using DistilGPT2 models",
"categories": ["Hugging Face", "Text Generation"]
"categories": ["Hugging Face", "Text Generation"],
"deltav": false
}
14 changes: 14 additions & 0 deletions integrations/ev_charger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 🌎 EV integrations examples 🚗

## geocode

This agent returns EV Chargers from the open chargemap API, requires lat/lon to get distance to EV charger.

#### OPENCHARGEMAP_API_KEY 🔌

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 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.
102 changes: 102 additions & 0 deletions integrations/ev_charger/ev_charger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Here we demonstrate how we can create a DeltaV compatible agent responsible for getting EV Chargers from the open
# chargemap API. 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 uuid
import requests
from ai_engine import KeyValue, UAgentResponse, UAgentResponseType
from pydantic import Field

# modules from booking_protocol.py
from booking_protocol import booking_proto


class EvRequest(Model):
latitude: float = Field(
description="Describes the latitude where the user wants an EV charger. This might not be the user current "
"location, if user specified a specific location on the objective.")
longitude: float = Field(
description="Describes the longitude where the user wants an EV charger. This might not be the user current "
"location, if user specified a specific location on the objective.")
miles_radius: float = Field(
description="Distance in miles, the maximum distance b/w ev charger and the location provided by user")


# To use this example, you will need to provide an API key for Openchargemap: https://api.openchargemap.io/
URL = "https://api.≈.io/v3/poi?"

API_KEY = "YOUR_API_KEY"

if API_KEY == "YOUR_API_KEY":
raise Exception("You need to provide an API key for Openchargemap to use this example")

MAX_RESULTS = 10

ev_charger_protocol = Protocol("EVCharger")


def get_data(latitude, longitude, miles_radius) -> list or None:
"""
Retrieves data from the open chargemap API for EV chargers.
Args:
latitude (float): The latitude coordinate.
longitude (float): The longitude coordinate.
miles_radius (float): The radius in miles for searching EV chargers.
Returns:
list or None: A list of EV charger data if successful, or None if the request fails.
"""
ev_charger_url = (
URL
+ f"maxresults={MAX_RESULTS}&latitude={latitude}&longitude={longitude}&distance={miles_radius}"
)
response = requests.get(url=ev_charger_url, headers={"x-api-key": API_KEY}, timeout=5)
if response.status_code == 200:
data = response.json()
return data
return []


@ev_charger_protocol.on_message(model=EvRequest, replies=UAgentResponse)
async def on_message(ctx: Context, sender: str, msg: EvRequest):
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"""● {o['AddressInfo']['Title']} , which is located {round(o['AddressInfo']['Distance'], 2)} miles from the 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 ev chargers 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(ev_charger_protocol)
6 changes: 6 additions & 0 deletions integrations/ev_charger/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"title": "Openchargemap integration",
"description": "Agent integration with Openchargemap.",
"categories": ["mobility", "EV"],
"deltav": true
}
4 changes: 3 additions & 1 deletion integrations/fetch-ai-engine/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"title": "Fetch AI Engine",
"description": "This integration adds types required by AI-Engine to UAgents",
"categories": ["AI Engine"]
"categories": ["AI Engine"],
"deltav": false
}
}
4 changes: 3 additions & 1 deletion integrations/fetch-holiday/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"title": "Fetch Holiday",
"description": "This integration provides the top destination places",
"categories": ["Holiday Planner", "Travel"]
"categories": ["Holiday Planner", "Travel"],
"deltav": false
}
}
4 changes: 3 additions & 1 deletion integrations/finbert/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"title": "Finbert",
"description": "FinBERT is a pre-trained NLP model to analyze sentiment of financial text. It is built by further training the BERT language model in the finance domain, using a large financial corpus and thereby fine-tuning it for financial sentiment classification.",
"categories": ["Financial Sentiment Analysis", "Financial News Analysis","Hugging Face"]
"categories": ["Financial Sentiment Analysis", "Financial News Analysis","Hugging Face"],
"deltav": false
}
}
4 changes: 3 additions & 1 deletion integrations/flights_data_integration/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"title": "Live Flight Status",
"description": "This integration helps user to track current status of flights.",
"categories": ["Live Flight Data", "Flight Status"]
"categories": ["Live Flight Data", "Flight Status"],
"deltav": false
}
}
4 changes: 3 additions & 1 deletion integrations/gemini_AI_integration/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"title": "Google Gemini Integration",
"description": "This integration helps to have chat conversation with Google Gemini Generative AI",
"categories": ["Generative AI", "Google Gemini"]
"categories": ["Generative AI", "Google Gemini"],
"deltav": false
}
}
13 changes: 13 additions & 0 deletions integrations/geocode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 🌎 geocode integrations examples 🚴

## geocode

This agent takes an address as input and returns latitude and longitude of the given address.

#### GOOGLE_MAPS_API_KEY 🗺️

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
85 changes: 85 additions & 0 deletions integrations/geocode/geocode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Here we demonstrate how we can create a DeltaV compatible agent responsible for getting Geo Coordinates from the
# Google Map API. 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 uuid
from typing import Tuple
import requests
from ai_engine import UAgentResponse, UAgentResponseType
from pydantic import Field


class GeoCode(Model):
address: str = Field(description="Address of a location to find lat and long of.")


URL = "https://maps.googleapis.com/maps/api/geocode/json"

API_KEY = "YOUR_API_KEY"

if API_KEY == "YOUR_API_KEY":
raise Exception("You need to provide an API key for Google Maps API to use this example")

geocode_protocol = Protocol("GeoCode")


def get_data(address: str) -> Tuple or None:
"""
Returns the latitude and longitude of a location using the Google Maps Geocoding API.
Args:
address (str): The address of the location.
Returns:
tuple: A tuple containing the latitude and longitude of the location.
"""
query_params = {"key": f"{API_KEY}", "address": f"{address}"}
response = requests.get(URL, params=query_params)
data = response.json()
if data['status'] == 'OK':
latitude = data['results'][0]['geometry']['location']['lat']
longitude = data['results'][0]['geometry']['location']['lng']
return latitude, longitude
else:
return None


@geocode_protocol.on_message(model=GeoCode, replies=UAgentResponse)
async def on_message(ctx: Context, sender: str, msg: GeoCode):
ctx.logger.info(f"Received message from {sender}.")
try:
data = get_data(msg.address)
request_id = str(uuid.uuid4())
latitude, longitude = data
option = f"""Location for {msg.address} is: \nlatitude={latitude}, longitude={longitude}"""
ctx.storage.set(request_id, option)
if latitude and longitude:
await ctx.send(
sender,
UAgentResponse(
message=option,
type=UAgentResponseType.FINAL,
request_id=request_id
),
)
else:
await ctx.send(
sender,
UAgentResponse(
message="No geo coordinates 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(geocode_protocol)
6 changes: 6 additions & 0 deletions integrations/geocode/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"title": "maps.googleapis integration",
"description": "Utilise Google apis to bring maps to your agents.",
"categories": ["mobility", "google"],
"deltav": true
}
13 changes: 13 additions & 0 deletions integrations/geopy_car_parking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 🌎 Geoapify integrations examples 🚴

## geocode

This agent retruns car parking availabiloty at a given location.

#### GEOAPI_API_KEY 🗺️

1. Go to the Geoapify website: https://www.geoapify.com/.
2. Sign in to your Google account or create a new one if you don't have an existing account.
3. Once you are logged in, create a new project by clicking on the "Add a new project" button under the Projects section.
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.
Loading

0 comments on commit 487c0a3

Please sign in to comment.