5555 Topic ,
5656)
5757from typeagent .podcasts import podcast
58- from typeagent .storage .sqlite .provider import SqliteStorageProvider
5958from typeagent .storage .utils import create_storage_provider
6059
6160### Classes ###
@@ -536,24 +535,6 @@ async def main():
536535 args = parser .parse_args ()
537536 fill_in_debug_defaults (parser , args )
538537
539- # Validate required podcast argument
540- if args .podcast is None and args .database is None :
541- scriptname = sys .argv [0 ]
542- raise SystemExit (
543- f"Error: Either --podcast or --database is required.\n "
544- f"Usage: python { scriptname } --podcast <path_to_index>\n "
545- f" or: python { scriptname } --database <path_to_database>\n "
546- f"Example: python { scriptname } --podcast tests/testdata/Episode_53_AdrianTchaikovsky_index"
547- )
548- if args .podcast is not None :
549- index_file = args .podcast + "_data.json"
550- if not os .path .exists (index_file ):
551- raise SystemExit (
552- f"Error: Podcast index file not found: { index_file } \n "
553- f"Please verify the path exists and is accessible.\n "
554- f"Note: The path should exclude the '_data.json' suffix."
555- )
556-
557538 if args .logfire :
558539 utils .setup_logfire ()
559540
@@ -564,9 +545,18 @@ async def main():
564545 args .database ,
565546 podcast .PodcastMessage ,
566547 )
567- query_context = await load_podcast_index (
568- args .podcast , settings , args .database , args .verbose
569- )
548+
549+ # Load existing database
550+ provider = await settings .get_storage_provider ()
551+ msgs = await provider .get_message_collection ()
552+ if await msgs .size () == 0 :
553+ raise SystemExit (f"Error: Database '{ args .database } ' is empty." )
554+
555+ with utils .timelog (f"Loading conversation from database { args .database !r} " ):
556+ conversation = await podcast .Podcast .create (settings )
557+
558+ await print_conversation_stats (conversation , args .verbose )
559+ query_context = query .QueryEvalContext (conversation )
570560
571561 ar_list , ar_index = load_index_file (
572562 args .qafile , "question" , QuestionAnswerData , args .verbose
@@ -943,12 +933,6 @@ def make_arg_parser(description: str) -> argparse.ArgumentParser:
943933 ),
944934 )
945935
946- parser .add_argument (
947- "--podcast" ,
948- type = str ,
949- default = None ,
950- help = "Path to the podcast index files (excluding the '_data.json' suffix)" ,
951- )
952936 explain_qa = "a list of questions and answers to test the full pipeline"
953937 parser .add_argument (
954938 "--qafile" ,
@@ -973,8 +957,8 @@ def make_arg_parser(description: str) -> argparse.ArgumentParser:
973957 "-d" ,
974958 "--database" ,
975959 type = str ,
976- default = None ,
977- help = "Path to the SQLite database file (default: in-memory) " ,
960+ required = True ,
961+ help = "Path to the SQLite database file" ,
978962 )
979963 parser .add_argument (
980964 "--query" ,
@@ -1110,30 +1094,6 @@ def fill_in_debug_defaults(
11101094### Data loading ###
11111095
11121096
1113- async def load_podcast_index (
1114- podcast_file_prefix : str ,
1115- settings : ConversationSettings ,
1116- dbname : str | None ,
1117- verbose : bool = True ,
1118- ) -> query .QueryEvalContext :
1119- provider = await settings .get_storage_provider ()
1120- msgs = await provider .get_message_collection ()
1121- if await msgs .size () > 0 : # Sqlite provider with existing non-empty database
1122- with utils .timelog (f"Reusing database { dbname !r} " ):
1123- conversation = await podcast .Podcast .create (settings )
1124- else :
1125- with utils .timelog (f"Loading podcast from { podcast_file_prefix !r} " ):
1126- conversation = await podcast .Podcast .read_from_file (
1127- podcast_file_prefix , settings , dbname
1128- )
1129- if isinstance (provider , SqliteStorageProvider ):
1130- provider .db .commit ()
1131-
1132- await print_conversation_stats (conversation , verbose )
1133-
1134- return query .QueryEvalContext (conversation )
1135-
1136-
11371097def load_index_file [T : Mapping [str , typing .Any ]](
11381098 file : str | None , selector : str , cls : type [T ], verbose : bool = True
11391099) -> tuple [list [T ], dict [str , T ]]:
0 commit comments