Skip to content

Commit 8b7271d

Browse files
committed
fix: lint
1 parent a752c9d commit 8b7271d

7 files changed

Lines changed: 64 additions & 58 deletions

File tree

openagent/agent/config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ def validate_celery_urls(cls, v, values):
3535

3636

3737
class TaskConfig(BaseModel):
38-
interval: Optional[int] = Field(default=None, description="Interval in seconds between task executions")
38+
interval: Optional[int] = Field(
39+
default=None, description="Interval in seconds between task executions"
40+
)
3941
delay_variation: Optional[int] = Field(
4042
default=0, description="Maximum random delay in seconds to add to the interval"
4143
)
4244
query: str
43-
cron: Optional[str] = Field(default=None, description="Cron expression for scheduling tasks")
45+
cron: Optional[str] = Field(
46+
default=None, description="Cron expression for scheduling tasks"
47+
)
4448
schedule: SchedulerConfig = Field(
4549
default_factory=lambda: SchedulerConfig(type="local"),
4650
description="Scheduler configuration for this task",

openagent/agent/scheduler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def init_scheduled_tasks(self, tasks_config: dict, task_runner):
3333
if task_config.schedule.type == "queue":
3434
self._init_celery_task(task_id, task_config, task_runner)
3535
else:
36+
3637
async def task_wrapper(query, delay_variation):
3738
if delay_variation > 0:
3839
delay = random.uniform(0, delay_variation)
@@ -48,7 +49,9 @@ async def task_wrapper(query, delay_variation):
4849
id=task_id,
4950
name=f"Task_{task_id}",
5051
)
51-
logger.info(f"Scheduled cron task '{task_id}' with cron expression: {task_config.cron}")
52+
logger.info(
53+
f"Scheduled cron task '{task_id}' with cron expression: {task_config.cron}"
54+
)
5255
else:
5356
self.scheduler.add_job(
5457
func=task_wrapper,

openagent/core/database/engine.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
from typing import Optional, Literal
31
from urllib.parse import urlparse
42

53
from sqlalchemy import create_engine as sa_create_engine, text as sa_text, Engine
@@ -9,10 +7,10 @@
97
def _create_sqlite_engine(db_url: str) -> Engine:
108
"""
119
Create a SQLite engine from a URL.
12-
10+
1311
Args:
1412
db_url: SQLite database URL (sqlite:///path/to/file.db)
15-
13+
1614
Returns:
1715
SQLAlchemy engine instance
1816
"""
@@ -23,7 +21,7 @@ def _ensure_postgres_database_exists(db_url: str) -> None:
2321
"""
2422
Ensure that the PostgreSQL database specified in the URL exists.
2523
Creates the database if it doesn't exist.
26-
24+
2725
Args:
2826
db_url: PostgreSQL database URL
2927
"""
@@ -39,10 +37,10 @@ def _ensure_postgres_database_exists(db_url: str) -> None:
3937
try:
4038
# Check if database exists
4139
result = default_conn.execute(
42-
sa_text(f"SELECT 1 FROM pg_database WHERE datname = :db_name"),
43-
{"db_name": pg_db_name}
40+
sa_text("SELECT 1 FROM pg_database WHERE datname = :db_name"),
41+
{"db_name": pg_db_name},
4442
)
45-
43+
4644
if not result.scalar():
4745
# Create database if it doesn't exist
4846
default_conn.execute(sa_text("commit"))
@@ -59,10 +57,10 @@ def _create_postgres_engine(db_url: str) -> Engine:
5957
"""
6058
Create a PostgreSQL engine from a URL.
6159
Ensures the database exists before creating the engine.
62-
60+
6361
Args:
6462
db_url: PostgreSQL database URL
65-
63+
6664
Returns:
6765
SQLAlchemy engine instance
6866
"""
@@ -74,25 +72,27 @@ def create_engine(db_url: str) -> Engine:
7472
"""
7573
Create a database engine based on the provided configuration.
7674
Database type is automatically detected from the URL.
77-
75+
7876
Args:
79-
db_url: Database URL. For postgres: postgresql://user:password@host:port/database,
77+
db_url: Database URL. For postgres: postgresql://user:password@host:port/database,
8078
for sqlite: sqlite:///path/to/file.db
81-
79+
8280
Returns:
8381
SQLAlchemy engine instance
84-
82+
8583
Raises:
8684
ValueError: If an unsupported database type is detected or if db_url is missing
8785
"""
8886
if not db_url:
8987
raise ValueError("Database URL is required")
90-
88+
9189
# Auto-detect database type from URL
92-
if db_url.startswith('sqlite:'):
90+
if db_url.startswith("sqlite:"):
9391
return _create_sqlite_engine(db_url)
94-
elif db_url.startswith('postgresql:'):
92+
elif db_url.startswith("postgresql:"):
9593
return _create_postgres_engine(db_url)
9694
else:
97-
raise ValueError(f"Could not detect database type from URL: {db_url}. "
98-
"Supported URL formats: 'sqlite:///path/to/file.db' or 'postgresql://user:password@host:port/database'")
95+
raise ValueError(
96+
f"Could not detect database type from URL: {db_url}. "
97+
"Supported URL formats: 'sqlite:///path/to/file.db' or 'postgresql://user:password@host:port/database'"
98+
)

openagent/tools/pendle/market_analysis.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
from heapq import nlargest
66
from typing import Optional, Literal
77

8-
import httpx
98
from pydantic import BaseModel, Field
109
from textwrap import dedent
1110
from loguru import logger
1211

13-
from sqlalchemy import Column, Integer, String, DateTime, text as sa_text
12+
from sqlalchemy import Column, Integer, String, DateTime
1413
from sqlalchemy.ext.declarative import declarative_base
1514
from sqlalchemy.orm import sessionmaker
1615
from langchain.prompts import PromptTemplate
@@ -54,13 +53,13 @@ class PendleMarket(Base):
5453

5554
class DatabaseConfig(BaseModel):
5655
"""Database configuration for the tool"""
56+
5757
type: Literal["sqlite", "postgres"] = Field(
58-
default="sqlite",
59-
description="Type of database to use"
58+
default="sqlite", description="Type of database to use"
6059
)
6160
url: Optional[str] = Field(
6261
default=None,
63-
description="Database URL. For postgres: postgresql://user:password@host:port/database, for sqlite: sqlite:///path/to/file.db"
62+
description="Database URL. For postgres: postgresql://user:password@host:port/database, for sqlite: sqlite:///path/to/file.db",
6463
)
6564

6665

@@ -73,7 +72,7 @@ class PendleMarketConfig(BaseModel):
7372
)
7473
db_url: Optional[str] = Field(
7574
default=None,
76-
description="Database URL. For postgres: postgresql://user:password@host:port/database, for sqlite: sqlite:///path/to/file.db"
75+
description="Database URL. For postgres: postgresql://user:password@host:port/database, for sqlite: sqlite:///path/to/file.db",
7776
)
7877

