ChatGPT in PowerApps

 Since ChatGPT is introduced it has made everyone curious. This AI powered chatbot built by OpenAI is just amazing!!! 

One of the key benefits of using ChatGPT in PowerApps is its ability to understand and respond to natural language input. This can greatly enhance the user experience by allowing more intuitive interactions with the app.

To know more about anything we ask "What is that" so i just asked that from ChatGPT itself....here's a brief of what I got. 

"I am an AI assistant, trained to answer questions and assist with tasks. I am a computer program designed to process and understand natural language input, and generate responses. I use machine learning algorithms, which allows me to improve my performance over time with more data and feedback. My capabilities include language processing, information retrieval, and knowledge management. My purpose is to provide helpful and accurate information to users and assist them with tasks, and you can ask me questions on wide range of topics within my knowledge cutoff which is 2021."



Since ChatGPT is out the only thing I was thinking is implementing it inside PowerApps....I mean why not? I have tried tons of combination of OpenAI API and finally come out with something.

I have figured a way to include the Power of OpenAI in PowerApps.


Create a Power Automate Flow -

1. Create a PowerApps trigger flow.

2. Add a HTTP trigger action with following parameters

URI - https://api.openai.com/v1/completions

Header - Authorization Bearer API_KEY

Body-{

  "model": "text-davinci-001",

  "prompt": "@{triggerBody()['text']}",

  "max_tokens": 100,

  "temperature": 0,

  "top_p": 1,

  "n": 1,

  "stream": false,

  "stop": "\n"

}

API Key you can generate from OPENAI website. ("https://beta.openai.com/account/api-keys").

3. Parse the Json that you got from HTTP trigger using Parse Json.

Schema-

{
    "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"
                    },
                    "logprobs": {},
                    "finish_reason": {
                        "type""string"
                    }
                },
                "required": [
                    "text",
                    "index",
                    "logprobs",
                    "finish_reason"
                ]
            }
        },
        "usage": {
            "type""object",
            "properties": {
                "prompt_tokens": {
                    "type""integer"
                },
                "completion_tokens": {
                    "type""integer"
                },
                "total_tokens": {
                    "type""integer"
                }
            }
        }
    }
}

4. Initialize a variable and Set the variable value as "Text" obtained from Parse Json option. It will go in Apply to each loop.

5. Use respond to Power Apps option so we can get the output.




Create a PowerApps -

1. Add an Input control.

2. Add one Search Icon and assign the formula on the OnSelect 

Set(valueof,'Button->HTTP,Initializevariable,ParseJSON,Setvariable'.Run(TextInput1.Text));

valueof;

ClearCollect(coll,valueof.outputtext);

(Here I have set a variable to store value of powerautomate flow, then used a collection to store the output of powerautomate in collection)

3. Add on reload button and use it to clear collection.

4.Add one HTML control to show the result-

"<div style='

padding:11px;

background: linear-gradient(to right, #d3cce3, #e9e4f0);

box-shadow: 35px 35px 68px 0px rgba(156, 103, 238, 0.5), inset -8px -8px 16px 0px rgba(156, 103, 238, 0.6), inset 0px 11px 28px 0px rgb(255, 255, 255);

font-size:28px;

'>"& TextInput1.Text & " " &First(coll).Value& " </div>".


It really took a lot of time to identify right model from the available models.

Thanks for staying!!!! till now, I tired to make it as interesting as possible.


Do let me know your thoughts in the comment section!!!!😝😋💭


Comments

  1. Hello. Very good idea. I tried to do this flow but I receive some errors because of the variable. Can u help me, please?

    ReplyDelete

Post a Comment

If you got any doubts, Kindly let me know.

Popular posts from this blog

CHATBOT with PowerApps

Multilingual PowerApps