You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The recently released Azure AI Foundry Python SDK supports retrieving Azure OpenAI connections from your Foundry project. This improves project security as you are not dealing with the AOAI endpoints and secret keys. I have not been able to find an integration point where I can initialize the SK-Python Kernel object in such a way to utilize the Foundry initialized AOAI instance.
Proposed Change
Allow the AOAI instance openai.AzureOpenAI to be injected similar to the below...
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from semantic_kernel import Kernel
import openai.AzureOpenAI
project_connection_string="<<AI Foundry connection string>>"
project = AIProjectClient.from_connection_string(conn_str=project_connection_string, credential=DefaultAzureCredential()) # or Managed Identity, etc.
# retrieve the AOAI instance from the Foundry project
injected_aoai_client = project.inference.get_azure_openai_client(api_version="2024-06-01") # this is an openai.AzureOpenAI object
# Create the Kernel object and add the existing AOAI service retrieved from the Foundry Project
kernel = Kernel(services={"azure_openai": injected_aoai_clieint})
The text was updated successfully, but these errors were encountered:
Hi @johnsinco, thanks for opening this item. I was looking for the code for the get_azure_openai_client method and it returns an AsyncAzureOpenAI client:
Thanks @moonbox3 for the quick reply. I was able to adapt your hints above and plug AI Foundry to the SK kernel like so...
importasyncio# from azure.ai.projects import AIProjectClientfromazure.ai.projects.aioimportAIProjectClient# <<-- identically named async version of the clientfromazure.identityimportDefaultAzureCredentialfromsemantic_kernelimportKernelfromsemantic_kernel.connectors.ai.open_aiimportAzureChatCompletion# Retrieve the connection string from environment variablesproject_connection_string=os.getenv("PROJECT_CONNECTION_STRING")
project=AIProjectClient.from_connection_string(
conn_str=project_connection_string,
credential=DefaultAzureCredential())
aoai_chat=AzureChatCompletion(
deployment_name="gpt-4o",
async_client=aoai_client
)
# Create the Kernel object and add the Azure OpenAI Chat Completion servicekernel=Kernel()
service_id="agent"kernel.add_service(AzureChatCompletion(service_id=service_id, async_client=aoai_client, deployment_name="gpt-4o"))
Support Foundry SDK in Python
The recently released Azure AI Foundry Python SDK supports retrieving Azure OpenAI connections from your Foundry project. This improves project security as you are not dealing with the AOAI endpoints and secret keys. I have not been able to find an integration point where I can initialize the SK-Python
Kernel
object in such a way to utilize the Foundry initialized AOAI instance.Proposed Change
Allow the AOAI instance
openai.AzureOpenAI
to be injected similar to the below...The text was updated successfully, but these errors were encountered: