diff --git a/skills/exchangerateapi/__init__.py b/skills/exchangerateapi/__init__.py new file mode 100644 index 00000000..aa273558 --- /dev/null +++ b/skills/exchangerateapi/__init__.py @@ -0,0 +1,7 @@ +# skills/currency_conversion/__init__.py +from .exchange_rate_api import ExchangeRateAPISkill + +def get_skills(config): + return [ + ExchangeRateAPISkill(api_key=config["api_key"]) + ] diff --git a/skills/exchangerateapi/base.py b/skills/exchangerateapi/base.py new file mode 100644 index 00000000..35ad1359 --- /dev/null +++ b/skills/exchangerateapi/base.py @@ -0,0 +1,6 @@ +# skills/currency_conversion/base.py +from intentkit.skills.base_skill import BaseSkill + +class CurrencyConversionSkill(BaseSkill): + def convert(self, amount: float, from_currency: str, to_currency: str) -> float: + raise NotImplementedError("This method must be implemented by subclasses.") diff --git a/skills/exchangerateapi/exchange_rate_api.py b/skills/exchangerateapi/exchange_rate_api.py new file mode 100644 index 00000000..78c70f09 --- /dev/null +++ b/skills/exchangerateapi/exchange_rate_api.py @@ -0,0 +1,18 @@ +# skills/currency_conversion/exchange_rate_api.py +import requests +from .base import CurrencyConversionSkill + +class ExchangeRateAPISkill(CurrencyConversionSkill): + def __init__(self, api_key: str): + self.api_key = api_key + + def convert(self, amount: float, from_currency: str, to_currency: str) -> float: + url = f"https://v6.exchangerate-api.com/v6/{self.api_key}/pair/{from_currency}/{to_currency}" + response = requests.get(url) + data = response.json() + + if response.status_code != 200 or 'conversion_rate' not in data: + raise ValueError("Failed to retrieve conversion rate.") + + rate = data['conversion_rate'] + return amount * rate diff --git a/skills/exchangerateapi/exchangerateapi.png b/skills/exchangerateapi/exchangerateapi.png new file mode 100644 index 00000000..3640feee Binary files /dev/null and b/skills/exchangerateapi/exchangerateapi.png differ diff --git a/skills/exchangerateapi/schema.json b/skills/exchangerateapi/schema.json new file mode 100644 index 00000000..72aba7ac --- /dev/null +++ b/skills/exchangerateapi/schema.json @@ -0,0 +1,34 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "title": "Currency Conversion Skills", + "description": "Convert between any two currencies (e.g., USD to EUR, BTC to NGN) using the ExchangeRate-API.", + "x-icon": "https://ai.service.crestal.dev/skills/exchangerateapi/exchangerateapi.png", + "x-api-key": "required", + "properties": { + "enabled": { + "type": "boolean", + "title": "Enabled", + "description": "Whether this skill category is enabled", + "default": false + }, + "states": { + "type": "object", + "properties": { + "convert_currency": { + "type": "string", + "enum": ["disabled", "public", "private"], + "x-enum-title": [ + "Disabled", + "Agent Owner + All Users", + "Agent Owner Only" + ], + "description": "Convert one currency to another using real-time exchange rates.", + "default": "disabled" + } + }, + "description": "Skill states: enable or restrict access to individual conversion tasks." + } + }, + "required": ["states", "enabled"] +}