Base Class

/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/fastcore/docscrape.py:230: UserWarning: Unknown section Parameters:
  else: warn(msg)

source

Prompt

 Prompt (instruction:str, examples:Optional[List[Tuple[Dict,Dict]]]=None)

Create a simple prompt object.

Example Usage

# Create a basic prompt
prompt = Prompt(
    instruction="Evaluate if given answer {response} is same as expected answer {expected_answer}"
)

# Add examples with dict inputs and dict outputs
prompt.add_example(
    {
        "response": "You can get a full refund if you miss your flight.",
        "expected_answer": "Refunds depend on ticket type; only refundable tickets qualify for full refunds."
    },
    {"score": "fail"}
)

prompt.add_example(
    {
        "response": "Each passenger gets 1 free checked bag up to 23kg.",
        "expected_answer": "Each passenger gets 1 free checked bag up to 23kg."
    },
    {"score": "pass"}
)

print(prompt.format(response="You can get a full refund if you miss your flight.", expected_answer="Refunds depend on ticket type; only refundable tickets qualify for full refunds."))
Evaluate if given answer You can get a full refund if you miss your flight. is same as expected answer Refunds depend on ticket type; only refundable tickets qualify for full refunds.

Examples:

Example 1:
Input:
response: You can get a full refund if you miss your flight.
expected_answer: Refunds depend on ticket type; only refundable tickets qualify for full refunds.
Output:
score: fail

Example 2:
Input:
response: Each passenger gets 1 free checked bag up to 23kg.
expected_answer: Each passenger gets 1 free checked bag up to 23kg.
Output:
score: pass
print(str(prompt))
Prompt(instruction='Evaluate if given answer {response} is same as expected answer {expected_answer}',
 examples=Examples:

Example 1:
Input:
response: You can get a full refund if you miss your flight.
expected_answer: Refunds depend on ticket type; only refundable tickets qualify for full refunds.
Output:
score: fail

Example 2:
Input:
response: Each passenger gets 1 free checked bag up to 23kg.
expected_answer: Each passenger gets 1 free checked bag up to 23kg.
Output:
score: pass)