Add wallet toolkit
Browse files- chatxbt-assistant.py +2 -0
- src/tools/crypto_wallet_toolkit.py +61 -0
chatxbt-assistant.py
CHANGED
|
@@ -11,6 +11,7 @@ from phi.tools.yfinance import YFinanceTools
|
|
| 11 |
from src.databases.postgres import sqlalchemy_engine
|
| 12 |
from src.tools.crypto_swap_toolkit import CryptoSwapTools
|
| 13 |
from src.tools.crypto_data_toolkit import CryptoDataTools
|
|
|
|
| 14 |
from phi.storage.assistant.postgres import PgAssistantStorage
|
| 15 |
from src.knowledge_bases.combined import knowledge_base
|
| 16 |
|
|
@@ -68,6 +69,7 @@ async def start():
|
|
| 68 |
DuckDuckGo(),
|
| 69 |
CryptoDataTools(),
|
| 70 |
CryptoSwapTools(),
|
|
|
|
| 71 |
YFinanceTools(stock_price=True)
|
| 72 |
],
|
| 73 |
show_tool_calls= is_dev_mode,
|
|
|
|
| 11 |
from src.databases.postgres import sqlalchemy_engine
|
| 12 |
from src.tools.crypto_swap_toolkit import CryptoSwapTools
|
| 13 |
from src.tools.crypto_data_toolkit import CryptoDataTools
|
| 14 |
+
from src.tools.crypto_wallet_toolkit import CryptoWalletTools
|
| 15 |
from phi.storage.assistant.postgres import PgAssistantStorage
|
| 16 |
from src.knowledge_bases.combined import knowledge_base
|
| 17 |
|
|
|
|
| 69 |
DuckDuckGo(),
|
| 70 |
CryptoDataTools(),
|
| 71 |
CryptoSwapTools(),
|
| 72 |
+
CryptoWalletTools(),
|
| 73 |
YFinanceTools(stock_price=True)
|
| 74 |
],
|
| 75 |
show_tool_calls= is_dev_mode,
|
src/tools/crypto_wallet_toolkit.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
from phi.tools import Toolkit
|
| 3 |
+
from phi.utils.log import logger
|
| 4 |
+
from src.libs.rpc_client import rpc_call
|
| 5 |
+
|
| 6 |
+
class CryptoWalletTools(Toolkit):
|
| 7 |
+
def __init__(self):
|
| 8 |
+
super().__init__(name="crypto_wallet_tools")
|
| 9 |
+
|
| 10 |
+
# Registering methods to make them accessible via the toolkit
|
| 11 |
+
self.register(self.create_crypto_wallet)
|
| 12 |
+
|
| 13 |
+
def create_crypto_wallet(self, user_email: str) -> str:
|
| 14 |
+
"""
|
| 15 |
+
Creates a crypto wallet account for the given user email.
|
| 16 |
+
|
| 17 |
+
Parameters:
|
| 18 |
+
user_email (str): The email of the user for whom the wallet is being created.
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
str: A string representation of the response from the RPC call.
|
| 22 |
+
|
| 23 |
+
Raises:
|
| 24 |
+
None
|
| 25 |
+
|
| 26 |
+
Note:
|
| 27 |
+
This method uses asyncio.run() to run the asynchronous RPC call.
|
| 28 |
+
"""
|
| 29 |
+
logger.info(f"Creating crypto wallet account for {user_email}")
|
| 30 |
+
|
| 31 |
+
params = {
|
| 32 |
+
'userEmail': user_email,
|
| 33 |
+
}
|
| 34 |
+
response = asyncio.run(rpc_call(method_name="createLocalWallet", params=params))
|
| 35 |
+
return f"{response}"
|
| 36 |
+
|
| 37 |
+
def get_crypto_wallet(self, user_email: str) -> str:
|
| 38 |
+
"""
|
| 39 |
+
Fetches the crypto wallet account for the given user email.
|
| 40 |
+
|
| 41 |
+
Parameters:
|
| 42 |
+
user_email (str): The email of the user for whom the wallet is being fetched.
|
| 43 |
+
|
| 44 |
+
Returns:
|
| 45 |
+
str: A string representation of the response from the RPC call.
|
| 46 |
+
|
| 47 |
+
Raises:
|
| 48 |
+
None
|
| 49 |
+
|
| 50 |
+
Note:
|
| 51 |
+
This method uses asyncio.run() to run the asynchronous RPC call.
|
| 52 |
+
"""
|
| 53 |
+
logger.info(f"Fetching crypto wallet account for {user_email}")
|
| 54 |
+
|
| 55 |
+
params = {
|
| 56 |
+
'userEmail': user_email,
|
| 57 |
+
}
|
| 58 |
+
response = asyncio.run(rpc_call(method_name="getLocalWallet", params=params))
|
| 59 |
+
return f"{response}"
|
| 60 |
+
|
| 61 |
+
|