Skip to main content

Uploading Question and Answers

This format is used to populate the knowledge management system with question-answer pairs. It's an efficient way to enhance the system's knowledge base.

{
"type": "questionAnswer",
"data": [
{
"question": "What is a planet?",
"answer": "A planet is a large, rounded astronomical body that is neither a star nor its remnant. The best available theory of planet formation is the nebular hypothesis, which posits that an interstellar cloud collapses out of a nebula to create a young protostar orbited by a protoplanetary disk. Planets grow in this disk by the gradual accumulation of material driven by gravity, a process called accretion. The Solar System has at least eight planets: the terrestrial planets Mercury, Venus, Earth, and Mars, and the giant planets Jupiter, Saturn, Uranus, and Neptune.",
"link": "https://en.wikipedia.org/wiki/Planet"
},
{
"question": "What is the sixth planet from the Sun?",
"answer": "Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter. It is a gas giant with an average radius of about nine-and-a-half times that of Earth. It has only one-eighth the average density of Earth, but is over 95 times more massive.",
"link": "https://en.wikipedia.org/wiki/Saturn"
}
]
}

Helper Python code to convert a CSV file into JSON

If you create an Excel or CSV file for question, answer, link

Excel document showing question and answers that can be uploaded to the knowledge base

In Excel save as a CSV file and then run this Python utility to convert to JSON

import csv
import json

# Path to the CSV file
csv_file_path = "notebook/questions.csv"

# Reading the CSV file and converting it to JSON format
json_data = {"type": "questionAnswer", "data": []}

with open(csv_file_path, mode='r', encoding='utf-8-sig') as file: # Note the encoding change here
csv_reader = csv.DictReader(file)
for row in csv_reader:
question = row["question"]
answer = row["answer"]
# Handling the optional presence of 'link' field
link = row.get("link", "") # Defaults to an empty string if 'link' is not present
json_data["data"].append({"question": question, "answer": answer, "link": link})

# Saving the JSON data to a file
json_file_path = "notebook/questions.json"
with open(json_file_path, 'w', encoding='utf-8') as jsonfile:
json.dump(json_data, jsonfile, ensure_ascii=False, indent=2)

print("JSON file saved at: ", json_file_path)