-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Allora Network machine learning price prediction to the CDP Agen…
…tKit
- Loading branch information
1 parent
638244c
commit 7f3a7e0
Showing
10 changed files
with
714 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
20 changes: 20 additions & 0 deletions
20
cdp-agentkit-core/cdp_agentkit_core/actions/allora/__init__.py
This file contains 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,20 @@ | ||
from cdp_agentkit_core.actions.allora.action import AlloraAction | ||
from cdp_agentkit_core.actions.allora.get_all_topics import GetAllTopicsAction | ||
from cdp_agentkit_core.actions.allora.get_price_prediction import GetPricePredictionAction | ||
|
||
|
||
def get_all_allora_actions() -> list[type[AlloraAction]]: | ||
actions = [] | ||
for action in AlloraAction.__subclasses__(): | ||
actions.append(action()) | ||
|
||
return actions | ||
|
||
|
||
ALLORA_ACTIONS = get_all_allora_actions() | ||
|
||
__all__ = [ | ||
"ALLORA_ACTIONS", | ||
"GetPricePredictionAction", | ||
"GetAllTopicsAction", | ||
] |
12 changes: 12 additions & 0 deletions
12
cdp-agentkit-core/cdp_agentkit_core/actions/allora/action.py
This file contains 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,12 @@ | ||
from collections.abc import Callable | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class AlloraAction(BaseModel): | ||
"""Allora Action Base Class.""" | ||
|
||
name: str | ||
description: str | ||
args_schema: type[BaseModel] | None = None | ||
func: Callable[..., str] |
38 changes: 38 additions & 0 deletions
38
cdp-agentkit-core/cdp_agentkit_core/actions/allora/get_all_topics.py
This file contains 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,38 @@ | ||
import json | ||
from collections.abc import Callable | ||
|
||
from allora_sdk.v2.api_client import AlloraAPIClient | ||
from pydantic import BaseModel | ||
|
||
from cdp_agentkit_core.actions.allora.action import AlloraAction | ||
|
||
GET_ALL_TOPICS_PROMPT = """ | ||
This tool will get all available topics from Allora Network. | ||
""" | ||
|
||
|
||
async def get_all_topics(client: AlloraAPIClient) -> str: | ||
"""Get all available topics from Allora Network. | ||
Args: | ||
client (AlloraAPIClient): The Allora API client. | ||
Returns: | ||
str: A list of available topics from Allora Network in JSON format | ||
""" | ||
try: | ||
topics = await client.get_all_topics() | ||
topics_json = json.dumps(topics, indent=4) | ||
return f"The available topics at Allora Network are:\n{topics_json}" | ||
except Exception as e: | ||
return f"Error getting all topics: {e}" | ||
|
||
|
||
class GetAllTopicsAction(AlloraAction): | ||
"""Get all topics action.""" | ||
|
||
name: str = "get_all_topics" | ||
description: str = GET_ALL_TOPICS_PROMPT | ||
args_schema: type[BaseModel] | None = None | ||
func: Callable[..., str] = get_all_topics |
50 changes: 50 additions & 0 deletions
50
cdp-agentkit-core/cdp_agentkit_core/actions/allora/get_price_prediction.py
This file contains 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,50 @@ | ||
from collections.abc import Callable | ||
|
||
from allora_sdk.v2.api_client import AlloraAPIClient | ||
from pydantic import BaseModel, Field | ||
|
||
from cdp_agentkit_core.actions.allora.action import AlloraAction | ||
|
||
GET_PRICE_PREDICTION_PROMPT = """ | ||
This tool will get the future price prediction for a given crypto asset from Allora Network. | ||
It takes the crypto asset and timeframe as inputs. | ||
""" | ||
|
||
|
||
class GetPricePredictionInput(BaseModel): | ||
"""Input argument schema for get price prediction action.""" | ||
|
||
token: str = Field( | ||
..., description="The crypto asset to get the price prediction for, e.g. `BTC`" | ||
) | ||
timeframe: str = Field( | ||
..., description="The timeframe to get the price prediction for, e.g. `5m` or `8h`" | ||
) | ||
|
||
|
||
async def get_price_prediction(client: AlloraAPIClient, token: str, timeframe: str) -> str: | ||
"""Get the future price prediction for a given crypto asset from Allora Network. | ||
Args: | ||
client (AlloraAPIClient): The Allora API client. | ||
token (str): The crypto asset to get the price prediction for, e.g. `BTC` | ||
timeframe (str): The timeframe to get the price prediction for, e.g. `5m` or `8h` | ||
Returns: | ||
str: The future price prediction for the given crypto asset | ||
""" | ||
try: | ||
price_prediction = await client.get_price_prediction(token, timeframe) | ||
return f"The future price prediction for {token} in {timeframe} is {price_prediction.inference_data.network_inference_normalized}" | ||
except Exception as e: | ||
return f"Error getting price prediction: {e}" | ||
|
||
|
||
class GetPricePredictionAction(AlloraAction): | ||
"""Get price prediction action.""" | ||
|
||
name: str = "get_price_prediction" | ||
description: str = GET_PRICE_PREDICTION_PROMPT | ||
args_schema: type[BaseModel] | None = GetPricePredictionInput | ||
func: Callable[..., str] = get_price_prediction |
Oops, something went wrong.