Skip to content

QuestionAnswer

Overview

The QuestionAnswer is a pipeline consisting of two singletons. It is designed to generate responses to questions based on provided context while adopting a specific persona. It processes inputs through a workflow that generates contextually relevant answers using AI models.

Inputs

Field Type Description
context str Context for answering the question
num_questions int Number of questions to be generated
persona str Persona to adopt while answering

Outputs

Field Type Description
question str The original question (echoed from input)
answer str Generated answer
model str The AI model used for generation

Usage

Answer instance can be used in data generation as follows:

from dria import DriaDataset, DatasetGenerator, Model
from dria.factory.question_answer import QA
import asyncio

my_dataset = DriaDataset(
    name="QA",
    description="A dataset for pages",
    schema=QA[-1].OutputSchema,
)

generator = DatasetGenerator(dataset=my_dataset)


instructions = [
    {
        "context": "Structured Outputs is a feature that ensures the model will always generate responses that adhere to your supplied JSON Schema, so you don't need to worry about the model omitting a required key, or hallucinating an invalid enum value.",
        "persona": "A highschool student.",
        "num_questions": 3,
    },
]

asyncio.run(
    generator.generate(
        instructions=instructions,
        singletons=QA,
        models=Model.GPT4O,
    )
)

Expected output

[
  {
    "question": "How does the feature of Structured Outputs prevent the model from omitting a required key or creating an invalid enum value?",
    "answer": "Okay, so like, think of Structured Outputs as having a kind of \"template\" or \"guideline\" for how the responses should look, right? It\u2019s like when a teacher gives you a worksheet, and you need to fill in certain blanks and you can't just write random things. The JSON Schema is sort of like that worksheet. It tells the model exactly what pieces of info need to be there (like all the answers you need to fill in), so it doesn\u2019t skip anything important. And, it stops the model from just making up weird answers (or invalid enum values, to be fancy) because it has to pick from what\u2019s allowed. It's kinda like having a multiple-choice test where you can only pick A, B, or C, not like, Z or something. So, it keeps everything on track and makes sure nothing's missing or made up!",
    "model": "gpt-4o"
  },
  {
    "question": "What role does a JSON Schema play in ensuring that Structured Outputs maintain response accuracy?",
    "answer": "So, have you ever had to stick to a certain format when writing an essay or something? JSON Schema in this situation is kinda like that format guide but for a computer program. It makes sure all its answers include what they should and nothing they shouldn't have. It's super important for keeping things organized and correct, ensuring that Structured Outputs are always spot-on and don't leave out anything important or add anything that's not supposed to be there.",
    "model": "gpt-4o"
  },
  {
    "question": "In what ways does the feature of Structured Outputs contribute to the reliability of model-generated responses?",
    "answer": "Okay, so the way Structured Outputs make model-generated responses more reliable is kind of like having a rulebook for how answers should be written. So, imagine if every time you wrote an answer in class, you had to make sure it fits into a particular format that your teacher gave you. This way, you won't forget to include important stuff, like your name, date, and the actual answer, and you also won't add in random things that your teacher doesn\u2019t want. It makes the answers neater and more trustworthy. That's what Structured Outputs do; they make sure the model doesn't mess up or go off track by sticking to a guide!",
    "model": "gpt-4o"
  }
]