Add pin rpc methods
Browse files
chatxbt-assistant.py
CHANGED
|
@@ -12,6 +12,7 @@ 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_evm_wallet_toolkit import CryptoEVMWalletTools
|
|
|
|
| 15 |
from src.tools.user_profile_toolkit import UserProfileToolkit
|
| 16 |
from phi.storage.assistant.postgres import PgAssistantStorage
|
| 17 |
from src.knowledge_bases.combined import knowledge_base
|
|
@@ -93,6 +94,7 @@ async def start():
|
|
| 93 |
CryptoDataTools(),
|
| 94 |
CryptoSwapTools(),
|
| 95 |
CryptoEVMWalletTools(),
|
|
|
|
| 96 |
YFinanceTools(stock_price=True)
|
| 97 |
],
|
| 98 |
show_tool_calls=is_dev_mode,
|
|
|
|
| 12 |
from src.tools.crypto_swap_toolkit import CryptoSwapTools
|
| 13 |
from src.tools.crypto_data_toolkit import CryptoDataTools
|
| 14 |
from src.tools.crypto_evm_wallet_toolkit import CryptoEVMWalletTools
|
| 15 |
+
from src.tools.user_confirmation_pin_toolkit import UserConfirmationPinToolkit
|
| 16 |
from src.tools.user_profile_toolkit import UserProfileToolkit
|
| 17 |
from phi.storage.assistant.postgres import PgAssistantStorage
|
| 18 |
from src.knowledge_bases.combined import knowledge_base
|
|
|
|
| 94 |
CryptoDataTools(),
|
| 95 |
CryptoSwapTools(),
|
| 96 |
CryptoEVMWalletTools(),
|
| 97 |
+
UserConfirmationPinToolkit(),
|
| 98 |
YFinanceTools(stock_price=True)
|
| 99 |
],
|
| 100 |
show_tool_calls=is_dev_mode,
|
src/tools/user_confirmation_pin_toolkit.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import chainlit as cl
|
| 3 |
+
from phi.tools import Toolkit
|
| 4 |
+
from phi.utils.log import logger
|
| 5 |
+
|
| 6 |
+
from src.libs.rpc_client import rpc_call
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class UserConfirmationPinToolkit(Toolkit):
|
| 10 |
+
def __init__(self):
|
| 11 |
+
super().__init__(name="user_confirmation_pin_toolkit")
|
| 12 |
+
|
| 13 |
+
# Registering methods to make them accessible via the toolkit
|
| 14 |
+
self.register(self.has_user_confirmation_pin)
|
| 15 |
+
self.register(self.set_user_confirmation_pin)
|
| 16 |
+
self.register(self.update_user_confirmation_pin)
|
| 17 |
+
self.register(self.verify_user_confirmation_pin)
|
| 18 |
+
|
| 19 |
+
def has_user_confirmation_pin(self, user_id: str) -> str:
|
| 20 |
+
"""
|
| 21 |
+
Checks if a user has a confirmation PIN.
|
| 22 |
+
|
| 23 |
+
This method takes a user's ID and checks if the user has a confirmation
|
| 24 |
+
PIN via a remote procedure call (RPC).
|
| 25 |
+
|
| 26 |
+
Args:
|
| 27 |
+
user_id (str): The ID of the user to check for a confirmation PIN.
|
| 28 |
+
|
| 29 |
+
Returns:
|
| 30 |
+
str: The response from the RPC call indicating if the user has a PIN.
|
| 31 |
+
"""
|
| 32 |
+
logger.info("Checking if user has confirmation pin")
|
| 33 |
+
|
| 34 |
+
params = {
|
| 35 |
+
"userId": user_id,
|
| 36 |
+
}
|
| 37 |
+
response = asyncio.run(rpc_call(method_name="hasUserPin", params=params))
|
| 38 |
+
return f"{response}"
|
| 39 |
+
|
| 40 |
+
def set_user_confirmation_pin(self, user_id: str, pin: str) -> str:
|
| 41 |
+
"""
|
| 42 |
+
Sets a user's confirmation PIN.
|
| 43 |
+
|
| 44 |
+
This method takes a user's ID and a new PIN, and sets the user's PIN
|
| 45 |
+
via a remote procedure call (RPC).
|
| 46 |
+
|
| 47 |
+
Args:
|
| 48 |
+
user_id (str): The ID of the user whose PIN is to be set.
|
| 49 |
+
pin (str): The new confirmation PIN to be set.
|
| 50 |
+
|
| 51 |
+
Returns:
|
| 52 |
+
str: The response from the RPC call setting the PIN.
|
| 53 |
+
"""
|
| 54 |
+
logger.info("Setting user confirmation pin")
|
| 55 |
+
|
| 56 |
+
params = {
|
| 57 |
+
"userId": user_id,
|
| 58 |
+
"pin": pin
|
| 59 |
+
}
|
| 60 |
+
response = asyncio.run(rpc_call(method_name="setUserPin", params=params))
|
| 61 |
+
return f"{response}"
|
| 62 |
+
|
| 63 |
+
def update_user_confirmation_pin(self, user_id: str, pin: str) -> str:
|
| 64 |
+
"""
|
| 65 |
+
Updates a user's confirmation PIN.
|
| 66 |
+
|
| 67 |
+
This method takes a user's ID and a new PIN, and updates the user's PIN
|
| 68 |
+
via a remote procedure call (RPC).
|
| 69 |
+
|
| 70 |
+
Args:
|
| 71 |
+
user_id (str): The ID of the user whose PIN is to be updated.
|
| 72 |
+
pin (str): The new confirmation PIN to be set.
|
| 73 |
+
|
| 74 |
+
Returns:
|
| 75 |
+
str: The response from the RPC call updating the PIN.
|
| 76 |
+
"""
|
| 77 |
+
logger.info("Updating user confirmation pin")
|
| 78 |
+
|
| 79 |
+
params = {
|
| 80 |
+
"userId": user_id,
|
| 81 |
+
"pin": pin
|
| 82 |
+
}
|
| 83 |
+
response = asyncio.run(rpc_call(method_name="updateUserPin", params=params))
|
| 84 |
+
return f"{response}"
|
| 85 |
+
|
| 86 |
+
def verify_user_confirmation_pin(self, user_id: str, pin: str) -> str:
|
| 87 |
+
"""
|
| 88 |
+
Verifies a user's confirmation PIN.
|
| 89 |
+
|
| 90 |
+
This method takes a user's ID and a PIN, converts the email to lowercase,
|
| 91 |
+
and verifies the PIN via a remote procedure call (RPC).
|
| 92 |
+
|
| 93 |
+
Args:
|
| 94 |
+
user_id (str): The ID of the user whose PIN is to be verified.
|
| 95 |
+
pin (str): The confirmation PIN to be verified.
|
| 96 |
+
|
| 97 |
+
Returns:
|
| 98 |
+
str: The response from the RPC call verifying the PIN.
|
| 99 |
+
"""
|
| 100 |
+
logger.info("Verifying user confirmation pin")
|
| 101 |
+
|
| 102 |
+
params = {
|
| 103 |
+
"userId": user_id,
|
| 104 |
+
"pin": pin
|
| 105 |
+
}
|
| 106 |
+
response = asyncio.run(rpc_call(method_name="verifyUserPin", params=params))
|
| 107 |
+
return f"{response}"
|