Skip to content

Commit 3e05c43

Browse files
author
Adam Balogh
committed
format
1 parent 54f8154 commit 3e05c43

9 files changed

Lines changed: 40 additions & 61 deletions

File tree

agent/agent_executors.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from openai import OpenAI
44
from langgraph.prebuilt import create_react_agent
55
from langgraph.graph.graph import CompiledGraph
6-
from langchain_openai import ChatOpenAI
6+
from langchain_google_genai import ChatGoogleGenerativeAI
7+
from langchain_core.language_models.chat_models import BaseChatModel
78

89
from agent.tools import create_investor_agent_toolkit, create_analytics_agent_toolkit
910
from onchain.tokens.metadata import TokenMetadataRepo
@@ -51,37 +52,27 @@
5152
API_KEY = "dummy_key"
5253

5354

54-
def create_routing_model() -> ChatOpenAI:
55-
return ChatOpenAI(
55+
def create_routing_model() -> BaseChatModel:
56+
return ChatGoogleGenerativeAI(
5657
model=ROUTING_MODEL,
5758
temperature=0.0,
58-
openai_api_base=BASE_URL,
59-
openai_api_key=API_KEY,
60-
request_timeout=60,
59+
google_api_key=API_KEY,
6160
)
6261

6362

64-
def create_suggestions_model() -> ChatOpenAI:
65-
return ChatOpenAI(
63+
def create_suggestions_model() -> BaseChatModel:
64+
return ChatGoogleGenerativeAI(
6665
model=SUGGESTIONS_MODEL,
6766
temperature=0.3,
68-
openai_api_base=BASE_URL,
69-
openai_api_key=API_KEY,
70-
request_timeout=60,
71-
max_tokens=500,
72-
streaming=False,
67+
google_api_key=API_KEY,
7368
)
7469

7570

7671
def create_investor_executor() -> CompiledGraph:
77-
openai_model = ChatOpenAI(
72+
openai_model = ChatGoogleGenerativeAI(
7873
model=REASONING_MODEL,
7974
temperature=0.0,
80-
openai_api_base=BASE_URL,
81-
openai_api_key=API_KEY,
82-
request_timeout=60,
83-
max_tokens=4096,
84-
streaming=False,
75+
google_api_key=API_KEY,
8576
)
8677
agent_executor = create_react_agent(
8778
model=openai_model, tools=create_investor_agent_toolkit()
@@ -91,14 +82,10 @@ def create_investor_executor() -> CompiledGraph:
9182

9283

9384
def create_analytics_executor(token_metadata_repo: TokenMetadataRepo) -> CompiledGraph:
94-
openai_model = ChatOpenAI(
85+
openai_model = ChatGoogleGenerativeAI(
9586
model=REASONING_MODEL,
9687
temperature=0.0,
97-
openai_api_base=BASE_URL,
98-
openai_api_key=API_KEY,
99-
request_timeout=60,
100-
max_tokens=4096,
101-
streaming=False,
88+
google_api_key=API_KEY,
10289
)
10390
analytics_executor = create_react_agent(
10491
model=openai_model,

agent/tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def create_investor_agent_toolkit() -> List[BaseTool]:
6464
def create_analytics_agent_toolkit(
6565
token_metadata_repo: TokenMetadataRepo,
6666
) -> List[BaseTool]:
67-
6867
@tool
6968
@track_tool_usage("search_token")
7069
def search_token(

onchain/analytics/analytics_tools.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,12 +633,16 @@ def calculate_sma(prices, period):
633633
"short_trend": (
634634
"Bullish"
635635
if sma7 and sma20 and sma7[-1] > sma20[-1]
636-
else "Bearish" if sma7 and sma20 else "Neutral"
636+
else "Bearish"
637+
if sma7 and sma20
638+
else "Neutral"
637639
),
638640
"long_trend": (
639641
"Bullish"
640642
if sma50 and sma200 and sma50[-1] > sma200[-1]
641-
else "Bearish" if sma50 and sma200 else "Neutral"
643+
else "Bearish"
644+
if sma50 and sma200
645+
else "Neutral"
642646
),
643647
},
644648
"technical_indicators": {
@@ -1242,7 +1246,7 @@ def analyze_wallet_portfolio(
12421246
# Drawdown insight
12431247
if max_dd > 0.1: # Only show if drawdown is significant (>10%)
12441248
insights.append(
1245-
f"Your maximum drawdown was {max_dd*100:.2f}% over {max_dd_duration} {candle_interval}s. Since then, your portfolio has recovered {recovery_pct:.2f}%."
1249+
f"Your maximum drawdown was {max_dd * 100:.2f}% over {max_dd_duration} {candle_interval}s. Since then, your portfolio has recovered {recovery_pct:.2f}%."
12461250
)
12471251

12481252
# Get time periods in user-friendly format
@@ -1268,7 +1272,7 @@ def analyze_wallet_portfolio(
12681272
"current_value": f"${float(portfolio_values[-1]):.2f}",
12691273
"total_return": f"{total_return_pct:.2f}%",
12701274
"annualized_return": (
1271-
f"{((1 + total_return_pct/100) ** (365/(num_candles)) - 1) * 100:.2f}%"
1275+
f"{((1 + total_return_pct / 100) ** (365 / (num_candles)) - 1) * 100:.2f}%"
12721276
if candle_interval == CandleInterval.DAY
12731277
else "N/A"
12741278
),

onchain/analytics/test_analytics_tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
class TestFinancialAnalyticsTools(unittest.TestCase):
16-
1716
def test_get_coingecko_price_history(self):
1817
response = get_coingecko_price_data(
1918
token_symbol="BTC",

onchain/analytics/test_defillama_metrics.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def format_tvl(value) -> str:
2020

2121

2222
class TestDefiLlamaSource(unittest.TestCase):
23-
2423
def test_show_defi_llama_protocols(self):
2524
"""Test the show_defi_llama_protocols tool"""
2625
print("\n=== Testing show_defi_llama_protocols() ===")

onchain/tokens/test_metadata.py

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

1010

1111
class TestMetadata(unittest.TestCase):
12-
1312
def setUp(self):
1413
self.dynamodb = boto3.resource(
1514
"dynamodb",

onchain/tokens/trending.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
from api.api_types import TokenMetadata
1313

14-
TRENDING_POOLS_URL = (
15-
"https://pro-api.coingecko.com/api/v3/onchain/networks/%s/trending_pools?include=base_token"
16-
)
14+
TRENDING_POOLS_URL = "https://pro-api.coingecko.com/api/v3/onchain/networks/%s/trending_pools?include=base_token"
1715
TOKEN_INFO_URL = (
1816
"https://pro-api.coingecko.com/api/v3/onchain/networks/%s/tokens/%s/info"
1917
)
@@ -135,9 +133,7 @@ def evaluate_token_risk(
135133
"category_scores (out of 100)": {
136134
"pool_quality_score (honeypot risk, buy/sell tax, proxy contract, liquidity amount)": attributes.get(
137135
"gt_score_details", {}
138-
).get(
139-
"pool", 0
140-
),
136+
).get("pool", 0),
141137
"token_age_score": attributes.get("gt_score_details", {}).get(
142138
"creation", 0
143139
),

server/server.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,28 +159,25 @@ def verify_cloudflare_turnstile_token():
159159
try:
160160
secret_key = os.getenv("CLOUDFLARE_TURNSTILE_SECRET_KEY")
161161
if not secret_key:
162-
raise Exception("CLOUDFLARE_TURNSTILE_SECRET_KEY environment variable is not set")
162+
raise Exception(
163+
"CLOUDFLARE_TURNSTILE_SECRET_KEY environment variable is not set"
164+
)
163165

164166
data = request.get_json()
165-
token = data.get('token')
167+
token = data.get("token")
166168

167169
if not token:
168170
return jsonify({"error": "Missing token"}), 400
169171

170172
# Make the request to Cloudflare Turnstile
171173
response = requests.post(
172-
'https://challenges.cloudflare.com/turnstile/v0/siteverify',
173-
data={
174-
'secret': secret_key,
175-
'response': token
176-
},
177-
headers={
178-
'content-type': 'application/x-www-form-urlencoded'
179-
}
174+
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
175+
data={"secret": secret_key, "response": token},
176+
headers={"content-type": "application/x-www-form-urlencoded"},
180177
)
181178

182179
result = response.json()
183-
status_code = 200 if result.get('success') else 400
180+
status_code = 200 if result.get("success") else 400
184181
return jsonify(result), status_code
185182

186183
except Exception as e:

subnet/subnet_methods.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828

2929
def create_evaluation_model() -> ChatOpenAI:
30-
3130
return ChatOpenAI(
3231
model=LLM_MODEL,
3332
temperature=0.0,
@@ -128,18 +127,13 @@ def subnet_query(quant_query: QuantQuery) -> QuantResponse:
128127
og.init(
129128
private_key=os.environ["OG_PRIVATE_KEY"],
130129
email=os.environ["OG_EMAIL"],
131-
password=os.environ["OG_PASSWORD"]
130+
password=os.environ["OG_PASSWORD"],
132131
)
133132
# Use the query string as prompt
134-
messages = [
135-
{"role": "user", "content": quant_query.query}
136-
]
133+
messages = [{"role": "user", "content": quant_query.query}]
137134
model_cid = og.LLM.LLAMA_3_2_3B_INSTRUCT
138-
result = og.llm_chat(
139-
model_cid=model_cid,
140-
messages=messages
141-
)
142-
answer = result.chat_output['content']
135+
result = og.llm_chat(model_cid=model_cid, messages=messages)
136+
answer = result.chat_output["content"]
143137
quant_response = QuantResponse(
144138
response=answer,
145139
signature=b"",
@@ -149,7 +143,12 @@ def subnet_query(quant_query: QuantQuery) -> QuantResponse:
149143
return quant_response
150144
except Exception as tee_e:
151145
logging.error(f"TEE/OG SDK query failed: {tee_e}")
152-
return QuantResponse(response="TEE/OG SDK error", signature=b"", proofs=[], metadata={"tee_error": str(tee_e)})
146+
return QuantResponse(
147+
response="TEE/OG SDK error",
148+
signature=b"",
149+
proofs=[],
150+
metadata={"tee_error": str(tee_e)},
151+
)
153152

154153
print(quant_query)
155154
# Create context with the provided wallet address

0 commit comments

Comments
 (0)