How to use azure open ai to complete contextual chat

欲沉 0 Reputation points
2023-12-10T14:38:46.3566667+00:00

Hi, I'm building a chat service using Azure's Openai service, and I'm not sure how to make the interface capable of contextual conversations. Do I have to bring in the previous conversation every time I request it? Is this too token consuming.

I see that each response has an id, whether I can use this to complete the context conversation?

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,082 questions
{count} votes

2 answers

Sort by: Most helpful
  1. AshokPeddakotla-MSFT 35,971 Reputation points Moderator
    2023-12-11T09:03:47.31+00:00

    欲沉 Greetings!

    Hi, I'm building a chat service using Azure's Openai service, and I'm not sure how to make the interface capable of contextual conversations. Do I have to bring in the previous conversation every time I request it? Is this too token consuming.

    It's great to hear that you're building a chat service using Azure's OpenAI service.

    To answer your question, Azure OpenAI doesn't remember the context of your conversation, so you'll need to bring in the previous conversation every time you request it. Please see Creating a basic conversation loop for more details.

    I see that each response has an id, whether I can use this to complete the context conversation?

    The response ID is simply a unique identifier for each response that Azure OpenAI generates. It can be useful for tracking and logging purposes, but it doesn't provide any contextual information about the conversation. It's not intended to be used to complete the context conversation.

    If you want to maintain context between conversations, you can store the conversation history in a database or other storage solution. This way, you can retrieve the previous conversation when needed and provide it to Azure OpenAI as part of the input. I would suggest you, check Cosmos DB + ChatGPT sample application for more details.

    I hope this helps! Let me know if you have any other questions.


    If the response helped, please do click Accept Answer and Yes for was this answer helpful.

    Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.


  2. umeshkumar sohaliya 80 Reputation points
    2024-04-22T15:45:23.9466667+00:00

    To maintain context in Azure AI search, we need to include the previous question along with the new query. This allows the system to understand the user's intent and provide accurate results.

    Lets assume we have below scenario, where we need to maintain context to get correct answer.

    User: How many legs do monkeys have?

    AI: Monkeys typically have four legs.

    User: What about their hands?

    In order to preserve context, we must include previous questions when submitting new queries. Below is C# example to pass previous question along with new question

    chatCompletionsOptions = new ChatCompletionsOptions()
    {
        Messages =
        {
             new ChatRequestUserMessage("How many legs do monkeys have?"),         
    		 new ChatRequestUserMessage("What about their hands?")    
    	 },
    //.......
    }
    
    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.