Primer
  • Factored Cognition Primer
  • Intro
    • Factored Cognition
    • Before We Start
  • Chapters
    • Hello World
    • Question Answering
      • Q&A without context
      • Q&A about short texts
    • Debate
      • Representing debates
      • From debates to prompts
      • The debate recipe
    • Long Texts
      • Loading paper text
      • Finding relevant paragraphs
      • Answering given paragraphs
    • Amplification
      • Asking subquestions
      • Answering subquestions
      • One-step amplification
      • Recursive amplification
    • Verifiers
      • Checking answers
      • Checking reasoning steps
    • Tool Use
      • Web search
      • Interpreters
    • Deduction
      • Chain of Thought
    • Action Selection
      • One-shot action selection
      • Iterative action selection
    • Amplification Revisited
  • Appendix
    • What’s next?
  • Links
    • We’re Hiring
    • Our Slack Community
    • ICE on Github
Powered by GitBook
On this page
Edit on GitHub
  1. Chapters
  2. Question Answering

Q&A without context

Answering questions without extra information

Let’s make our first recipe that calls out to an agent:

qa_simple.py
from fvalues import F

from ice.recipe import recipe


def make_qa_prompt(question: str) -> str:
    return F(
        f"""Answer the following question:

Question: "{question}"
Answer: "
"""
    ).strip()


async def answer(question: str = "What is happening on 9/9/2022?"):
    prompt = make_qa_prompt(question)
    answer = await recipe.agent().complete(prompt=prompt, stop='"')
    return answer


recipe.main(answer)

Now let's try running this recipe:

python qa_simple.py

Looking at the trace, we see two nodes—one for the answer function we implemented, and one for the agent method call. If we click on the agent method, we see the exact prompt that was passed to the agent:

We can run recipes in different modes, which controls what type of agent is used. Some examples:

  • machine: Use an automated agent (usually GPT-3 if no hint is provided in the agent call). This is the default mode.

  • human: Elicit answers from you using a command-line interface.

  • augmented: Elicit answers from you, but providing the machine-generated answer as a default.

You specify the mode like this:

python qa_simple.py --mode human

Try running your recipe in different modes.

Because the agent’s answer method is async, we use await when we call it.

PreviousQuestion AnsweringNextQ&A about short texts

Last updated 2 years ago

Wrapping f-strings in fvalues.F is entirely optional, but .

it makes traces a little bit nicer to work with
Execution trace ()
view online