How to add model from Azure AI Studio Chat Playground into MS Automate Flow

Tharun Tharukaran 0 Reputation points
2024-03-20T10:51:07.4833333+00:00

I'm currently creating a JSON formatter assistant in Azure OpenAI Studio Chat Playground, and have added data to make the model more suited to it's role. The AI works as it should in the chat playground but I'd like it to be run through inputs by MS automate flow, with the chat's output also given back to the MS flow. Is this possible and if so, how would I go about doing this?

I've currently tried a HTTP request in a MS flow which calls the model used in the Azure Open AI Chat Playground, but this doesn't include the indexing and preprocessing that has been done with my own data.

Thank you in advance!

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,098 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,628 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 22,031 Reputation points Volunteer Moderator
    2024-03-20T13:07:05.25+00:00

    Hello Tharun Tharukaran

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    Sequel to your questions, I understand that you would like to integrate your Azure OpenAI Studio Chat Playground model with Microsoft Power Automate. You were asking if it is possible and if so, how would you go about doing it.

    Most of all! Yes, it's possible to integrate your Azure OpenAI Studio Chat Playground model with Microsoft Power Automate.

    Now on how to do this, there are general overview and best practice on how you can do this.

    I will be providing best practices here with more detailed and structured approach to implementing the integration between your Azure OpenAI Studio Chat Playground model and Microsoft Power Automate, following best practices:

    1. Input and Output definitions: Clearly define what inputs your model expects (e.g., raw text, structured data) and what kind of output it produces (e.g., formatted JSON). Ensure that your Power Automate flow is designed to handle these inputs and outputs effectively.
    2. Create Azure Function: Consider creating an Azure Function that acts as a middleware between Power Automate and your model. This can help abstract away the complexities of calling your model's API directly from Power Automate. The Azure Function can handle tasks such as input validation, preprocessing, and error handling before sending requests to your model.
         const axios = require('axios');
         module.exports = async function (context, req) {
             try {
                 // Validate input
                 if (!req.body || !req.body.text) {
                     context.res = {
                         status: 400,
                         body: "Invalid input. 'text' field is required."
                     };
                     return;
                 }
                 // Call OpenAI Studio API
                 const response = await axios.post('YOUR_MODEL_API_ENDPOINT', {
                     text: req.body.text
                 }, {
                     headers: {
                         'Content-Type': 'application/json',
                         'Authorization': 'Bearer YOUR_API_KEY'
                     }
                 });
                 // Process response
                 const responseData = response.data;
                 // Return formatted response
                 context.res = {
                     body: responseData
                 };
             } catch (error) {
                 // Handle errors
                 context.res = {
                     status: error.response ? error.response.status : 500,
                     body: error.message
                 };
             }
         };
         
      
      The code above represents a simple Azure Function written in Node.js that acts as middleware between Power Automate and your OpenAI Studio Chat Playground model. It validates input, makes a request to the model API, handles errors, and returns the response to Power Automate. Make sure to replace 'YOUR_MODEL_API_ENDPOINT' and 'YOUR_API_KEY' with your actual model API endpoint and API key, respectively. You will deploy this Azure Function to your Azure subscription and configure Power Automate to call this function as part of your workflow.
    3. Design and Implement Error Handling: Incorporate robust error handling mechanisms at each step of the flow. This includes handling cases such as network errors, API failures, and invalid inputs. Use retries mechanisms with exponential backoff to handle transient failures gracefully. Provide informative error messages or notifications to users or administrators when errors occur.
    4. Secure API: Ensure that access to your model's API endpoint is secured using appropriate authentication mechanisms (e.g., API keys, OAuth tokens). Implement rate limiting and throttling to prevent abuse or excessive usage of your API.
    5. Others will be to monitor, test, document, and continuous review and updates.

    You can utilize the documents and references available by the right side of this page for more reading.

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    Please remember to "Accept Answer" if answer helped, so that others in the community facing similar issues can easily find the solution.

    Best Regards,

    Sina Salam

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.