Issues with AI Client when connecting to AI Studio Projects through Python SDK
- Package Name: azure-ai-resources
- Package Version:
- Operating System: Windows 11
- Python Version: 3.11.8
Describe the bug Issues connecting to the AI Client in the azure-ai-generative portion of the Azure AI SDK. Link: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/ai/azure-ai-generative#connecting-to-projects. I am getting the following error but have Owner access to my AI Studio project.
Code: AuthorizationFailed Message: The client '' with object id '' does not have authorization to perform action 'Microsoft.MachineLearningServices/workspaces/read' over scope '/subscriptions//resourceGroups/rg-dthakarai/providers/Microsoft.MachineLearningServices/workspaces/' or the scope is invalid. If access was recently granted, please refresh your credentials.
To Reproduce Steps to reproduce the behavior:
from azure.ai.resources.client import AIClient
from azure.identity import DefaultAzureCredential
ai_client = AIClient(
credential=DefaultAzureCredential(),
subscription_id='subscription_id',
resource_group_name='resource_group',
project_name='project_name'
)
Expected behavior Successfully be able to connect to the project.
Thank you for your feedback. Tagging and routing to the team member best able to assist.
same., unabel to connect.
from azure.ai.ml.entities import CustomerManagedKey, WorkspaceHub ImportError: cannot import name 'WorkspaceHub' from 'azure.ai.ml.entities'
from azure.ai.resources.client import AIClient from azure.identity import DefaultAzureCredential
ai_client = AIClient( credential=DefaultAzureCredential(), subscription_id='subscription_id', resource_group_name='resource_group', project_name='project_name' )
from azure.ai.ml.entities import CustomerManagedKey, WorkspaceHub ImportError: cannot import name 'WorkspaceHub' from 'azure.ai.ml.entities'
Please degrade your azure-ai-ml by pip install azure-ai-ml==1.15.0 as WorkspaceHub got renamed after this version but the main package didn't
thanks,
i am contnoiulsy facing below
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\COPILOT_MS\deploy\10-june\flask-app.venv\Lib\site-packages\promptflow_core\flow_execution_context.py", line 90, in invoke_tool result = self._invoke_tool_inner(node, f, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\COPILOT_MS\deploy\10-june\flask-app.venv\Lib\site-packages\promptflow_core\flow_execution_context.py", line 206, in _invoke_tool_inner raise ToolExecutionError(node_name=node_name, module=module) from e promptflow._core._errors.ToolExecutionError: Execution failure in 'evaluate_with_rai_service': (ClientAuthenticationError) DefaultAzureCredential failed to retrieve a token from the included credentials. Attempted credentials: EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured. Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot this issue. ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint. SharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache. AzureCliCredential: Failed to invoke the Azure CLI AzurePowerShellCredential: Failed to invoke PowerShell AzureDeveloperCliCredential: Azure Developer CLI could not be found. Please visit https://aka.ms/azure-dev for installation instructions and then,once installed, authenticate to your Azure account using 'azd auth login'. To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot. 2024-06-11 02:37:21 +0530 31932 execution.flow ERROR Flow execution has failed. Cancelling all running nodes: evaluate_with_rai_service.
i have already passed below
Load environment variables from .env file
load_dotenv()
Use DefaultAzureCredential to authenticate using environment variables or other available credentials
credential = DefaultAzureCredential()
Initialize Azure Resource Management client with the credentials
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID") resource_client = ResourceManagementClient(credential, subscription_id)
# Initialize Azure OpenAI Connection with your environment variables
model_config = AzureOpenAIModelConfiguration( azure_endpoint=os.environ.get('AZURE_OPENAI_ENDPOINT'), api_key=os.environ.get('OPENAI_API_KEY'), azure_deployment=os.environ.get('deployment'), api_version=os.environ.get('OPENAI_API_VERSION'), )
# Initialize Azure AI Studio credentials
config_path = 'config.json' with open(config_path, 'r') as config_file: config = json.load(config_file) azure_ai_project = { 'subscription_id': config.get('subscription_id'), 'resource_group_name': config.get('resource_group_name'), 'project_name': config.get('project_name') }
my requirements.txt
Flask pandas Flask-RESTful python-dotenv openpyxl openai azure.identity azure.mgmt.resource azure-ai-ml==1.15.0 azure.ai.resources promptflow promptflow.core fonttools>=4.22.0 regex>=2022.1.18 promptflow-azure promptflow-evals
also app seems work fine in local but wehn deployed in Azure web app as end point, ot say
{ "message": "Exception occurred while publishing the message", "error": "Azure CLI not found on path" }
I did this inside jupyter notebook to fix the issue !az login --scope https://management.azure.com/.default
!az login --scope https://management.azure.com/.default
this gives pop to login in azure. we need manage azure cli access through code only & no pop window, from backhand.