Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 14 additions & 26 deletions tools/load_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from typeagent.aitools import utils
from typeagent.knowpro.convsettings import ConversationSettings
from typeagent.podcasts import podcast
from typeagent.storage.sqlite.provider import SqliteStorageProvider
from typeagent.storage.utils import create_storage_provider


Expand Down Expand Up @@ -69,8 +68,8 @@ async def load_json_to_database(
conversation = await podcast.Podcast.read_from_file(
podcast_file_prefix, settings, dbname
)
if isinstance(provider, SqliteStorageProvider):
provider.db.commit()
async with provider:
pass # Commit happens in __aexit__
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, no, no! The async with goes around lines 68-70.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bfab170 - moved async with provider: to wrap the read_from_file call (lines 68-71).


# Print statistics
if verbose:
Expand All @@ -91,19 +90,6 @@ def main():
"""Main entry point."""
parser = argparse.ArgumentParser(
description="Load JSON-serialized podcast data into a SQLite database",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python tools/load_json.py tests/testdata/Episode_53_AdrianTchaikovsky_index -d podcast.db
python tools/load_json.py path/to/index -d output.db -v

Note: The index path should exclude the "_data.json" suffix.
""",
)

parser.add_argument(
"index_path",
help="Path to the podcast index files (excluding the '_data.json' suffix)",
)

parser.add_argument(
Expand All @@ -120,9 +106,14 @@ def main():
help="Show verbose output including statistics",
)

parser.add_argument(
"index_path",
help="Path to the podcast index files (excluding the '_data.json' suffix)",
)

args = parser.parse_args()

# Validate index file exists
# Ensure index file exists
index_file = args.index_path + "_data.json"
if not os.path.exists(index_file):
raise SystemExit(
Expand All @@ -135,16 +126,13 @@ def main():
utils.load_dotenv()

# Run the loading process
try:
asyncio.run(
load_json_to_database(
args.index_path,
args.database,
args.verbose,
)
asyncio.run(
load_json_to_database(
args.index_path,
args.database,
args.verbose,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove the trailing comma and re-run make format the load_json_to_database() call will likely collapse on one line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bfab170 - removed trailing comma and ran black formatter, which collapsed the call to one line.

)
except (RuntimeError, ValueError) as err:
raise SystemExit(f"Error: {err}")
)


if __name__ == "__main__":
Expand Down
8 changes: 1 addition & 7 deletions tools/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,7 @@ async def main():
provider = await settings.get_storage_provider()
msgs = await provider.get_message_collection()
if await msgs.size() == 0:
raise SystemExit(
f"Error: Database '{args.database}' is empty.\n"
f"Please load data into the database first using tools/load_json.py:\n"
f" python tools/load_json.py <index_path> -d {args.database}\n"
f"Example:\n"
f" python tools/load_json.py tests/testdata/Episode_53_AdrianTchaikovsky_index -d {args.database}"
)
raise SystemExit(f"Error: Database '{args.database}' is empty.")

with utils.timelog(f"Loading conversation from database {args.database!r}"):
conversation = await podcast.Podcast.create(settings)
Expand Down