@@ -382,7 +382,7 @@ async def process_files():
382382 docs .extend (await prepare_search_doc (content , conversation_id , path .name , embeddings_client ))
383383 counter += 1
384384 except Exception :
385- logging . exception ( "Error processing transcript file %s" , path . name )
385+ pass
386386 if docs != [] and counter % 10 == 0 :
387387 result = search_client .upload_documents (documents = docs )
388388 docs = []
@@ -536,22 +536,11 @@ async def call_topic_mining_agent(topics_str1):
536536 mined_topics = ", " .join (mined_topics_list )
537537 print (f"✓ Mined { len (mined_topics_list )} topics" )
538538
539- async def call_topic_mapping_agent (input_text , list_of_topics ):
539+ async def call_topic_mapping_agent (agent , input_text , list_of_topics ):
540540 """Use Topic Mapping Agent with Agent Framework to map topic to category."""
541- async with (
542- AsyncAzureCliCredential (process_timeout = 30 ) as async_cred ,
543- AIProjectClient (endpoint = AI_PROJECT_ENDPOINT , credential = async_cred ) as project_client ,
544- ):
545- # Create provider for agent management
546- provider = AzureAIProjectAgentProvider (project_client = project_client )
547-
548- # Get agent using provider
549- agent = await provider .get_agent (name = TOPIC_MAPPING_AGENT_NAME )
550-
551- query = f"""Find the closest topic for this text: '{ input_text } ' from this list of topics: { list_of_topics } """
552-
553- result = await agent .run (query )
554- return result .text .strip ()
541+ query = f"""Find the closest topic for this text: '{ input_text } ' from this list of topics: { list_of_topics } """
542+ result = await agent .run (query )
543+ return result .text .strip ()
555544
556545 cursor .execute ('SELECT * FROM processed_data' )
557546 rows = [tuple (row ) for row in cursor .fetchall ()]
@@ -562,10 +551,22 @@ async def call_topic_mapping_agent(input_text, list_of_topics):
562551 # Map topics using agent asynchronously
563552 async def map_all_topics ():
564553 """Map all topics to categories using agent."""
565- for _ , row in df_processed_data .iterrows ():
566- mined_topic_str = await call_topic_mapping_agent (row ['topic' ], str (mined_topics_list ))
567- cursor .execute ("UPDATE processed_data SET mined_topic = ? WHERE ConversationId = ?" , (mined_topic_str , row ['ConversationId' ]))
568- conn .commit ()
554+ # Create credential, project client, provider, and agent once for reuse
555+ async with (
556+ AsyncAzureCliCredential (process_timeout = 30 ) as async_cred ,
557+ AIProjectClient (endpoint = AI_PROJECT_ENDPOINT , credential = async_cred ) as project_client ,
558+ ):
559+ # Create provider for agent management
560+ provider = AzureAIProjectAgentProvider (project_client = project_client )
561+
562+ # Get agent using provider
563+ agent = await provider .get_agent (name = TOPIC_MAPPING_AGENT_NAME )
564+
565+ # Process all rows using the same agent instance
566+ for _ , row in df_processed_data .iterrows ():
567+ mined_topic_str = await call_topic_mapping_agent (agent , row ['topic' ], str (mined_topics_list ))
568+ cursor .execute ("UPDATE processed_data SET mined_topic = ? WHERE ConversationId = ?" , (mined_topic_str , row ['ConversationId' ]))
569+ conn .commit ()
569570
570571 asyncio .run (map_all_topics ())
571572
0 commit comments