- Active Azure Subscription (get one here).
- [Part 1] A OneDrive account (M365 or personal)
- [Part 1] An OpenAI account (either Azure OpenAI or directly from OpenAI)
- [Part 2] An Azure API Management. This is for Part 2, but this 30-120 mins to provision, so best start now.
FOR TRAINERS: You may pre-create items 1, 3, 4 and 5 above to make the lab faster.
- Create lab user accounts, with access to an Azure Resource Group.
- Pre-provision an Azure API management in this resource group.
- Provide the OpenAI API URL and API key.
IDEA: Create a new REST API using Azure Logic Apps that...
- Takes a text input
- Create an OpenAI prompt text: combining a text content from OneDrive, and the request text body
- Call OpenAI completion API, using text-davinci-002
- [Optional] Send the result to an e-mail address
- Return the result as an API Response
- On your local machine, create a text file with the filename /.txt
- In the file, enter a fun fact about yourself that the internet does not know. Avoid using special characters like the following
/ \ ' " ; < >
For exampleYOUR-NAME likes to drink coffee before sleeping.
- Go to https://onedrive.live.com/ and login with the demo account provided (or your own preferred account)
- Upload the text file that you created in #2.
- Sign into https://portal.azure.com
- Create a new Azure Logic App resource
- Resource name: /-logicapp
- Region: West US
- Resource Group: Your assigned resource group (or create a new one)
- Publish: Workflow
- Plan type: Consumption
- Zone Redundancy: Disabled
- Once created, Go to resource, this should lead you to the Logic App Designer
- Select the template "When a HTTP request is received"
- Click on "Use sample payload to generate schema" and enter the following
{"message":"Hello"}
- It should look like this
- Don't forget to save.
- Add a step Compose, which is under Data Operations
- Add as input the HTTP Request message. It should look like this
- Add a step Initialize Variable, which is under Variables
- Add a step and look for OneDrive (for personal accounts) or OneDrive for Business (for M365 accounts)
- Select the action Get file content
- Sign In with the OneDrive account you used in 1a
- In *File, browse for your text file
- Add a step Compose, which is under Data Operations
- Add as input the OneDrive File content and the Output from your compose message above. It should look like this
- Don't forget to save.
- Add a step HTTP and enter the following:
Method: POST // Change to the OpenAI completion URL if that's what you're using. URL: https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/completions?api-version=2022-12-01 Headers: 1. api-key: {your-api-key} 2. Content-Type: application/json Body: { "prompt":"{Outputs from #12}", "max_tokens": 1000 }
- Here's an example:
- Add a step Parse JSON, under Data Operations
- In the content, select the Body from the HTTP action
- In the Schema, copy-paste the following
{ "type": "object", "properties": { "id": { "type": "string" }, "object": { "type": "string" }, "created": { "type": "integer" }, "model": { "type": "string" }, "choices": { "type": "array", "items": { "type": "object", "properties": { "text": { "type": "string" }, "index": { "type": "integer" }, "finish_reason": { "type": "string" }, "logprobs": {} }, "required": [ "text", "index", "finish_reason", "logprobs" ] } }, "usage": { "type": "object", "properties": { "completion_tokens": { "type": "integer" }, "prompt_tokens": { "type": "integer" }, "total_tokens": { "type": "integer" } } } } }
- Don't forget to save.
- Add a step Append to string variable, under Variables
- For the name, select Response
- For the value, select text from the Parse JSON action. This will automatically place this action in a For each loop.
- Finally, add a step Response, under Request with the following values
Status Code: 200 Headers: 1. Content-Type: application/json Body: {"response":"{response-variable}"}
- Save.
If your logic app looks like this, congratulations! You've completed Challenge 1.
NOTE: Testing this logic app will come in the next API management challenge. But if you really want to test now, you may use Postman to try and do an HTTP POST call on the URL generated from your HTTP trigger (step 4 above).
Modify the logic app and send an e-mail or sms to yourself, with the OpenAI response. You may use SendGrid or Azure Communication Services.
- FTP and SFTP-SSH connectors
- SharePoint connector
- SQL Server
- Adobe PDF Services connector
- Zoom Meetings
- See full list here
- Also read on the on-premise gateway to connect to any of the supported on-premise data sources
IDEA: Use APIM as an abstraction layer (gateway) between the API consumer and the Azure Logic App.
- Add the Azure Logic App in API management
- Observe the generated policies, etc.
- Test the API and troubleshoot if needed.
- While still in your Azure Logic App, copy the HTTP POST URL HTTP trigger that was automatically generated (at the very top of your logic app)
- Now go to the Azure API Management resource that was created in the Pre-requisites
- On the left, click API, and click + Add API
- Click on Create from Azure Resource --> Logic App
- Browse for your logic app. And if you are sharing the API management with other lab participants, change the display name to something that says it's yours
- In the API URL suffix, enter your name abbreviation
- If it looks something like this, click Create
- A new API with a manual-invoke operation should be created. Click on this operation and observe what is auto-generated in the various parts: Frontend, Inbound processing, Backend, and Outbound processing
- Click on the Test tab and change the message. Ask something about yourself and then click Send
- If you encounter any issues, troubleshoot. (TIP: The problem may either be in the logic app or API management. You may use Postman to test-call the logic app URL directly)
- Scroll down and see the response.
IDEA: Learn about the Developer Portal. Discuss and explore the concept of Products and Subscriptions.
- Stay in the Azure Portal --> API Management resource
- Click on Overview (on the left), and then click on the Developer portal URL (on the right). This is the URL that you can send to your developers.
- Try creating an account, subscribing to a product, and testing through the portal.
- To modify the Developer Portal UI, go back to the Azure Portal and look for Developer portal --> Portal overview. Click the Developer portal button on top. This opens the portal in administrative/edit mode.