Skip to content

Commit

Permalink
Rebase master
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandofcampos committed Jan 23, 2025
1 parent 6c31561 commit ef08d19
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 1,369 deletions.

This file was deleted.

2 changes: 1 addition & 1 deletion cdp-agentkit-core/python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
### Added

- Added `wrap_eth` action to wrap ETH to WETH on Base.
- Added support for Allora Chain machine learning (`get_price_prediction` and `get_all_topics` actions).
- Added support for Allora Chain machine learning (`get_price_inference` and `get_all_topics` actions).

## [0.0.7] - 2025-01-08

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from cdp_agentkit_core.actions.allora.get_all_topics import GetAllTopicsAction
from cdp_agentkit_core.actions.allora.get_price_inference import GetPriceInferenceAction
from cdp_agentkit_core.actions.cdp_action import CdpAction
from cdp_agentkit_core.actions.deploy_nft import DeployNftAction
from cdp_agentkit_core.actions.deploy_token import DeployTokenAction
Expand Down Expand Up @@ -54,4 +56,6 @@ def get_all_cdp_actions() -> list[type[CdpAction]]:
"MorphoWithdrawAction",
"PythFetchPriceFeedIDAction",
"PythFetchPriceAction",
"GetPriceInferenceAction",
"GetAllTopicsAction",
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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
from cdp_agentkit_core.actions.allora.get_price_inference import GetPriceInferenceAction


def get_all_allora_actions() -> list[type[AlloraAction]]:
Expand All @@ -15,6 +15,6 @@ def get_all_allora_actions() -> list[type[AlloraAction]]:

__all__ = [
"ALLORA_ACTIONS",
"GetPricePredictionAction",
"GetPriceInferenceAction",
"GetAllTopicsAction",
]
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_INFERENCE_PROMPT = """
This tool will get the future price inference for a given crypto asset from Allora Network.
It takes the crypto asset and timeframe as inputs.
"""


class GetPriceInferenceInput(BaseModel):
"""Input argument schema for get price inference action."""

token: str = Field(
..., description="The crypto asset to get the price inference for, e.g. `BTC`"
)
timeframe: str = Field(
..., description="The timeframe to get the price inference for, e.g. `5m` or `8h`"
)


async def get_price_inference(client: AlloraAPIClient, token: str, timeframe: str) -> str:
"""Get the future price inference for a given crypto asset from Allora Network.
Args:
client (AlloraAPIClient): The Allora API client.
token (str): The crypto asset to get the price inference for, e.g. `BTC`
timeframe (str): The timeframe to get the price inference for, e.g. `5m` or `8h`
Returns:
str: The future price inference for the given crypto asset
"""
try:
price_inference = await client.get_price_prediction(token, timeframe)
return f"The future price inference for {token} in {timeframe} is {price_inference.inference_data.network_inference_normalized}"
except Exception as e:
return f"Error getting price inference: {e}"


class GetPriceInferenceAction(AlloraAction):
"""Get price inference action."""

name: str = "get_price_inference"
description: str = GET_PRICE_INFERENCE_PROMPT
args_schema: type[BaseModel] | None = GetPriceInferenceInput
func: Callable[..., str] = get_price_inference
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,15 @@
class MorphoDepositInput(BaseModel):
"""Input schema for Morpho Vault deposit action."""

assets: str = Field(
...,
description="The quantity of assets to deposit, in whole units"
)
assets: str = Field(..., description="The quantity of assets to deposit, in whole units")
receiver: str = Field(
...,
description="The address that will own the position on the vault which will receive the shares"
description="The address that will own the position on the vault which will receive the shares",
)
token_address: str = Field(
...,
description="The address of the assets token to approve for deposit"
)
vault_address: str = Field(
...,
description="The address of the Morpho Vault to deposit to"
..., description="The address of the assets token to approve for deposit"
)
vault_address: str = Field(..., description="The address of the Morpho Vault to deposit to")


DEPOSIT_PROMPT = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,9 @@
class MorphoWithdrawInput(BaseModel):
"""Input schema for Morpho Vault withdraw action."""

