{
"Ocp-Apim-Subscription-Key": "YOUR_SUBSCRIPTION_KEY",
"Ocp-Apim-Subscription-Region": "YOUR_SUBSCRIPTION_REGION",
"AzureTranslateURL": "YOUR_AZURE_TRANSLATE_URL",
"YOUR_DEPLOYMENT_NAME": "YOUR_DEPLOYMENT_NAME",
"YOUR_RESOURCE_NAME": "YOUR_RESOURCE_NAME",
"api-key": "YOUR_API_KEY",
"endpoint": "YOUR_ENDPOINT",
"key": "YOUR_KEY",
"indexName": "YOUR_INDEX_NAME"
}
In this exercise we are going to walkthrough building a universal translator in C# to take an input in any language and output it in English. We will continue this process with our own documents to use retrieval augmented generation (RAG) to get a printer manual to every language in Azure! This example document is owned and produced by Epson. It just so happens to be a printer I own and have the manual for. You can use this example for any document you have access to just throw it into the example every time you see Epson.
This is a sample project and a basic tier of Azure AI Search does run about $75 per month. So be sure to tear this down after you are done with it. Everything else should be under the free or almost free usage of the rest of the services.
- Install Azure CLI If you want to follow the completed solution
- Have an Azure account
- Have access to Azure OpenAI
- .Net 8.0 (or your rest client/framework of choice)
Here is a sample architecture diagram. The challenge section of this will be replacing the logic app section. You can use any rest client or framework you want to use to call our APIs Azure will give us! Knowing that all we can use Azd up to create a resource group, Azure AI Services, Azure OpenAI, and an Azure Storage Account!
If you want more of a hands on challenge try creating each of these resources yourself by hand, and then manually indexing the data in Azure Search. This will give you a better understanding of how each of these services work and how they can be used in a real world scenario.
Talking about the resources from ingress to egress we have our app, next we will call Azure AI Services to identify the language coming in and translating it to English, we then will take that output and send it to Azure OpenAI understand our question and generate a response with our data stored in Azure Search, Azure Search is connected and will have indexed our data stored in our storage account, Azure Open AI's response will go back into Azure AI Services to return it in the language we want, finally sending back the user's request in the language they requested.
If you want to follow along and skip the challenge section you can run the following commands to create the resources needed for this project.
We are going to run the deploy.sh script. This script will
- Create a resource group
- Create an Azure AI Services resource
- Create an Azure OpenAI resource
- Create an Azure Storage Account
- Create a container in the storage account called testcontainer
- Create an Azure Search resource
First you want to run az login and confirm you are in the right subscription. Then run the following commands
./Infra/deploy.sh
By the end of this you will now have an Azure AI Services resource, an Azure OpenAI resource, an Azure Storage Account, and an Azure Search resource. Now we will move onto the next step.
Now that we have our storage account and AI Search services created we need to create a container in our storage account and upload our document in our documents folder. After that we are going to add it as a data source in our Azure Search service and index the data!
Hint 1 Option 2 File Upload CLI
Make sure you wap out with your details. storageAccountKey=$(az storage account keys list --account-name mystorageaccount --query "[0].value" --output tsv)
az storage blob upload --account-name mystorageaccount --account-key $storageAccountKey --container-name mycontainer --name myblob --type block --file ./Document/epsonManual.pdf --output table
Now that we have our resources created we will need to create a rest client to call our APIs. We will need to call Azure AI Services to identify the language and translate it to English. We will also want to save off the incoming language so we can translate it back later. Get to reading documentation and start coding!
Hint 1
Here is the docs for Azure AI Services specifically the translate API.
Hint 2
URL Doesn't work anymore but good for inspiration use this URL format instead /translate?api-version=3.0&to=enHint 3
Example body should look like the following[
{"Text":"I would really like to drive your car around the block a few times."}
]
If you are still stuck don't worry! Check out FIRST API CALL in SampleConsoleApp/Program.cs in the code folder for a sample implementation.
Now we need to make a rest call to our Azure OpenAI service giving it access to our data in Azure Search. We are going to pass the result from Challenge 3 into the content section of our call.
Hint 1
Here is the docs for Azure OpenAI specifically the extensions API.
If you can't figure it out checkout SECOND API CALL in SampleConsoleApp/Program.cs in the code folder for a sample implementation.
Now we should have our data back from our document and we can translate it back from the language we first received. We will need to call Azure AI Services again to translate it back to the language we received in the first call.
Hint 1
Here is the docs for Azure AI Services specifically the translate API.
If you are still stuck don't worry! Check out THIRD API CALL in SampleConsoleApp/Program.cs in the code folder for a sample implementation.
You are now able to build a universal translator to get any language in and back out in your rest client of choice. If you are using my sample app you now have a console app and an example on how you can bring AI into you C# code!
The program now accepts a command line argument for the phrase to be translated. If no command line argument is provided, the program will use a default phrase.
dotnet run --project SampleConsoleApp "Your phrase to be translated"
If no command line argument is provided, the program will use the default phrase: "Boutons et voyants du panneau de commande\n".