-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c31561
commit 838c2f1
Showing
16 changed files
with
330 additions
and
1,426 deletions.
There are no files selected for viewing
50 changes: 0 additions & 50 deletions
50
cdp-agentkit-core/cdp_agentkit_core/actions/allora/get_price_prediction.py
This file was deleted.
Oops, something went wrong.
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
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
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
File renamed without changes.
File renamed without changes.
50 changes: 50 additions & 0 deletions
50
cdp-agentkit-core/python/cdp_agentkit_core/actions/allora/get_price_inference.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_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_inference(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 |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions
67
cdp-agentkit-core/python/tests/actions/allora/test_get_price_inference.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,67 @@ | ||
from unittest.mock import AsyncMock, Mock, patch | ||
|
||
import pytest | ||
|
||
from cdp_agentkit_core.actions.allora.get_price_inference import ( | ||
GetPriceInferenceInput, | ||
get_price_inference, | ||
) | ||
|
||
MOCK_TOKEN = "BTC" | ||
MOCK_TIMEFRAME = "5m" | ||
|
||
|
||
def test_get_price_inference_input_model_valid(): | ||
"""Test that GetPriceInferenceInput accepts valid parameters.""" | ||
input_model = GetPriceInferenceInput( | ||
token=MOCK_TOKEN, | ||
timeframe=MOCK_TIMEFRAME, | ||
) | ||
|
||
assert input_model.token == MOCK_TOKEN | ||
assert input_model.timeframe == MOCK_TIMEFRAME | ||
|
||
|
||
def test_get_price_inference_input_model_missing_params(): | ||
"""Test that GetPriceInferenceInput raises error when params are missing.""" | ||
with pytest.raises(ValueError): | ||
GetPriceInferenceInput() | ||
|
||
|
||
@pytest.mark.asyncio | ||
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_inference.AlloraAPIClient" | ||
) as mock_client: | ||
mock_client_instance = mock_client.return_value | ||
mock_client_instance.get_price_inference = AsyncMock(return_value=mock_inference) | ||
|
||
result = await get_price_inference(mock_client_instance, MOCK_TOKEN, MOCK_TIMEFRAME) | ||
|
||
expected_response = ( | ||
f"The future price inference for {MOCK_TOKEN} in {MOCK_TIMEFRAME} is 50000.00" | ||
) | ||
assert result == expected_response | ||
|
||
mock_client_instance.get_price_inference.assert_called_once_with(MOCK_TOKEN, MOCK_TIMEFRAME) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_price_inference_api_error(): | ||
"""Test price inference when API error occurs.""" | ||
with patch( | ||
"cdp_agentkit_core.actions.allora.get_price_inference.AlloraAPIClient" | ||
) as mock_client: | ||
mock_client_instance = mock_client.return_value | ||
mock_client_instance.get_price_inference.side_effect = Exception("API error") | ||
|
||
result = await get_price_inference(mock_client_instance, MOCK_TOKEN, MOCK_TIMEFRAME) | ||
|
||
expected_response = "Error getting price inference: API error" | ||
assert result == expected_response | ||
|
||
mock_client_instance.get_price_inference.assert_called_once_with(MOCK_TOKEN, MOCK_TIMEFRAME) |
71 changes: 0 additions & 71 deletions
71
cdp-agentkit-core/tests/actions/allora/test_get_price_prediction.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.