20
20
FileSearchTool ,
21
21
Tool ,
22
22
)
23
- from azure .ai .projects .models import ConnectionType
23
+ from azure .ai .projects .models import ConnectionType , ApiKeyCredentials
24
24
from azure .identity .aio import DefaultAzureCredential
25
25
from azure .core .credentials_async import AsyncTokenCredential
26
26
@@ -74,18 +74,11 @@ async def create_index_maybe(
74
74
except ValueError as e :
75
75
logger .error ("Error creating index: {e}" )
76
76
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
88
77
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
+
89
82
search_mgr = SearchIndexManager (
90
83
endpoint = endpoint ,
91
84
credential = creds ,
@@ -94,7 +87,7 @@ async def create_index_maybe(
94
87
model = embedding ,
95
88
deployment_name = embedding ,
96
89
embedding_endpoint = aoai_connection .target ,
97
- embed_api_key = aoai_connection . credentials . api_key
90
+ embed_api_key = embed_api_key
98
91
)
99
92
# If another application instance already have created the index,
100
93
# do not upload the documents.
0 commit comments