I previously shared how to maintain past context when interacting with an OpenAI GPT model, by setting and updating a global variable using Bot Framework Composer, here: Set and update global variables using Bot Framework Composer and how to retain conversation context when interacting with OpenAI GPT models.
Today I'd like to show how to do the same, but this time using Azure OpenAI ChatGPT model that just came out.
I find that model much better suited for conversation experiences and automatically formats code samples:
Couple of useful resources on this topic:
@mboninco I have created an FAQ bot. But my bot is facing a hard time in maintaining context. I am saving the entities provided by user in his response and thus I can use them. I was wondering is there a way to access/save bot's response in any variable.
To provide full context of a session to bot, the only solution I can think of is to append these to and fro messages in a string variable. But I am clueless how can I set/append this new variable with the texts being exchanged between the bot and the user.
@HenryJammes How can this be done in MS copilot studio . I want my bot to maintain the context of the conversation, however currently it is not.
FYI I've created a new version of this article using the Chat Completion API format, in both the classic and new version of Power Virtual Agents:
Integrate a PVA chatbot with Azure OpenAI ChatGPT using the Chat Completion API format
now It's worked good in our prod env.
our PVA in teams version bot face to about 1000+ users
I already use the same way to use azure openai gpt-4. thank you!
Thank you ! Hope you got Azure OpenAI GPT-4 soon...
Hi @angerfire1213 the example above was created on the GPT 3.5 Turbo model with Chat Markup Language and works.
I haven't tried the Chat Completion format yet, and GPT-4 might require that format, so the above approach would indeed need reworking to meet the new JSON format requirements, but the approach should be the same.
I'll try to update or create a new article once I get access to GPT-4.
How to do that for GPT-35-Turbo (preview) & GPT-4 (preview) ?
In GPT-35-Turbo (preview) & GPT-4 (preview) use messages not prompt
messages=[ {"role": "system", "content": "Assistant is a large language model trained by OpenAI."}, {"role": "user", "content": "What's the difference between garbanzo beans and chickpeas?"}, ]
learn more about GPT-35-Turbo (preview) & GPT-4 (preview):
https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/chatgpt?pivots=programming-language-chat-completions#working-with-the-chatgpt-and-gpt-4-models-preview
This is awesome, @HenryJammes !
I just went through a very similar exercise, but am using Unified Canvas instead, so I thought I'd share the code view of my Fallback topic, since it's a breeze copy/pasting a topic in the Unified Canvas! 😀
A few notes to get it set up:
kind: AdaptiveDialog
beginDialog:
kind: OnUnknownIntent
id: main
actions:
- kind: SetVariable
id: setVariable_Kyy1Yh
variable: Topic.UserQuery
value: =System.Activity.Text
- kind: ConditionGroup
id: conditionGroup_Nuj40I
conditions:
- id: conditionItem_iRCr9Y
condition: =IsBlank(Global.FullConversation)
actions:
- kind: SetVariable
id: 36cfgS
variable: Global.FullConversation
value: <|im_start|>system\nI am a virtual assistant that can answer questions\n<|im_end|>\n<|im_start|>user\n
- kind: InvokeFlowAction
id: invokeFlowAction_Ho6dKr
input:
binding:
text: =Topic.UserQuery
text_1: =Global.FullConversation
output:
binding:
response: Topic.Response
flowId: 00000000-0000-0000-0000-000000000000
- kind: SendMessage
id: sendMessage_UgHog9
message: "{Topic.Response}"
- kind: SetVariable
id: setVariable_0LLSEn
variable: Global.FullConversation
value: =Concatenate(Global.FullConversation,Topic.UserQuery,"\n<|im_end|>\n<|im_start|>assistant", Topic.Response, "\n<|im_end|>\n<|im_start|>user\n")