HomeGuidesRecipesAPI EndpointsRelease NotesCommunity
Log In
Guides

Asking Questions of a Single Document

This section will go over how to ask questions using layar endpoints. There are a variety of endpoints at /layar/question that will allow us to create a question and then run that question on a document.

Pre-Reqs

Make sure you have already followed the instructions for importing dependencies and authentication from the Getting Started Guide. You can use your token variable to authenticate your requests.

👍

Check Your Imported Modules

Make sure you have imported the requests and json module before proceeding with this guide.

Identify Your Document

In this use case, we aren't attempting to locate an answer wherever it may exist in the fabric. Instead, we are looking to interrogate a specific document. This document may be one that has been found/created previously, or a document that matches specific search criteria. For this example, we will be using the documentId variable that was created in Upload Documents into Layar.

Build the Request Body

In order to create the question, we will need to make body variable and fill out with the relevant question details. For this we will be using queryString to define the question and search. For search you will notice it's a dictionary that includes multiple other values, which allow us to define that the question will be ran on a specific document ID.

👍

Pro Tip

You can use Swagger to double check all the possible values you can use at https://YOUR_LAYAR_ENVIRONMENT/layar/swagger-ui.html

body = {
       'queryString' : 'What is the disease or indication being studied?',
       'search' : {
                  'sourceDocumentSearchCommand' : {
                                                  'ids' : [f'{documentId}']
                                                  }
                  }
       }

Create your Question

Now that we have the body filled out, we can do a requests.post in order to create the question. We will also be using json.get in order to pull out the ID of the question we just created and load it into the variable questionId.

createQuestionUri = f'{envurl}/layar/question'

response = requests.post(createQuestionUri, 
                         headers = header, 
                         json = body
                        )

questionId = response.json().get('id')
print(questionId) #optional

Ask your Question

Now that you have your questionId you can use request.post and the /layar/question/{questionId}/answers/more endpoint to get answers to the question. We do not need a body for this request.

askQuestionUri = f'{envurl}/layar/question/{questionId}/answers/more'

response = requests.post(askQuestionUri, 
                         headers = header 
                        )
print(response)

The response we get here will not be the answer, you will just get a 200, which signifies the question has been asked.

Getting Answers

In order to get your answers, you will need use requests.get utilizing the questionId in the body.

body = {
       'questionIds' : [f'{questionId}']
       }

Our endpoint to grab the answers will be /layar/answer

findAnswerUri = f'{envurl}/layar/answer'

response = requests.get(findAnswerUri, 
                         headers = header,
                         json = body
                        )
print(response.text)

The print command will give us JSON data with various answers to the question asked.


Up Next

Now that we know how to submit a question against a single document in Layar, lets submit a bulk QA job against a set of documents.