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)

Naimish MakwanaPosted May 16, 2024, 5:52 AM
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:
Remember to replace
"Your Azure OpenAI Key"and"Your Azure OpenAI Endpoint"with your actual Azure OpenAI key and endpoint.Thanks
Amit MohantyPosted May 16, 2024, 5:28 AM
Try this:
Vikas SinghPosted May 15, 2024, 1:46 PM
Thanks @Amit Mohanty, Now getting another error: AttributeError: 'ConversationAnalysisClient' object has no attribute 'analyze_sentiment'
Amit MohantyPosted May 15, 2024, 11:38 AM
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.