Getting error using below code, As I want to access my Azure OpenAI into Google colab with python script.
However, getting error
ModuleNotFoundError Traceback (most recent call last)
1 from azure.core.credentials import AzureKeyCredential
----> 2 from azure.ai.language.conversations import ConversationAnalysisClient
3
4 # Azure OpenAI Credentials
5 key = "99d8153831534d8d9e05630ec6be0f8a"
ModuleNotFoundError: No module named 'azure.ai.language'
from azure.core.credentials import AzureKeyCredential
from azure.ai.language.conversations import ConversationAnalysisClient
# Azure OpenAI Credentials
key = "Azue OpenAI Keys"
endpoint = "Azue OpenAI Endpoint"
# Create a conversation analysis client
credential = AzureKeyCredential(key)
conversation_client = ConversationAnalysisClient(endpoint=endpoint, credential=credential)
# Prompt
prompt = "What is the capital of India?"
# Analyze sentiment
response = conversation_client.analyze_sentiment(prompt)
# Extract sentiment
sentiment = response.sentiment
# Print the sentiment
print("Sentiment:", sentiment)


Amit MohantyRank #112 · 20K reputationPosted May 15, 2024, 7:38 AM EDT
I think the azure.ai.language module is not installed in your environment. This module is part of the Azure AI Language package. Try to install the Azure AI Language package in your Google Colab environment.
Vikas SinghRank #441 · 5.7K reputationPosted May 15, 2024, 9:46 AM EDT
Thanks @Amit Mohanty, Now getting another error: AttributeError: 'ConversationAnalysisClient' object has no attribute 'analyze_sentiment'
Amit MohantyRank #112 · 20K reputationPosted May 16, 2024, 1:28 AM EDT
Try this:
Naimish MakwanaRank #324 · 7.7K reputationPosted May 16, 2024, 1:52 AM EDT
The error message
ModuleNotFoundError: No module named 'azure.ai.language'indicates that the Python moduleazure.ai.languageis not installed in your current environment.To use the Azure AI Language services, you need to install the
azure-ai-languagepackage. You can do this in Google Colab by running the following command at the beginning of your notebook:After running this command, you should be able to import the
ConversationAnalysisClientfromazure.ai.language.conversationswithout any issues.Please note that you should replace
"Azue OpenAI Keys"and"Azue OpenAI Endpoint"with your actual Azure OpenAI keys and endpoint. Be sure to keep these credentials secure and do not share them publicly.Here’s your updated code:
!pip install azure-ai-language from azure.core.credentials import AzureKeyCredential from azure.ai.language.conversations import ConversationAnalysisClient # Azure OpenAI Credentials key = "Your Azure OpenAI Key" endpoint = "Your Azure OpenAI Endpoint" # Create a conversation analysis client credential = AzureKeyCredential(key) conversation_client = ConversationAnalysisClient(endpoint=endpoint, credential=credential) # Prompt prompt = "What is the capital of India?" # Analyze sentiment response = conversation_client.analyze_sentiment(prompt) # Extract sentiment sentiment = response.sentiment # Print the sentiment print("Sentiment:", sentiment)Remember to replace
"Your Azure OpenAI Key"and"Your Azure OpenAI Endpoint"with your actual Azure OpenAI key and endpoint.Thanks