Skip to main content

Notifications

Copilot Studio - General
Answered

Integrate a PVA chatbot with Azure OpenAI ChatGPT using the Chat Completion API format

Posted on by

OpenAI ChatGPT and GPT-4 models are both optimized for conversational interfaces. This means they accept input formatted as a conversation. The main benefit is retaining the conversation context (i.e. the history of past questions and answers), so that any new follow up question is made in the context of past interactions.

 

Example in ChatGPT, where the question "Who was it before?" only makes sense in the context of the previous questions and answers: 

HenryJammes_1-1683653156588.png

 

To replicate this behavior in Power Virtual Agents, you integrate with the Azure OpenAI Service APIs using a Power Automate cloud flow.

For each of the requests you make to Azure OpenAI, you need to retain the context of previous questions and answers. 

The Chat Completion API is a new dedicated API for interacting with the ChatGPT and GPT-4 models in conversational manner. 

Chat Completion is optimized and will lead to better results than the previous Chat Markup Language (ChatML) format.

 

The format allows you to set the system prompt (with instructions, rules, data, etc.) as well as a format for the following question and answers, between the bot and the user. It's formatted in JSON.

Below is an example of the above example conversation:

 

[
    {
        "role": "system",
        "content": "You are an AI assistant that helps people find information."
    },
    {
        "role": "user",
        "content": "Who was Microsoft CEO in 2020?"
    },
    {
        "role": "assistant",
        "content": "In 2020, the CEO of Microsoft was Satya Nadella. He has been the CEO of Microsoft since 2014."
    },
    {
        "role": "user",
        "content": "Who was it before?"
    },
    {
        "role": "assistant",
        "content": "Before Satya Nadella, Steve Ballmer was the CEO of Microsoft. He served as the CEO from 2000 to 2014, following Bill Gates who co-founded Microsoft and served as CEO for many years."
    }
]

 

You can learn more about Chat Completion API here:

How to work with the ChatGPT and GPT-4 models (preview) - Azure OpenAI Service | Microsoft Learn

 

You cannot keep an infinitely large history of past interactions. Each model has a token limit. 

You can learn more on how to remain the thoken limit here.

 

In the below example, I show how to integrate Power Virtual Agents with Azure OpenAI with Power Automate, and use the Chat Completion API to retain conversation context.

  • In the first post, I show how to do this using the Power Virtual Agents new unified authoring canvas.
  • In the second post, I show how to do this using the classic version of Power Virtual Agents (using Bot Framework Composer).

 

Important note:

 

Prerequisites for the below articles:

  • AkshayShinde Profile Picture
    AkshayShinde 7 on at
    Re: Integrate a PVA chatbot with Azure OpenAI ChatGPT using the Chat Completion API format

    Hello @adasilva ,

     

    This will help: Solved: Re: Citations / references not showing in the chat... - Page 2 - Power Platform Community (microsoft.com)

  • adasilva Profile Picture
    adasilva 41 on at
    Re: Integrate a PVA chatbot with Azure OpenAI ChatGPT using the Chat Completion API format

    How can you make it include the URL references on the answers?

  • remidyon Profile Picture
    remidyon on at
    Re: Integrate a PVA chatbot with Azure OpenAI ChatGPT using the Chat Completion API format

    Hi @AkshayShinde 

    If you want to use the GPT model's internal knowledge you can use a power automate flow to call the "create text using GPT" action (from AI builder) and send your question to the model and the answer back to your Copilot just like a ChatGPT

  • AkshayShinde Profile Picture
    AkshayShinde 7 on at
    Re: Integrate a PVA chatbot with Azure OpenAI ChatGPT using the Chat Completion API format

    Hello @remidyon,

     

    Thank you for the training links, I have completed them, and I have also created a chatbot!

     

    My chatbot has multiple topics as per my requirement. I have also added multiple public websites in it so that generative answers work properly, but there is limitation on how many websites I can add. Thus, I was wondering if I can integrate ChatGPT with my chatbot so that it can answer complex questions easily with help of ChatGPT.

     

    If this is possible, can you please tell me how I can achieve this? I would like to keep my existing topics, files and websites as primary source of information.

  • remidyon Profile Picture
    remidyon on at
  • AkshayShinde Profile Picture
    AkshayShinde 7 on at
    Re: Integrate a PVA chatbot with Azure OpenAI ChatGPT using the Chat Completion API format

    Hello @HenryJammes,

     

    Thank you very much for the amazing solution.

     

    I am working on an internal team chatbot which will help team in 2 scenarios:

    1. Information and doubt solving with internal documentation and processes, which i have uploaded in chatbot as word and excel files.

    2. General Procurement and negotiation related queries, which can be answered by chatbot like ChatGPT. 

     

    how can i make this happen?

  • Re: Integrate a PVA chatbot with Azure OpenAI ChatGPT using the Chat Completion API format

    Hello @HenryJammes ,

    Thanks a lot for your sharing. I got a ActionResponseSkipped at the last step. Do you have any idea about this ? thanks in advance.gpt.PNG

  • Renad Profile Picture
    Renad 67 on at
    Re: Integrate a PVA chatbot with Azure OpenAI ChatGPT using the Chat Completion API format

    Hello there @HenryJammes I've followed your tutorial with wonderful results. Thanks for the succinct explanation. 

    I'd like to know the changes needed for creating a dedicated Azure OpenAI ChatGPT topic though, since the method described replies on every question being appended to FullDialog since it's an UnrecognizedTriggerPhrase.

    This is what I got in mind but it obviously can't parse every follow up question by the user.

    Renad_0-1698136217058.png

    Renad_1-1698136261128.png

    Any suggestions would be helpful. TIA.

  • Meliodas Profile Picture
    Meliodas 2 on at
    Re: Integrate a PVA chatbot with Azure OpenAI ChatGPT using the Chat Completion API format

    Hi Henry! 

    Is there a fix for this error? I think that the "" are getting appended ..

    Meliodas_0-1696866085401.png

     

     

  • Samuel-Zhou Profile Picture
    Samuel-Zhou 388 on at
    Re: Integrate a PVA chatbot with Azure OpenAI ChatGPT using the Chat Completion API format

    @HenryJammes Thanks for the response. How do I set up expressions in Power Automate?

Helpful resources

Quick Links

Welcome to the Power Platform…

We are thrilled to unveil the newly-launched Power Platform Communities!…

Getting Started…

Welcome to the Power Platform Community! We appreciate your visit…

Welcome to the new Power Platform Community!…

We are excited to announce our new Copilot Cookbook Gallery in the Community…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 138,006

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,059

Leaderboard