how to download/access the azure openai rag return file?

AMROUN Lysa 396 Reputation points
2024-04-25T17:49:52.92+00:00

good morning,

I'm currently using azure openai in python to use the chat for question and answer on my documents. I'd like to know if there was a way to download the file where the char found the answer (still in python).

thanks

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,350 questions
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,092 questions
{count} votes

Accepted answer
  1. Grmacjon-MSFT 19,301 Reputation points Moderator
    2024-04-25T23:18:04.3166667+00:00

    Hi @AMROUN Lysa thanks for the question.

    Azure OpenAI Service does not currently provide a built-in way to download or access the source file from which the Retrieval-Augmented Generation (RAG) model retrieved the answer. However, you can customize the RAG model to include the source file information in the output, which you can then use to retrieve the file if needed.

    Here's how you can approach this:

    • When you initialize the RAG model using openai.Deployment.retrieve_and_read, you can specify a custom output format using the response_format parameter. This parameter accepts a Python formatting string that can include placeholders for different components of the model's output.

    For example, you can include the placeholder {context} to get the context (source text) that the model used to generate the answer. You can then parse this context to extract the file information.

    
    from openai.retrievers import retrieve, RetrieverRegistry
    
    retriever = RetrieverRegistry.get("azureml.openai")
    
    deployment = openai.Deployment.retrieve_and_read(retriever=retriever, response_format="{result}\n\nContext: {context}")
    
    
    • After getting the model's output, you can parse the {context} part to extract the file information. The exact parsing logic will depend on how you structured your source files and the metadata you included.

    For example, if your source files have a consistent naming convention or include file paths in the metadata, you can use string manipulation or regular expressions to extract the file information from the context.

    • Once you have the file information (e.g., file path, name, or URL), you can use the appropriate Python libraries or Azure SDK to access or download the file.

    If the files are stored in Azure Blob Storage or Azure File Share, you can use the azure-storage-blob or azure-storage-file Python libraries to download the files.

    If the files are stored in a local file system or network share, you can use the built-in os and shutil Python modules to access or copy the files.

    It's important to note that this approach requires you to modify the RAG model's output format and implement custom parsing logic to extract the file information. Additionally, you'll need to ensure that your source files or their metadata include the necessary information to identify and locate the files. Best,

    Grace

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.