Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions skills/exchangerateapi/__init__.py
Original file line number Diff line number Diff line change
@@ -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"])
]
6 changes: 6 additions & 0 deletions skills/exchangerateapi/base.py
Original file line number Diff line number Diff line change
@@ -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.")
18 changes: 18 additions & 0 deletions skills/exchangerateapi/exchange_rate_api.py
Original file line number Diff line number Diff line change
@@ -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
Binary file added skills/exchangerateapi/exchangerateapi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions skills/exchangerateapi/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"title": "Currency Conversion Skill Configuration",
"type": "object",
"required": ["api_key"],
"properties": {
"api_key": {
"type": "string",
"description": "Your API key for ExchangeRate-API."
}
}
}