1

**Update: It's a shame Microsoft set a redirect of the tutorial I was using for this Stackoverflow question and the tutorial is now lost and replaced without it being the same tutorial or code. If Microsoft is reading this, it would more helpful you keep the existing page but mark it outdated, stale. Fortunately I have found the original website on the azure docs github repo if someone can help with this stackoverflow question. https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/ai-studio/how-to/generate-data-qa.md

I am following tutorial using Azure AI SDK but the sdk fails to connect to ai studio project openai resource.

I have a connected resource and deployment of an AzureOpenAI resource in the Azure AI Studio project.

enter image description here

enter image description here

enter image description here

Separately, I have an OpenAI connection to the Azure AI Hub. I have I also created a compute.

enter image description here

enter image description here

enter image description here

The ai_client is successful but AIClient get_default_aoai_connection fails to find openai resource:

def connect_to_openai(self):
    subscription = "myazuresubscriptionid"  # Subscription of your AI Studio project
    resource_group = "Quiz-Test"  # Resource Group of your AI Studio project
    project = "quiz-ai-project"  # Name of your AI Studio Project
    ai_client = AIClient(
        subscription_id=subscription,
        resource_group_name=resource_group,
        project_name=project,
        credential=DefaultAzureCredential()
    )

    # Let's get the default AOAI connection
    print("Before AOAI")
    aoai_connection = ai_client.get_default_aoai_connection()

I did not see a setting to set a default azureopenAI model but I only have one. The log shows it sends a request for Default_AzureOpenAI , how can I change it to look for Quiz-Test-OpenAI openai resource I created and connected?

https://management.azure.com/subscriptions/ccb8b6a1-1ab6-4da3-b832-532955cf3be0/resourceGroups/Quiz-Test/providers/Microsoft.MachineLearningServices/workspaces/quiz-ai-hub/connections/Default_AzureOpenAI?api-version=REDACTED' Exception: ResourceNotFoundError: (UserError) Connection Default_AzureOpenAI can't be found in this workspace

Full Log:

[2024-05-21T08:01:36.925Z] AzureCliCredential.get_token succeeded
[2024-05-21T08:01:36.926Z] DefaultAzureCredential acquired a token from AzureCliCredential
[2024-05-21T08:01:36.926Z] Request URL: 'https://management.azure.com/subscriptions/ccb8b6a1-1ab6-4da3-b832-532955cf3be0/resourceGroups/Quiz-Test/providers/Microsoft.MachineLearningServices/workspaces/quiz-ai-hub/connections/Default_AzureOpenAI?api-version=REDACTED'
Request method: 'GET'
Request headers:
    'Accept': 'application/json'
    'x-ms-client-request-id': '58a33908-1748-11ef-9728-8c1d96da156e'
    'User-Agent': 'azure-ai-resources/1.0.0b2 azure-ai-ml/1.13.0 azsdk-python-mgmt-machinelearningservices/0.1.0 Python/3.10.11 (Windows-10-10.0.22621-SP0)'
    'Authorization': 'REDACTED'
No body was attached to the request
[2024-05-21T08:01:37.110Z] ActivityCompleted: Activity=WorkspaceConnections.Get, HowEnded=Failure, Duration=714.25 [ms], Exception=ResourceNotFoundError
[2024-05-21T08:01:37.110Z] Response status: 404
Executed 'Functions.http_trigger' (Failed, Id=d676dd6c-3130-48e6-bdf4-54b57ae1e6a5, Duration=2450ms)

[2024-05-21T07:47:46.185Z] System.Private.CoreLib: Exception while executing function: Functions.http_trigger. System.Private.CoreLib: Result: Failure
**Exception: ResourceNotFoundError: (UserError) Connection Default_AzureOpenAI can't be found in this workspace
Code: UserError
Message: Connection Default_AzureOpenAI can't be found in this workspace**
Stack:   File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 604, in _handle__invocation_request

0