Azure AI 102 Certification - Demo
Initial Setup Script
Initial Script for Azure AI 102
1test azure AI-102
2
3https://learn.microsoft.com/en-us/python/api/overview/azure/ai-translation-text-readme?view=azure-python&preserve-view=true
Azure AI Workspace Setup





Demo Use Cases
Azure Text Translation Shell Script
1%pip install azure-ai-translation-text
2Collecting azure-ai-translation-text
3 Downloading azure_ai_translation_text-1.0.1-py3-none-any.whl.metadata (18 kB)
4Requirement already satisfied: isodate>=0.6.1 in /anaconda/envs/azureml_py310_sdkv2/lib/python3.10/site-packages (from azure-ai-translation-text) (0.6.1)
5Requirement already satisfied: azure-core>=1.30.0 in /anaconda/envs/azureml_py310_sdkv2/lib/python3.10/site-packages (from azure-ai-translation-text) (1.31.0)
6Requirement already satisfied: typing-extensions>=4.6.0 in /anaconda/envs/azureml_py310_sdkv2/lib/python3.10/site-packages (from azure-ai-translation-text) (4.12.2)
7Requirement already satisfied: requests>=2.21.0 in /anaconda/envs/azureml_py310_sdkv2/lib/python3.10/site-packages (from azure-core>=1.30.0->azure-ai-translation-text) (2.32.3)
8Requirement already satisfied: six>=1.11.0 in /anaconda/envs/azureml_py310_sdkv2/lib/python3.10/site-packages (from azure-core>=1.30.0->azure-ai-translation-text) (1.16.0)
9Requirement already satisfied: charset-normalizer<4,>=2 in /anaconda/envs/azureml_py310_sdkv2/lib/python3.10/site-packages (from requests>=2.21.0->azure-core>=1.30.0->azure-ai-translation-text) (3.3.2)
10Requirement already satisfied: idna<4,>=2.5 in /anaconda/envs/azureml_py310_sdkv2/lib/python3.10/site-packages (from requests>=2.21.0->azure-core>=1.30.0->azure-ai-translation-text) (3.10)
11Requirement already satisfied: urllib3<3,>=1.21.1 in /anaconda/envs/azureml_py310_sdkv2/lib/python3.10/site-packages (from requests>=2.21.0->azure-core>=1.30.0->azure-ai-translation-text) (2.2.3)
12Requirement already satisfied: certifi>=2017.4.17 in /anaconda/envs/azureml_py310_sdkv2/lib/python3.10/site-packages (from requests>=2.21.0->azure-core>=1.30.0->azure-ai-translation-text) (2024.8.30)
13Downloading azure_ai_translation_text-1.0.1-py3-none-any.whl (87 kB)
14Installing collected packages: azure-ai-translation-text
15Successfully installed azure-ai-translation-text-1.0.1
16Note: you may need to restart the kernel to use updated packages
17
18
19
20from azure.ai.translation.text import TextTranslationClient
21from azure.core.credentials import AzureKeyCredential
22
23# Azure Translator resource details
24endpoint = "https://translator-test.cognitiveservices.azure.com/"
25key = "dkakiimcDGV0QvQAn6RO72ngb4y5hCFiSGgOgGnH9FTyyGZ123456789"
26region = "westus"
27
28# Create the client
29client = TextTranslationClient(
30 endpoint=endpoint,
31 credential=AzureKeyCredential(key),
32 region=region
33)
34
35# Input
36body = [{"text": "Good morning!"}]
37
38# Translate
39response = client.translate(
40 body=body,
41 to_language=["fr", "es"],
42 from_language="en"
43)
44
45# Output results
46for item in response:
47 for translation in item.translations:
48 print(f"{translation.to}: {translation.text}")
49
50--------------------------------------------------------------------------------:
51
52fr: Bonjour!
53es: ¡Buenos días!
54
55
56
57(.venv) bharathkumardasaraju@demos$ python3.12 ./1.azure-text-translation.py
58English text is: Good Morning!
59
60The Telugu language code is as below
61తెలుగు ==> te
62
63the telugu language translation is this
64శుభోదయం! ==> te
65(.venv) bharathkumardasaraju@demos$
Azure Text Translation Shell Script 2
1(.venv) bharathkumardasaraju@demos$ python3.12 ./2.azure-text-translation.py
2Detected languages of the input text: en with score: 1.0.
3Text was translated to: 'cs' and the result is: 'Tohle je test'.
4Text was translated to: 'es' and the result is: 'Esto es una prueba'.
5Text was translated to: 'de' and the result is: 'Dies ist ein Test'.
6Text was translated to: 'te' and the result is: 'ఇది ఒక పరీక్ష'.
7Text was translated to: 'ta' and the result is: 'இது ஒரு சோதனை'.
8Text was translated to: 'hi' and the result is: 'यह एक कसौटी है'.
9(.venv) bharathkumardasaraju@demos$
Azure Text Translation Python Script 1
1from azure.ai.translation.text import TextTranslationClient
2from azure.core.credentials import AzureKeyCredential
3
4
5endpoint = "https://translator-bhrth-test.cognitiveservices.azure.com/"
6key = "123GV0QvQAn6RO72ngb4y5hCFiSGgOgGnH9FTyyGZTys6XJQQJ99BCAC4f1c123"
7region = "westus"
8
9# Create the client
10
11client = TextTranslationClient(
12 endpoint = endpoint,
13 credential=AzureKeyCredential(key),
14 region = region
15)
16
17body = [{"text": "Good Morning!"}]
18
19for i in body:
20 print("English text is: ", i['text'])
21
22list_of_langs = client.get_supported_languages(scope="translation")
23
24#print(list_of_langs.translation)
25
26# for langcode, nativelangname in list_of_langs.translation.items():
27# print(f"{langcode} ==> {nativelangname['nativeName']}")
28
29print("")
30print("The Telugu language code is as below")
31for langcode, nativelangname in list_of_langs.translation.items():
32 if langcode == "te":
33 print(f"{nativelangname['nativeName']} ==> {langcode}")
34
35response = client.translate(
36 body=body,
37 to_language=["te"],
38 from_language="en"
39 )
40
41# print("the response is: ", response)
42
43print("")
44for item in response:
45 for translation in item.translations:
46# print(f"the keys and values of translation is this {translation}")
47 print("the telugu language translation is this")
48 print(f"{translation.text} ==> {translation.to}")
49
50
Azure Text Translation Python Script 2
1from azure.ai.translation.text import TextTranslationClient
2from azure.core.credentials import AzureKeyCredential
3from azure.core.exceptions import HttpResponseError
4
5# Azure Translator resource details
6endpoint = "https://translator-bhrth-test.cognitiveservices.azure.com/"
7key = "DGV0QvQAn6RO72ngb4y5hCFiSGgOgGnH9FTyyGZTys6XJQQJ99BCAC4f1cMXJ3"
8region = "westus"
9
10# Create the client
11text_translator = TextTranslationClient(
12 endpoint=endpoint,
13 credential=AzureKeyCredential(key),
14 region=region
15)
16
17
18try:
19 to_language = ["cs", "es", "de", "te", "ta", "hi"]
20 input_text_elements = ["This is a test"]
21
22 response = text_translator.translate(body=input_text_elements, to_language=to_language)
23 translation = response[0] if response else None
24
25 if translation:
26 detected_language = translation.detected_language
27 if detected_language:
28 print(
29 f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}."
30 )
31 for translated_text in translation.translations:
32 print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.")
33
34except HttpResponseError as exception:
35 if exception.error is not None:
36 print(f"Error Code: {exception.error.code}")
37 print(f"Message: {exception.error.message}")
Demo Jupyter Notebooks
Azure AI Domains - Shell Scripts & Python Modules
Azure AI Solutions Demo
1Azure AI solutions
2
3CNN
4RNN
5
6Transformer Architecture
7Tokenization
8Vector Embedding
9
10Tokens and Capacity:
11
12Vectors and Embeddings
13
14Positional ENcoding: is a technique used to preserve order of words when processing natural language.
15Attention: Attention figures out each word(or token) in a sequence is important to other words within that sequence by assigning the words weights.
16self-attention,
17cross-attention,
18Multi-Head attention
19
20
21Supervised Learning(SL): -
22This is where the data has been labeled for training. It is considered as task-driven cause we are going to make a pediction get a value back.
23So when the labels are known and we want a precise outcome, When we need a specific value returned -
24examples: We will be using Classification, Regression
25
26Unsupervised Learning(USL): -
27This is where the data that has not been labeled, The ML model needs to do its own labeling,
28This is considered as Data-driven - It recognizes a structure or pattern,
29So this is where the labels are not known and outcome doesnot need to be precise. When we are trying to make sense of data.
30Examples: Clustering, Dimensionality Reduction, Association
31
32Reinforcement Learning(RI):
33So this is where, There is no data, There is environment and ML model generates data and makes many attempts to reach a goal.
34It is a Decision Driven -
35Examples: GameAI, Learning Tasks, Robot Navigation
36
37
38Neural Networks -- Deep Learning -- Feed Forward -- Backpropagation -- Loss Function -- Activation Functions -- Dense -- Sparse
39
40GPU - General Processing Unit - Optimized for Many Parallel tasks
41
42CUDA - Compute Unified Device Architecture
43Compute Unified Device Architecture(CUDA) is a parallel computing platform and API by NVIDIA that allows developers to use CUDA-enabled GPUs for general purpose computing on GPUs(GPGPU)
44
45All major deep learning frameworks are integrated with NVIDIA Deep Learning SDK.
46
47The NVIDIA Deep Learning SDK is a collection of NVIDIA libraries for deep learning.
48one of the library is cuDNN - CUDA Deep Neural Network Library(cuDNN):
49
50
51Jupyter Notebooks - Jupyter Lab
52
53Responsible-AI
541. Fairness -- Fairlearn python library
552. Reliability and Safety
563. Privacy and Security -- personally identifiable information(PII ), Anomoly detection
574. Inclusiveness
585. Transparency
596. Accountability
60
61
62
63RAI - Responsile AI
1Azure AI Services containers allows you to deploy subset of AI Service APIs via container.
2
3Azure Container Instances(ACI)
4Azure Kubernetes Service(AKS)
5
6Language containers
7Speech containers
8Vision containers
1Create Azure OpenAI workspace
2
3Azure OpenAI-Studio
4
5Azure OpenAI Services Deployment Types
6
7Azure AI - prompt engineering
1import os
2from openai import AzureOpenAI
3
4endpoint = "https://bhrthaihub1179674445.openai.azure.com/"
5model_name = "gpt-4o"
6deployment = "gpt-4o"
7
8subscription_key = "EhJSsf4BM02dSZ2cuFi0klciOP3VBEnhNJM7B2Nexlc17UNdIqOGJQQJ99BCAC4f1cMXJ3w3123"
9api_version = "2024-12-01-preview"
10
11client = AzureOpenAI(
12 api_version=api_version,
13 azure_endpoint=endpoint,
14 api_key=subscription_key,
15)
16
17response = client.chat.completions.create(
18 stream=True,
19 messages=[
20 {
21 "role": "system",
22 "content": "You are a helpful assistant.",
23 },
24 {
25 "role": "user",
26 "content": "I am going to Paris, what should I see?",
27 }
28 ],
29 max_tokens=4096,
30 temperature=1.0,
31 top_p=1.0,
32 model=deployment,
33)
34
35for update in response:
36 if update.choices:
37 print(update.choices[0].delta.content or "", end="")
38
39client.close()
40
1Azure AI models
2
3
4https://github.com/Azure-Samples/rag-data-openai-python-promptflow/tree/main
5
6https://learn.microsoft.com/en-in/azure/ai-foundry/tutorials/copilot-sdk-build-rag
1from azure.ai.translation.text import TextTranslationClient
2from azure.core.credentials import AzureKeyCredential
3from azure.core.exceptions import HttpResponseError
4
5# Azure Translator resource details
6endpoint = "https://api.cognitive.microsofttranslator.com/"
7key = "P2wvbrhxRb6ba79WnVoyyQ61i2KEhxBzDyktjcP2vLINkJQQJ99BDAC4f1cMXJ1232"
8region = "westus"
9
10# Create the client
11text_translator = TextTranslationClient(
12 endpoint=endpoint,
13 credential=AzureKeyCredential(key),
14 region=region
15)
16
17
18try:
19 to_language = ["cs", "es", "de", "te", "ta", "hi", "ka", "lt"]
20 input_text_elements = ["This is a test.. I would like to say thank you to Mr.Sam Altman! why because he invented chatGPT! Great guy!"]
21
22 response = text_translator.translate(body=input_text_elements, to_language=to_language)
23 translation = response[0] if response else None
24
25 if translation:
26 detected_language = translation.detected_language
27 if detected_language:
28 print(
29 f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}."
30 )
31 for translated_text in translation.translations:
32 print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.")
33
34except HttpResponseError as exception:
35 if exception.error is not None:
36 print(f"Error Code: {exception.error.code}")
37 print(f"Message: {exception.error.message}")
1Azure AI Services containers allows you to deploy subset of AI Service APIs via container.
2
3Azure Container Instances(ACI)
4Azure Kubernetes Service(AKS)
5
6Language containers
7Speech containers
8Vision containers
9
10Diagnostic Logging provides insights into the operations of Azure-AI services.
111. Activity Logs
122. Resource Logs
133. Metrics
14
15
16Log Analytics
17Azure Monitor -- Azure Metrics
18Event Hubs
19
20
21
22
23(.venv) bharathkumardasaraju@Azure_AI$ python3.12 ./1.azure_ai_services_endpoints.py
24Detected languages of the input text: en with score: 1.0.
25Text was translated to: 'cs' and the result is: 'Tohle je test.. Rád bych poděkoval panu Samu Altmanovi! proč, protože vynalezl chatGPT! Skvělý chlap!'.
26Text was translated to: 'es' and the result is: 'Esto es una prueba.. ¡Me gustaría dar las gracias al Sr. Sam Altman! ¿Por qué?, ¡porque inventó ChatGPT! ¡Gran tipo!'.
27Text was translated to: 'de' and the result is: 'Dies ist ein Test.. Ich möchte mich bei Herrn Sam Altman bedanken! Warum, weil er ChatGPT erfunden hat! Pfundskerl!'.
28Text was translated to: 'te' and the result is: 'ఇది ఒక పరీక్ష.. నేను మిస్టర్.సామ్ ఆల్ట్ మాన్ కు ధన్యవాదాలు చెప్పాలనుకుంటున్నాను! ఎందుకంటే అతను చాట్ జిపిటిని కనుగొన్నాడు! గొప్ప వ్యక్తి!'.
29Text was translated to: 'ta' and the result is: 'இது ஒரு சோதனை.. திரு.சாம் ஆல்ட்மேன் அவர்களுக்கு நன்றி சொல்ல விரும்புகிறேன்! ஏன் அவர் ChatGPT ஐ கண்டுபிடித்தார்! பெரிய பையன்!'.
30Text was translated to: 'hi' and the result is: 'यह एक कसौटी है।। मैं श्री सैम ऑल्टमैन को धन्यवाद कहना चाहूंगा! क्यों क्योंकि उन्होंने चैटजीपीटी का आविष्कार किया था! महान आदमी!'.
31Text was translated to: 'ka' and the result is: 'ეს ტესტია.. მინდა მადლობა გადაგიხადოთ ბატონ სემ ალტმანს! რატომ იმიტომ, რომ მან გამოიგონა chatGPT! ფსევჟნჲ!'.
32Text was translated to: 'lt' and the result is: 'Tai – testas.. Norėčiau padėkoti ponui Samui Altmanui! kodėl, nes jis išrado chatGPT! Puikus vaikinas!'.
33(.venv) bharathkumardasaraju@Azure_AI$
1(.venv) bharathkumardasaraju@Azure_AI$ python3.12 ./2.azure_ai_cohere_model.py
2Paris is a beautiful city with a rich history and culture. Here are some must-see attractions and places to visit during your trip:
3
4- Eiffel Tower: The iconic Eiffel Tower is a symbol of Paris and offers breathtaking views of the city from its observation decks. You can take an elevator or climb the stairs to enjoy the panoramic vistas.
5
6- Louvre Museum: Home to one of the world's largest and most renowned art collections, the Louvre is a must-visit for art enthusiasts. Don't miss the Mona Lisa, the Venus de Milo, and other famous works of art.
7
8- Notre-Dame Cathedral: This Gothic masterpiece is a stunning example of medieval architecture. Although the cathedral suffered damage in a fire, it is still an impressive sight and a symbol of Paris' religious history.
9
10- Champs-Élysées: This famous avenue is a hub of luxury shopping, fine dining, and entertainment. Stroll along the Champs-Élysées to admire the elegant boutiques, cafes, and the iconic Arc de Triomphe at one end.
11
12- Montmartre and Sacré-Cœur Basilica: Located on a hill, Montmartre is a charming neighborhood known for its artistic history. Visit the Sacré-Cœur Basilica, a beautiful white-domed church offering stunning views of the city.
13
14- Palace of Versailles: Take a day trip to the Palace of Versailles, a former royal residence located outside Paris. Explore the lavish halls, gardens, and the famous Hall of Mirrors.
15
16- Seine River Cruise: Enjoy a relaxing boat ride along the Seine River. This cruise offers a unique perspective of Paris, passing by iconic landmarks and providing a peaceful break from the bustling city.
17
18- Musée d'Orsay: Housed in a former railway station, the Musée d'Orsay showcases an impressive collection of impressionist and post-impressionist art, including works by Monet, Renoir, and Van Gogh.
19
20- Luxembourg Gardens: These beautiful gardens provide a peaceful escape in the heart of Paris. Enjoy a leisurely walk, rent a rowboat, or simply relax on the grass.
21
22- Sainte-Chapelle: This Gothic chapel is known for its stunning stained glass windows, considered some of the finest in the world. It's a hidden gem located within the Palais de Justice.
23
24Remember to also explore the charming neighborhoods like Le Marais, Saint-Germain-des-Près, and Montmartre for their unique atmosphere, cafes, and boutique shops. Enjoy the delicious French cuisine, try some classic dishes like croissants, macarons, and French cheeses.
25
26Make sure to check the opening hours and any necessary reservations or tickets in advance, as some attractions can get busy. Have a wonderful time in Paris!% (.venv) bharathkumardasaraju@Azure_AI$
1import os
2from azure.ai.inference import ChatCompletionsClient
3from azure.ai.inference.models import SystemMessage, UserMessage
4from azure.core.credentials import AzureKeyCredential
5
6endpoint = "https://bhrthaihub1179674445.services.ai.azure.com/models"
7model_name = "Cohere-command-r-08-2024"
8
9client = ChatCompletionsClient(
10 endpoint=endpoint,
11 credential=AzureKeyCredential("EhJSsf4BM02dSZ2cuFi0klciOP3VBEnhNJM7B2Nexlc17UNdIqOGJQQJ991319"),
12)
13
14response = client.complete(
15 stream=True,
16 messages=[
17 SystemMessage(content="You are a helpful assistant."),
18 UserMessage(content="I am going to Paris, what should I see?")
19 ],
20 max_tokens=2048,
21 temperature=0.8,
22 top_p=0.1,
23 frequency_penalty=0.0,
24 presence_penalty=0.0,
25 model=model_name
26)
27
28for update in response:
29 if update.choices:
30 print(update.choices[0].delta.content or "", end="")
31
32client.close()
1Azure AI Containers
2
3https://bkr-japanese-teacher.azurewebsites.net/
Jupyter Notebooks
Mini Demo Shell Scripts (Sub-Domains)
1Azure AI moderation Solutions
1Azure AI Moderation Solutions
1Azure Natural Language Processing
1Azure AI Document INtelligence SOlutions
1Azure AI-GenAI Solutions
1build nitelligent apps with azureAI
Azure-AI-Examples (from Microsoft GitHub)
Prompt Flow (LLMOps Usecase)
Format Output Script
1
2from promptflow import tool
3
4
5# The inputs section will change based on the arguments of the tool function, after you save the code
6# Adding type to arguments and return value will help the system show the types properly
7# Please update the function name/signature per need
8@tool
9def my_python_tool(input1: str) -> str:
10 return 'Final Answer: ' + input1
1system:
2Role: Anwser Extractor
3
4Look at the input, and try and select only the numerical answer.
5
6## Good Outputs:
7
8user: In the hockey game; Mitchell scored more points than William but fewer points than Auston. Who scored the most points? Who scored the fewest points?
9assitant: Auston most. William fewest.
10
11user: Julia went to 10 houses on her street for Halloween. 5 of the houses gave her a chocolate bar. What fraction of houses on Julia�s street gave her a chocolate bar?
12assistant 1/2
13
14user: Heather is painting a portrait of her best friend; Lisa. To make it easier; she divides the portrait into 6 equal parts. What fraction represents each part of the portrait?
15assistant 1/6
16
17user: Noah walks ? of a kilometre to school each day. He also walks ? of a kilometre to get home after school. How many kilometres does he walk in total?
18assistant: 2KM
19
20## Bad Outputs:
21
22user: In the hockey game; Mitchell scored more points than William but fewer points than Auston. Who scored the most points? Who scored the fewest points?
23assitant: Auston scored the most points and William scored the fewest points.
24
25user: Julia went to 10 houses on her street for Halloween. 5 of the houses gave her a chocolate bar. What fraction of houses on Julia�s street gave her a chocolate bar?
26assistant 5 out of 10 houses gave Julia a chocolate bar.\n\nSo, the fraction of houses that gave her a chocolate bar is 5\/10, which simplifies to 1\/2. \n\nTherefore, the fraction of houses that gave her a chocolate bar is 1\/2.
27
28user: Heather is painting a portrait of her best friend; Lisa. To make it easier; she divides the portrait into 6 equal parts. What fraction represents each part of the portrait?
29assistant The fraction representing each part of the portrait is 1\/6.",
30
31user: Noah walks ? of a kilometre to school each day. He also walks ? of a kilometre to get home after school. How many kilometres does he walk in total?
32assistant: Noah walks 1 kilometer to school each day. He also walks 1 kilometer to get home after school. In total, he walks 2 kilometers.
33
34{% for item in chat_history %}
35user:
36{{item.inputs.question}}
37assistant:
38{{item.outputs.answer}}
39{% endfor %}
40
41user:
42{{question}}
1system:
2Role: Math assistant
3
4Ouput: Provide the final numerical value as the answer, Do not output reasoning or explanation.
5
6
7{% for item in chat_history %}
8user:
9{{item.inputs.question}}
10assistant:
11{{item.outputs.answer}}
12{% endfor %}
13
14user:
15{{question}}
1$schema: https://azuremlschemas.azureedge.net/promptflow/latest/OpenAIConnection.schema.json
2name: open_ai_connection
3type: open_ai
4api_key: "<user-input>"
1$schema: https://azuremlschemas.azureedge.net/promptflow/latest/AzureOpenAIConnection.schema.json
2name: open_ai_connection
3type: azure_open_ai
4api_key: "<user-input>"
5api_base: "<user-input>"
6api_type: "azure"
1$schema: https://azuremlschemas.azureedge.net/promptflow/latest/Flow.schema.json
2environment:
3 python_requirements_txt: requirements.txt
4inputs:
5 chat_history:
6 type: list
7 is_chat_history: true
8 default: []
9 question:
10 type: string
11 is_chat_input: true
12 default: Elizabeth eats a healthy, balanced breakfast b times a week. Madison
13 sometimes skips breakfast. In total, Madison eats 3 fewer breakfasts a
14 week than Elizabeth. Write an expression that shows how many times a week
15 Madison eats breakfast.
16outputs:
17 answer:
18 type: string
19 reference: ${format_output.output}
20 is_chat_output: true
21nodes:
22- name: chat
23 type: llm
24 source:
25 type: code
26 path: chat.jinja2
27 inputs:
28 deployment_name: gpt-35-turbo
29 max_tokens: 256
30 temperature: 0.7
31 chat_history: ${inputs.chat_history}
32 question: ${inputs.question}
33 response_format:
34 type: text
35 connection: to_replace_with_connection_name
36 api: chat
37- name: llm_extract_answer
38 type: llm
39 source:
40 type: code
41 path: llm_extract_answer.jinja2
42 inputs:
43 deployment_name: gpt-35-turbo
44 response_format:
45 type: text
46 chat_history: ${inputs.chat_history}
47 question: ${chat.output}
48 connection: to_replace_with_connection_name
49 api: chat
50- name: format_output
51 type: python
52 source:
53 type: code
54 path: format_output.py
55 inputs:
56 input1: ${llm_extract_answer.output}
1promptflow
End of Azure AI 102 Content