Skip to content

Commit 8cbbb47

Browse files
authored
Merge pull request #74 from pattern-tech/refactor/ai-v2
fix: Rename exceptions.py and update imports across codebase
2 parents ee26135 + 340a969 commit 8cbbb47

File tree

18 files changed

+73
-67
lines changed

18 files changed

+73
-67
lines changed

src/agentflow/providers/chain_scan_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def get_block_transactions(block_number: int, chain_id: str, output_include: Lis
405405
for result in transactions:
406406
final_results.append({item: result[item]
407407
for item in result.keys() if item in output_include})
408-
return final_results
408+
return str(final_results)
409409

410410

411411
@tool

src/agentflow/providers/moralis_tools.py

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,43 @@
1+
"""
2+
MORALIS API v2.2
3+
"""
14
import requests
25

3-
from typing import Any
46
from moralis import evm_api
57
from langchain.tools import tool
68

79
from src.util.configuration import Config
10+
from src.util.exceptions import NotSupportedError
811
from src.agentflow.utils.shared_tools import handle_exceptions
912

1013
_config = Config.get_config()
1114
_moralis_config = Config.get_service_config(_config, "MORALIS")
1215

13-
_MORALIS_URL = "https://deep-index.moralis.io/api/v2"
16+
_MORALIS_URL = "https://deep-index.moralis.io/api/v2.2"
1417

15-
@tool
16-
@handle_exceptions
17-
def get_wallet_active_chains(wallet_address: str, output_include: list[str]) -> list[dict[str, Any]]:
18-
"""
19-
Get active chains for a wallet address across all chains
20-
21-
Args:
22-
wallet_address (str): Ethereum wallet address
23-
output_include (list[str]):
24-
A list of field names to include in in the output.
25-
26-
27-
Returns:
28-
List[dict[str, Any]]:
29-
A list of dictionaries where each dictionary only contains the keys
30-
listed in `output_include` (if they exist in the source data).
31-
Possible fields include:
3218

33-
- chain, chain_id, first_transaction, last_transaction
19+
def check_chain_supported(chain: str) -> bool:
3420
"""
35-
params = {
36-
"address": wallet_address
37-
}
38-
39-
result = evm_api.wallets.get_wallet_active_chains(
40-
api_key=_moralis_config["api_key"],
41-
params=params,
42-
)
43-
44-
results = result["active_chains"]
45-
final_results = []
46-
for result in results:
47-
final_results.append({item: result[item]
48-
for item in result.keys() if item in output_include})
49-
return final_results
21+
Moralis supported chains in v2.2
22+
"""
23+
supported_chains = ["eth", "0x1", "polygon", "0x89", "bsc", "0x38", "avalanche", "0xa86a", "fantom", "0xfa", "palm", "0x2a15c308d", "cronos", "0x19", "arbitrum", "0xa4b1", "chiliz", "0x15b38",
24+
"gnosis", "0x64", "base", "0x2105", "optimism", "0xa", "linea", "0xe708", "moonbeam", "0x504", "moonriver", "0x505", "flow", "0x2eb", "ronin", "0x7e4", "lisk", "0x46f", "pulse", "0x171"]
25+
if chain in supported_chains:
26+
return True
27+
raise NotSupportedError(
28+
f"chain {chain} is not supported. supported chains are : {supported_chains}")
5029

5130

5231
@tool
5332
@handle_exceptions
54-
def get_wallet_token_balances(wallet_address: str, output_include: list[str], cursor: str = "") -> dict:
33+
def get_wallet_token_balances(wallet_address: str, chain: str, output_include: list[str], cursor: str = "") -> dict:
5534
"""
5635
Get token balances for a specific wallet address and their token prices in USD. (paginated)
5736
apply decimal conversion for balance
5837
5938
Args:
6039
wallet_address (str): Ethereum wallet address
40+
chain (str): The chain ID can be ["eth", "0x1", "polygon", "0x89", "bsc", "0x38", "avalanche", "0xa86a", "fantom", "0xfa", "palm", "0x2a15c308d", "cronos", "0x19", "arbitrum", "0xa4b1", "chiliz", "0x15b38","gnosis", "0x64", "base", "0x2105", "optimism", "0xa", "linea", "0xe708", "moonbeam", "0x504", "moonriver", "0x505", "flow", "0x2eb", "ronin", "0x7e4", "lisk", "0x46f", "pulse", "0x171"]
6141
output_include (list[str]): A list of field names to include in the output.
6242
cursor (str): The cursor returned in the previous response (used for getting the next page). end of page cursor is None
6343
@@ -72,8 +52,10 @@ def get_wallet_token_balances(wallet_address: str, output_include: list[str], cu
7252
usd_price, usd_price_24hr_percent_change, usd_price_24hr_usd_change, usd_value,
7353
usd_value_24hr_usd_change, native_token, portfolio_percentage
7454
"""
55+
check_chain_supported(chain)
56+
7557
params = {
76-
"chain": "eth",
58+
"chain": chain,
7759
"address": wallet_address
7860
}
7961

@@ -97,12 +79,14 @@ def get_wallet_token_balances(wallet_address: str, output_include: list[str], cu
9779

9880
@tool
9981
@handle_exceptions
100-
def get_wallet_stats(wallet_address: str, output_include: list[str]) -> dict:
82+
def get_wallet_stats(wallet_address: str, chain: str, output_include: list[str]) -> dict:
10183
"""
10284
Get the stats for a wallet address.
10385
10486
Args:
10587
wallet_address (str): Ethereum wallet address
88+
chain (str): The chain ID can be ["eth", "0x1", "polygon", "0x89", "bsc", "0x38", "avalanche", "0xa86a", "fantom", "0xfa", "palm", "0x2a15c308d", "cronos", "0x19", "arbitrum", "0xa4b1", "chiliz", "0x15b38","gnosis", "0x64", "base", "0x2105", "optimism", "0xa", "linea", "0xe708", "moonbeam", "0x504", "moonriver", "0x505", "flow", "0x2eb", "ronin", "0x7e4", "lisk", "0x46f", "pulse", "0x171"]
89+
output_include (list[str]): A list of field names to include in the output.
10690
10791
Returns:
10892
List[dict[str, Any]]:
@@ -112,8 +96,10 @@ def get_wallet_stats(wallet_address: str, output_include: list[str]) -> dict:
11296
11397
- nfts, collections, transactions, nft_transfers, token_transfers
11498
"""
99+
check_chain_supported(chain)
100+
115101
params = {
116-
"chain": "eth",
102+
"chain": chain,
117103
"address": wallet_address
118104
}
119105

@@ -128,13 +114,14 @@ def get_wallet_stats(wallet_address: str, output_include: list[str]) -> dict:
128114

129115
@tool
130116
@handle_exceptions
131-
def get_wallet_history(wallet_address: str, output_include: list[str], cursor: str = "") -> dict:
117+
def get_wallet_history(wallet_address: str, chain: str, output_include: list[str], cursor: str = "") -> dict:
132118
"""
133119
Retrieve the full transaction history of a specified wallet address, including sends, receives, token and NFT transfers
134120
and contract interactions. (paginated & in descending order)
135121
136122
Args:
137123
wallet_address (str): Ethereum wallet address
124+
chain (str): The chain ID can be ["eth", "0x1", "polygon", "0x89", "bsc", "0x38", "avalanche", "0xa86a", "fantom", "0xfa", "palm", "0x2a15c308d", "cronos", "0x19", "arbitrum", "0xa4b1", "chiliz", "0x15b38","gnosis", "0x64", "base", "0x2105", "optimism", "0xa", "linea", "0xe708", "moonbeam", "0x504", "moonriver", "0x505", "flow", "0x2eb", "ronin", "0x7e4", "lisk", "0x46f", "pulse", "0x171"]
138125
output_include (list[str]): A list of field names to include in the output.
139126
cursor (str): The cursor returned in the previous response (used for getting the next page). end of page cursor is None
140127
@@ -149,8 +136,10 @@ def get_wallet_history(wallet_address: str, output_include: list[str], cursor: s
149136
value, receipt_contract_address, block_timestamp, block_number, block_hash, internal_transactions,
150137
nft_transfers, erc20_transfer, native_transfers
151138
"""
139+
check_chain_supported(chain)
140+
152141
params = {
153-
"chain": "eth",
142+
"chain": chain,
154143
"order": "DESC",
155144
"address": wallet_address
156145
}
@@ -174,12 +163,13 @@ def get_wallet_history(wallet_address: str, output_include: list[str], cursor: s
174163

175164
@tool
176165
@handle_exceptions
177-
def get_transaction_detail(transaction_hash: str, output_include: list[str]) -> dict:
166+
def get_transaction_detail(transaction_hash: str, chain: str, output_include: list[str]) -> dict:
178167
"""
179168
Get the contents of a transaction by the given transaction hash.
180169
181170
Args:
182171
transaction_hash (str): transaction hash to be decoded
172+
chain (str): The chain ID can be ["eth", "0x1", "polygon", "0x89", "bsc", "0x38", "avalanche", "0xa86a", "fantom", "0xfa", "palm", "0x2a15c308d", "cronos", "0x19", "arbitrum", "0xa4b1", "chiliz", "0x15b38","gnosis", "0x64", "base", "0x2105", "optimism", "0xa", "linea", "0xe708", "moonbeam", "0x504", "moonriver", "0x505", "flow", "0x2eb", "ronin", "0x7e4", "lisk", "0x46f", "pulse", "0x171"]
183173
output_include (list[str]): A list of field names to include in the output.
184174
185175
Returns:
@@ -195,8 +185,10 @@ def get_transaction_detail(transaction_hash: str, output_include: list[str]) ->
195185
196186
197187
"""
188+
check_chain_supported(chain)
189+
198190
params = {
199-
"chain": "eth",
191+
"chain": chain,
200192
"transaction_hash": transaction_hash
201193
}
202194

@@ -211,12 +203,13 @@ def get_transaction_detail(transaction_hash: str, output_include: list[str]) ->
211203

212204
@tool
213205
@handle_exceptions
214-
def get_token_approvals(wallet_address: str, output_include: list[str], cursor: str = "") -> dict:
206+
def get_token_approvals(wallet_address: str, chain: str, output_include: list[str], cursor: str = "") -> dict:
215207
"""
216208
Get ERC20 approvals for one or many wallet addresses and/or contract addresses, ordered by block number in descending order.
217209
218210
Args:
219211
wallet_address (str): Ethereum wallet address
212+
chain (str): The chain ID can be ["eth", "0x1", "polygon", "0x89", "bsc", "0x38", "avalanche", "0xa86a", "fantom", "0xfa", "palm", "0x2a15c308d", "cronos", "0x19", "arbitrum", "0xa4b1", "chiliz", "0x15b38","gnosis", "0x64", "base", "0x2105", "optimism", "0xa", "linea", "0xe708", "moonbeam", "0x504", "moonriver", "0x505", "flow", "0x2eb", "ronin", "0x7e4", "lisk", "0x46f", "pulse", "0x171"]
220213
output_include (list[str]): A list of field names to include in the output.
221214
cursor (str): The cursor returned in the previous response (used for getting the next page). end of page cursor is None
222215
@@ -228,10 +221,12 @@ def get_token_approvals(wallet_address: str, output_include: list[str], cursor:
228221
229222
- block_number, block_timestamp, transaction_hash, value, value_formatted, token, spender
230223
"""
224+
check_chain_supported(chain)
225+
231226
base_url = _MORALIS_URL
232227
api_url = f"{base_url}/wallets/{wallet_address}/approvals"
233228

234-
params = {'chain': 'eth'}
229+
params = {'chain': chain}
235230

236231
if cursor:
237232
params["cursor"] = cursor

src/auth/routers/auth_router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
RegisterInput,
1010
VerifyInput
1111
)
12-
from src.util.execptions import *
12+
from src.util.exceptions import *
1313
from src.db.sql_alchemy import Database
1414
from src.util.response import global_response, GlobalResponse, ExceptionResponse
1515

src/auth/services/auth_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from sqlalchemy.orm import Session
55
from pydantic import BaseModel, Field, EmailStr
66

7-
from src.util.execptions import *
7+
from src.util.exceptions import *
88
from src.db.models import UserModel
99
from src.db.sql_alchemy import Database
1010
from src.share.base_types import WalletAddress

src/auth/utils/bcrypt_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from jose import JWTError, jwt
55
from dotenv import load_dotenv
66
from passlib.context import CryptContext
7-
from src.util.execptions import JWTDecodeError
7+
from src.util.exceptions import JWTDecodeError
88

99
load_dotenv()
1010

src/auth/utils/get_token.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from src.util.execptions import JWTDecodeError
1+
from src.util.exceptions import JWTDecodeError
22
from fastapi import Depends, HTTPException, Request, status
33
from src.auth.utils.bcrypt_helper import decode_access_token
44
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
@@ -58,7 +58,9 @@ def authenticate_user(
5858
decode_token = decode_access_token(token)
5959
return decode_token["user_id"]
6060
except JWTDecodeError as e:
61-
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED,detail=str(e))
61+
raise HTTPException(
62+
status_code=status.HTTP_401_UNAUTHORIZED, detail=str(e))
6263
except Exception as e:
6364
# Handle any other unexpected errors with a 400 Bad Request
64-
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
65+
raise HTTPException(
66+
status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))

src/conversation/repositories/conversation_repository.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from sqlalchemy.orm import Session
44

55
from src.db.models import Conversation
6-
from src.util.execptions import NotFoundError
6+
from src.util.exceptions import NotFoundError
77
from src.share.base_repository import BaseRepository
88

9+
910
class ConversationRepository(BaseRepository[Conversation]):
1011
"""
1112
Repository class for handling CRUD operations on the Conversation model.

src/conversation/routers/playground_conversation_router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from src.db.sql_alchemy import Database
1111
from src.auth.utils.get_token import authenticate_user
12-
from src.util.execptions import NotFoundError, RateLimitError
12+
from src.util.exceptions import NotFoundError, RateLimitError
1313
from src.project.services.project_service import ProjectService
1414
from src.query_usage.services.query_usage_service import QueryUsageService
1515
from src.conversation.services.conversation_service import ConversationService

src/conversation/services/conversation_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from langchain_core.messages.human import HumanMessage
99

1010
from src.util.configuration import Config
11-
from src.util.execptions import NotFoundError
11+
from src.util.exceptions import NotFoundError
1212
from src.db.models import Conversation, QueryUsage
1313
from src.agentflow.tool.hub import ToolRegistery
1414
from src.agentflow.utils.shared_tools import init_llm

src/project/repositories/project_repository.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from sqlalchemy.orm import Session
44

55
from src.db.models import Project
6-
from src.util.execptions import NotFoundError
6+
from src.util.exceptions import NotFoundError
77
from src.share.base_repository import BaseRepository
88

9+
910
class ProjectRepository(BaseRepository[Project]):
1011
"""
1112
Repository class for handling CRUD operations on the Project model.

0 commit comments

Comments
 (0)