2020 FileSearchTool ,
2121 Tool ,
2222)
23- from azure .ai .projects .models import ConnectionType
23+ from azure .ai .projects .models import ConnectionType , ApiKeyCredentials
2424from azure .identity .aio import DefaultAzureCredential
2525from azure .core .credentials_async import AsyncTokenCredential
2626
@@ -74,18 +74,11 @@ async def create_index_maybe(
7474 except ValueError as e :
7575 logger .error ("Error creating index: {e}" )
7676 return
77- if aoai_connection .credentials is None or aoai_connection .credentials .api_key is None :
78- err = "Error getting the connection to Azure Open AI service. {}"
79- if aoai_connection is not None and (aoai_connection .key is None or aoai_connection .credentials .api_key is None ):
80- logger .error (
81- err .format (
82- "Please configure "
83- f"{ aoai_connection .name } to use API key." ))
84- else :
85- logger .error (
86- err .format ("Azure Open AI service connection is absent." ))
87- return
8877
78+ embed_api_key = None
79+ if aoai_connection .credentials and isinstance (aoai_connection .credentials , ApiKeyCredentials ):
80+ embed_api_key = aoai_connection .credentials .api_key
81+
8982 search_mgr = SearchIndexManager (
9083 endpoint = endpoint ,
9184 credential = creds ,
@@ -94,7 +87,7 @@ async def create_index_maybe(
9487 model = embedding ,
9588 deployment_name = embedding ,
9689 embedding_endpoint = aoai_connection .target ,
97- embed_api_key = aoai_connection . credentials . api_key
90+ embed_api_key = embed_api_key
9891 )
9992 # If another application instance already have created the index,
10093 # do not upload the documents.
0 commit comments