-
Notifications
You must be signed in to change notification settings - Fork 687
Add exchangerateapi skill using ExchangeRate-API #462
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
Open
0xnald
wants to merge
3
commits into
crestalnetwork:main
Choose a base branch
from
0xnald:feature/exchangerateapi-skill
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.