vault_address: str = Field(
...,
description="The address of the Morpho Vault to withdraw from"
)
assets: str = Field(
...,
description="The amount of assets to withdraw in atomic units"
)
receiver: str = Field(
...,
description="The address to receive the withdrawn assets"
)
vault_address: str = Field(..., description="The address of the Morpho Vault to withdraw from")
assets: str = Field(..., description="The amount of assets to withdraw in atomic units")
receiver: str = Field(..., description="The address to receive the withdrawn assets")


WITHDRAW_PROMPT = """
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import pytest

from cdp_agentkit_core.actions.allora.get_price_prediction import (
GetPricePredictionInput,
get_price_prediction,
from cdp_agentkit_core.actions.allora.get_price_inference import (
GetPriceInferenceInput,
get_price_inference,
)

MOCK_TOKEN = "BTC"
MOCK_TIMEFRAME = "5m"


def test_get_price_prediction_input_model_valid():
"""Test that GetPricePredictionInput accepts valid parameters."""
input_model = GetPricePredictionInput(
def test_get_price_inference_input_model_valid():
"""Test that GetPriceInferenceInput accepts valid parameters."""
input_model = GetPriceInferenceInput(
token=MOCK_TOKEN,
timeframe=MOCK_TIMEFRAME,
)
Expand All @@ -22,28 +22,28 @@ def test_get_price_prediction_input_model_valid():
assert input_model.timeframe == MOCK_TIMEFRAME


def test_get_price_prediction_input_model_missing_params():
"""Test that GetPricePredictionInput raises error when params are missing."""
def test_get_price_inference_input_model_missing_params():
"""Test that GetPriceInferenceInput raises error when params are missing."""
with pytest.raises(ValueError):
GetPricePredictionInput()
GetPriceInferenceInput()


@pytest.mark.asyncio
async def test_get_price_prediction_success():
"""Test successful price prediction with valid parameters."""
async def test_get_price_inference_success():
"""Test successful price inference with valid parameters."""
mock_inference = Mock()
mock_inference.inference_data.network_inference_normalized = "50000.00"

with patch(
"cdp_agentkit_core.actions.allora.get_price_prediction.AlloraAPIClient"
"cdp_agentkit_core.actions.allora.get_price_inference.AlloraAPIClient"
) as mock_client:
mock_client_instance = mock_client.return_value
mock_client_instance.get_price_prediction = AsyncMock(return_value=mock_inference)

result = await get_price_prediction(mock_client_instance, MOCK_TOKEN, MOCK_TIMEFRAME)
result = await get_price_inference(mock_client_instance, MOCK_TOKEN, MOCK_TIMEFRAME)

expected_response = (
f"The future price prediction for {MOCK_TOKEN} in {MOCK_TIMEFRAME} is 50000.00"
f"The future price inference for {MOCK_TOKEN} in {MOCK_TIMEFRAME} is 50000.00"
)
assert result == expected_response

Expand All @@ -53,17 +53,17 @@ async def test_get_price_prediction_success():


@pytest.mark.asyncio
async def test_get_price_prediction_api_error():
"""Test price prediction when API error occurs."""
async def test_get_price_inference_api_error():
"""Test price inference when API error occurs."""
with patch(
"cdp_agentkit_core.actions.allora.get_price_prediction.AlloraAPIClient"
"cdp_agentkit_core.actions.allora.get_price_inference.AlloraAPIClient"
) as mock_client:
mock_client_instance = mock_client.return_value
mock_client_instance.get_price_prediction.side_effect = Exception("API error")

result = await get_price_prediction(mock_client_instance, MOCK_TOKEN, MOCK_TIMEFRAME)
result = await get_price_inference(mock_client_instance, MOCK_TOKEN, MOCK_TIMEFRAME)

expected_response = "Error getting price prediction: API error"
expected_response = "Error getting price inference: API error"
assert result == expected_response

mock_client_instance.get_price_prediction.assert_called_once_with(
Expand Down
Loading

0 comments on commit ef08d19

Please sign in to comment.