7978

@@ -91,7 +90,9 @@ def _init_database(self, db_url: Optional[str]) -> None:
9190
"""Initialize database connection based on configuration"""
9291
# Set default configuration if not provided
9392
if not db_url:
94-
db_url = 'sqlite:///' + os.path.join(os.getcwd(), "storage", f"{self.name}.db")
93+
db_url = "sqlite:///" + os.path.join(
94+
os.getcwd(), "storage", f"{self.name}.db"
95+
)
9596

9697
# Create engine using the database module's create_engine function
9798
engine = create_engine(db_url)
@@ -233,16 +234,22 @@ def _process_market_data(results: dict) -> PendleMarketSnapshot:
233234
new_markets = [market for market in markets if market.isNewPool]
234235
existing_markets = [market for market in markets if not market.isNewPool]
235236

236-
def get_top_markets(markets: list[PendleMarketData], key_attr: str, n: int = 3) -> list[PendleMarketData]:
237+
def get_top_markets(
238+
markets: list[PendleMarketData], key_attr: str, n: int = 3
239+
) -> list[PendleMarketData]:
237240
"""Helper function to get top n markets based on a specific attribute"""
238-
filtered_markets = [m for m in markets if m and getattr(m, key_attr) is not None]
241+
filtered_markets = [
242+
m for m in markets if m and getattr(m, key_attr) is not None
243+
]
239244
return nlargest(n, filtered_markets, key=lambda x: getattr(x, key_attr))
240245

241246
# Get top markets for both liquidity and APY
242-
liquidity_increase = get_top_markets(existing_markets, 'liquidityChange24h')
243-
new_market_liquidity_increase = get_top_markets(new_markets, 'liquidityChange24h')
244-
apy_increase = get_top_markets(existing_markets, 'impliedApyChange24h')
245-
new_market_apy_increase = get_top_markets(new_markets, 'impliedApyChange24h')
247+
liquidity_increase = get_top_markets(existing_markets, "liquidityChange24h")
248+
new_market_liquidity_increase = get_top_markets(
249+
new_markets, "liquidityChange24h"
250+
)
251+
apy_increase = get_top_markets(existing_markets, "impliedApyChange24h")
252+
new_market_apy_increase = get_top_markets(new_markets, "impliedApyChange24h")
246253

