How to return citations with Azure OpenAI API responses

Anthony Pham 55 Reputation points
2023-09-25T03:31:55.54+00:00

I have developed a chatbot in Power Apps connected to my enterprise data. I setup RAG design pattern to send the prompt via REST API to Azure Cognitive service which indexed my enterprise data. Then the top search results is sent to Azure OpenAI service via REST API.

My goal is to include the citations of the answers in response similar to the Azure OpenAI web app. However, I haven't found any documentation to do this.

I tried appending the following user instructions for every prompt. However the responses are not returning citations consistently.

{
  "role": "user",
  "content": "Your response will have a citation section at the end of your answer. It will include a citation number starting at 1 enclosed by brackets and increments for each citation. all URL links in your citation response should be hyperlinks in the format : <a href\"URL\">policy document title</a>.  Add <br><br> whenever there is a line break in your answer."
}

Please advise on the best approach.

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

2 answers

Sort by: Most helpful
  1. Saurabh Sharma 23,851 Reputation points Microsoft Employee Moderator
    2023-10-11T19:04:00.68+00:00

    @Anthony Pham

    I have checked internally and citations should be available under the role: "tool" part of the response. Here is the example of the different parts of the API response. Please refer to the documentation

    Please let me know if you have any questions.

    Thanks

    Saurabh


    Please 'Accept as answer' and Upvote if it helped so that it can help others in the community looking for help on similar topics.


  2. Edward Moemeka 0 Reputation points MVP
    2024-02-22T11:04:24.01+00:00

    HI,
    the information you are looking for is in the AzureExtensionsContext property for the message. The Messages property of the returned object is a list of ChatResponseMessage objects (which have the citation listed in a json object). Happy coding, hope this helped!

    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.