Skip to content

Commit edc9b6b

Browse files
committed
Update
1 parent b217586 commit edc9b6b

23 files changed

+372
-407
lines changed

cookbook/models/aws/bedrock/image_agent_bytes.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
image_path = Path(__file__).parent.joinpath("sample.jpg")
1616

17-
download_image(url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg", save_path=str(image_path))
17+
download_image(
18+
url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg",
19+
save_path=str(image_path),
20+
)
1821

1922
# Read the image file content as bytes
2023
image_bytes = image_path.read_bytes()

cookbook/models/azure/ai_foundry/image_agent_bytes.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
image_path = Path(__file__).parent.joinpath("sample.jpg")
1414

15-
download_image(url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg", save_path=str(image_path))
15+
download_image(
16+
url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg",
17+
save_path=str(image_path),
18+
)
1619

1720
# Read the image file content as bytes
1821
image_bytes = image_path.read_bytes()

cookbook/models/cohere/image_agent_bytes.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
image_path = Path(__file__).parent.joinpath("sample.jpg")
1414

15-
download_image(url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg", save_path=str(image_path))
15+
download_image(
16+
url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg",
17+
save_path=str(image_path),
18+
)
1619

1720
# Read the image file content as bytes
1821
image_bytes = image_path.read_bytes()

cookbook/models/cohere/image_agent_local_file.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
image_path = Path(__file__).parent.joinpath("sample.jpg")
1414

15-
download_image(url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg", save_path=str(image_path))
15+
download_image(
16+
url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg",
17+
save_path=str(image_path),
18+
)
1619

1720
agent.print_response(
1821
"Tell me about this image.",

cookbook/models/openai/image_agent_bytes.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
image_path = Path(__file__).parent.joinpath("sample.jpg")
1616

17-
download_image(url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg", save_path=str(image_path))
17+
download_image(
18+
url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg",
19+
save_path=str(image_path),
20+
)
1821

1922
# Read the image file content as bytes
2023
image_bytes = image_path.read_bytes()

cookbook/models/xai/image_agent_bytes.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
image_path = Path(__file__).parent.joinpath("sample.jpg")
1616

17-
download_image(url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg", save_path=str(image_path))
17+
download_image(
18+
url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg",
19+
save_path=str(image_path),
20+
)
1821

1922
# Read the image file content as bytes
2023
image_bytes = image_path.read_bytes()

cookbook/storage/mongodb_storage/mongodb_storage_for_workflow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from agno.utils.pprint import pprint_run_response
1111
from agno.workflow import Workflow
1212

13-
1413
db_url = "mongodb://localhost:27017"
1514

15+
1616
class HackerNewsReporter(Workflow):
1717
description: str = (
1818
"Get the top stories from Hacker News and write a report on them."

cookbook/storage/postgres_storage/postgres_storage_for_workflow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from agno.utils.pprint import pprint_run_response
1111
from agno.workflow import Workflow
1212

13-
1413
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
1514

15+
1616
class HackerNewsReporter(Workflow):
1717
description: str = (
1818
"Get the top stories from Hacker News and write a report on them."

cookbook/storage/singlestore_storage/singlestore_storage_for_agent.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
# Download the certificate if SSL_CERT is not provided
2222
if not SSL_CERT:
23-
SSL_CERT = download_cert(cert_url="https://portal.singlestore.com/static/ca/singlestore_bundle.pem", filename="singlestore_bundle.pem")
23+
SSL_CERT = download_cert(
24+
cert_url="https://portal.singlestore.com/static/ca/singlestore_bundle.pem",
25+
filename="singlestore_bundle.pem",
26+
)
2427
if SSL_CERT:
2528
os.environ["SINGLESTORE_SSL_CERT"] = SSL_CERT
2629

cookbook/storage/singlestore_storage/singlestore_storage_for_workflow.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import json
2-
from os import getenv
32
import os
3+
from os import getenv
44
from typing import Iterator
55

6-
from agno.utils.certs import download_cert
76
import httpx
87
from agno.agent import Agent
98
from agno.run.response import RunResponse
109
from agno.storage.singlestore import SingleStoreStorage
1110
from agno.tools.newspaper4k import Newspaper4kTools
11+
from agno.utils.certs import download_cert
1212
from agno.utils.log import logger
1313
from agno.utils.pprint import pprint_run_response
1414
from agno.workflow import Workflow
@@ -93,14 +93,15 @@ def run(self, num_stories: int = 5) -> Iterator[RunResponse]:
9393

9494
# Download the certificate if SSL_CERT is not provided
9595
if not SSL_CERT:
96-
SSL_CERT = download_cert(cert_url="https://portal.singlestore.com/static/ca/singlestore_bundle.pem", filename="singlestore_bundle.pem")
96+
SSL_CERT = download_cert(
97+
cert_url="https://portal.singlestore.com/static/ca/singlestore_bundle.pem",
98+
filename="singlestore_bundle.pem",
99+
)
97100
if SSL_CERT:
98101
os.environ["SINGLESTORE_SSL_CERT"] = SSL_CERT
99102

100103
# SingleStore DB URL
101-
db_url = (
102-
f"mysql+pymysql://{USERNAME}:{PASSWORD}@{HOST}:{PORT}/{DATABASE}?charset=utf8mb4"
103-
)
104+
db_url = f"mysql+pymysql://{USERNAME}:{PASSWORD}@{HOST}:{PORT}/{DATABASE}?charset=utf8mb4"
104105
if SSL_CERT:
105106
db_url += f"&ssl_ca={SSL_CERT}&ssl_verify_cert=true"
106107

@@ -109,8 +110,12 @@ def run(self, num_stories: int = 5) -> Iterator[RunResponse]:
109110
# Run workflow
110111
report: Iterator[RunResponse] = HackerNewsReporter(
111112
storage=SingleStoreStorage(
112-
table_name="workflow_sessions", mode="workflow", db_engine=db_engine, schema=DATABASE
113-
), debug_mode=False
113+
table_name="workflow_sessions",
114+
mode="workflow",
115+
db_engine=db_engine,
116+
schema=DATABASE,
117+
),
118+
debug_mode=False,
114119
).run(num_stories=5)
115120
# Print the report
116121
pprint_run_response(report, markdown=True, show_time=True)

libs/agno/agno/storage/postgres.py

+21-27
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,14 @@ def table_exists(self) -> bool:
154154
exists_query = text(
155155
"SELECT 1 FROM information_schema.tables WHERE table_schema = :schema AND table_name = :table"
156156
)
157-
exists = sess.execute(
158-
exists_query, {"schema": self.schema, "table": self.table_name}
159-
).scalar() is not None
160-
else:
161-
exists_query = text(
162-
"SELECT 1 FROM information_schema.tables WHERE table_name = :table"
157+
exists = (
158+
sess.execute(exists_query, {"schema": self.schema, "table": self.table_name}).scalar()
159+
is not None
163160
)
164-
exists = sess.execute(
165-
exists_query, {"table": self.table_name}
166-
).scalar() is not None
167-
161+
else:
162+
exists_query = text("SELECT 1 FROM information_schema.tables WHERE table_name = :table")
163+
exists = sess.execute(exists_query, {"table": self.table_name}).scalar() is not None
164+
168165
logger.debug(f"Table '{self.table.fullname}' does {'not' if not exists else ''} exist")
169166
return exists
170167

@@ -176,7 +173,7 @@ def create(self) -> None:
176173
"""
177174
Create the table if it does not exist.
178175
"""
179-
self.table: Table = self.get_table()
176+
self.table = self.get_table()
180177
if not self.table_exists():
181178
try:
182179
with self.Session() as sess, sess.begin():
@@ -185,48 +182,45 @@ def create(self) -> None:
185182
sess.execute(text(f"CREATE SCHEMA IF NOT EXISTS {self.schema};"))
186183

187184
logger.debug(f"Creating table: {self.table_name}")
188-
185+
189186
# First create the table without indexes
190187
table_without_indexes = Table(
191188
self.table_name,
192189
MetaData(schema=self.schema),
193190
*[c.copy() for c in self.table.columns],
194-
schema=self.schema
191+
schema=self.schema,
195192
)
196193
table_without_indexes.create(self.db_engine, checkfirst=True)
197-
194+
198195
# Then create each index individually with error handling
199196
for idx in self.table.indexes:
200197
try:
201198
idx_name = idx.name
202199
logger.debug(f"Creating index: {idx_name}")
203-
200+
204201
# Check if index already exists
205202
with self.Session() as sess:
206203
if self.schema:
207204
exists_query = text(
208205
"SELECT 1 FROM pg_indexes WHERE schemaname = :schema AND indexname = :index_name"
209206
)
210-
exists = sess.execute(
211-
exists_query, {"schema": self.schema, "index_name": idx_name}
212-
).scalar() is not None
213-
else:
214-
exists_query = text(
215-
"SELECT 1 FROM pg_indexes WHERE indexname = :index_name"
207+
exists = (
208+
sess.execute(exists_query, {"schema": self.schema, "index_name": idx_name}).scalar()
209+
is not None
216210
)
217-
exists = sess.execute(
218-
exists_query, {"index_name": idx_name}
219-
).scalar() is not None
220-
211+
else:
212+
exists_query = text("SELECT 1 FROM pg_indexes WHERE indexname = :index_name")
213+
exists = sess.execute(exists_query, {"index_name": idx_name}).scalar() is not None
214+
221215
if not exists:
222216
idx.create(self.db_engine)
223217
else:
224218
logger.debug(f"Index {idx_name} already exists, skipping creation")
225-
219+
226220
except Exception as e:
227221
# Log the error but continue with other indexes
228222
logger.warning(f"Error creating index {idx.name}: {e}")
229-
223+
230224
except Exception as e:
231225
logger.error(f"Could not create table: '{self.table.fullname}': {e}")
232226
raise

libs/agno/agno/storage/singlestore.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ def mode(self, value: Optional[Literal["agent", "workflow"]]) -> None:
8585
self.table = self.get_table()
8686

8787
def get_table_v1(self) -> Table:
88-
8988
common_columns = [
9089
Column("session_id", mysql.TEXT, primary_key=True),
9190
Column("user_id", mysql.TEXT),
@@ -113,7 +112,7 @@ def get_table_v1(self) -> Table:
113112
)
114113

115114
return table
116-
115+
117116
def get_table(self) -> Table:
118117
if self.schema_version == 1:
119118
return self.get_table_v1()
@@ -129,7 +128,7 @@ def table_exists(self) -> bool:
129128
return False
130129

131130
def create(self) -> None:
132-
self.table: Table = self.get_table()
131+
self.table = self.get_table()
133132
if not self.table_exists():
134133
logger.info(f"\nCreating table: {self.table_name}\n")
135134
self.table.create(self.db_engine)

libs/agno/agno/storage/sqlite.py

+39-8
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@ def get_table_v1(self) -> Table:
123123
]
124124

125125
# Create table with all columns
126-
table = Table(self.table_name, self.metadata, *common_columns, *specific_columns, extend_existing=True, sqlite_autoincrement=True,)
126+
table = Table(
127+
self.table_name,
128+
self.metadata,
129+
*common_columns,
130+
*specific_columns,
131+
extend_existing=True,
132+
sqlite_autoincrement=True,
133+
)
127134

128135
return table
129136

@@ -165,16 +172,40 @@ def create(self) -> None:
165172
"""
166173
Create the table if it doesn't exist.
167174
"""
168-
self.table: Table = self.get_table()
175+
self.table = self.get_table()
169176
if not self.table_exists():
170177
logger.debug(f"Creating table: {self.table.name}")
171178
try:
172-
# Create schema if it doesn't exist
173-
with self.SqlSession() as sess, sess.begin():
174-
# SQLite doesn't support schemas, so we'll just create the table
175-
# Use checkfirst=True to avoid errors if the table already exists
176-
self.table.create(self.db_engine, checkfirst=True)
177-
sess.commit()
179+
# First create the table without indexes
180+
table_without_indexes = Table(
181+
self.table_name,
182+
MetaData(),
183+
*[c.copy() for c in self.table.columns],
184+
)
185+
table_without_indexes.create(self.db_engine, checkfirst=True)
186+
187+
# Then create each index individually with error handling
188+
for idx in self.table.indexes:
189+
try:
190+
idx_name = idx.name
191+
logger.debug(f"Creating index: {idx_name}")
192+
193+
# Check if index already exists using SQLite's schema table
194+
with self.SqlSession() as sess:
195+
exists_query = text(
196+
"SELECT 1 FROM sqlite_master WHERE type='index' AND name=:index_name"
197+
)
198+
exists = sess.execute(exists_query, {"index_name": idx_name}).scalar() is not None
199+
200+
if not exists:
201+
idx.create(self.db_engine)
202+
else:
203+
logger.debug(f"Index {idx_name} already exists, skipping creation")
204+
205+
except Exception as e:
206+
# Log the error but continue with other indexes
207+
logger.warning(f"Error creating index {idx.name}: {e}")
208+
178209
except Exception as e:
179210
logger.error(f"Error creating table: {e}")
180211
raise

libs/agno/agno/tools/agentql.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313

1414
class AgentQLTools(Toolkit):
15-
def __init__(
16-
self, api_key: Optional[str] = None, scrape: bool = True, agentql_query: str = ""
17-
):
15+
def __init__(self, api_key: Optional[str] = None, scrape: bool = True, agentql_query: str = ""):
1816
super().__init__(name="agentql_tools")
1917

2018
self.api_key = api_key or getenv("AGENTQL_API_KEY")

libs/agno/agno/utils/certs.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
21
from pathlib import Path
2+
33
import requests
44

5+
56
def download_cert(cert_url: str, filename: str = "cert.pem"):
67
"""
78
Downloads a CA certificate bundle if it doesn't exist locally.
8-
9+
910
Returns:
1011
str: Path to the certificate file
1112
"""
1213
cert_dir = Path("./certs")
1314
cert_path = cert_dir / filename
14-
15+
1516
# Create directory if it doesn't exist
1617
cert_dir.mkdir(parents=True, exist_ok=True)
17-
18+
1819
# Download the certificate if it doesn't exist
1920
if not cert_path.exists():
2021
response = requests.get(cert_url)
2122
response.raise_for_status()
22-
23+
2324
with open(cert_path, "wb") as f:
2425
f.write(response.content)
25-
26-
27-
return str(cert_path.absolute())
26+
27+
return str(cert_path.absolute())

0 commit comments

Comments
 (0)