247254
# Extract symbols from sorted markets in one step
248255
liquidity_increase_top_symbols = {
@@ -258,10 +265,10 @@ def get_top_markets(markets: list[PendleMarketData], key_attr: str, n: int = 3)
258265

259266
# Combine all relevant symbols
260267
relevant_symbols = (
261-
liquidity_increase_top_symbols
262-
| new_market_liquidity_increase_symbols
263-
| apy_increase_symbols
264-
| new_market_apy_increase_symbols
268+
liquidity_increase_top_symbols
269+
| new_market_liquidity_increase_symbols
270+
| apy_increase_symbols
271+
| new_market_apy_increase_symbols
265272
)
266273

267274
# Filter markets to include only those in the relevant symbols set

openagent/tools/pendle/voter_apy_analysis.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from textwrap import dedent
44
from typing import Optional
55

6-
import httpx
76
from langchain.chat_models import init_chat_model
87
from langchain.prompts import PromptTemplate
98
from langchain_core.output_parsers import StrOutputParser
@@ -47,7 +46,7 @@ def __init__(self, core_model=None):
4746
self.core_model = core_model
4847
self.tool_model = None
4948
self.tool_prompt = None
50-
db_url = 'sqlite:///' + os.path.join(os.getcwd(), "storage", f"{self.name}.db")
49+
db_url = "sqlite:///" + os.path.join(os.getcwd(), "storage", f"{self.name}.db")
5150
self.engine = create_engine(db_url)
5251
Base.metadata.create_all(self.engine)
5352
session = sessionmaker(bind=self.engine)
@@ -182,7 +181,9 @@ def extract_pool_info(item: dict) -> dict:
182181
change_direction = (
183182
"increased"
184183
if last_epoch_change > 0
185-
else "decreased" if last_epoch_change < 0 else "unchanged"
184+
else "decreased"
185+
if last_epoch_change < 0
186+
else "unchanged"
186187
)
187188

188189
# Convert to percentage strings, use absolute value for lastEpochChange

openagent/tools/twitter/feed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(self):
8080
self.retry_delay = 1
8181

8282
# Initialize database
83-
db_url = 'sqlite:///' + os.path.join(os.getcwd(), "storage", f"{self.name}.db")
83+
db_url = "sqlite:///" + os.path.join(os.getcwd(), "storage", f"{self.name}.db")
8484
self.engine = create_engine(db_url)
8585
Base.metadata.create_all(self.engine)
8686
Session = sessionmaker(bind=self.engine)
@@ -99,7 +99,7 @@ async def setup(self, config: TwitterFeedConfig) -> None:
9999
self.config = config
100100

101101
async def _fetch_single_handle(
102-
self, client: httpx.AsyncClient, handle: str
102+
self, client: httpx.AsyncClient, handle: str
103103
) -> List[dict]:
104104
"""Fetch tweets for a single handle with retry logic"""
105105
params = {"limit": self.config.limit if self.config else 50}

test/tools/test_pendle_market.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
import asyncio
22

3-
from sqlalchemy.testing.config import db_url
43

54
from openagent.agent.config import ModelConfig
6-
from openagent.tools.pendle.market_analysis import PendleMarketTool, PendleMarketConfig, DatabaseConfig
5+
from openagent.tools.pendle.market_analysis import PendleMarketTool, PendleMarketConfig
76

87

98
async def test_pendle_market():
109
# Initialize configuration
1110
config = PendleMarketConfig(
12-
model=ModelConfig(
13-
provider="openai",
14-
name="gpt-4",
15-
temperature=0.7
16-
),
17-
db_url='sqlite:///storage/test_pendle_market.db'
11+
model=ModelConfig(provider="openai", name="gpt-4", temperature=0.7),
12+
db_url="sqlite:///storage/test_pendle_market.db",
1813
)
1914

2015
# Initialize the tool
@@ -30,12 +25,8 @@ async def test_pendle_market():
3025
async def test_pendle_market_postgres():
3126
# Initialize configuration with PostgreSQL
3227
config = PendleMarketConfig(
33-
model=ModelConfig(
34-
provider="openai",
35-
name="gpt-4",
36-
temperature=0.7
37-
),
38-
db_url='postgresql://postgres:password@localhost:5434/pendle_market_test'
28+
model=ModelConfig(provider="openai", name="gpt-4", temperature=0.7),
29+
db_url="postgresql://postgres:password@localhost:5434/pendle_market_test",
3930
)
4031

4132
# Initialize the tool

0 commit comments

Comments
 (0)