跳至主要内容

Trivet - 教程

假设我们想测试一个简单的图形,该图形执行对GPT-3.5的调用,但需要命名助手:

Simple GPT-3.5 graph

让我们创建一个包装器测试图,这样我们就不需要在每个测试用例中都传递助手的名称:

Simple GPT-3.5 wrapper graph

接下来,让我们创建一个验证器图表。它必须包含inputoutputexpectedOutput Graph Input节点,且这些节点都必须是Object类型。在本例中,我们将使用全部3个输入节点。

我们从expectedOutput中提取验证问题,从output中获取实际输出,并从input中提取问题。然后我们询问GPT验证是否通过。本示例使用以下提示:

An AI was asked the following question:

"""
{{question}}
"""

The AI responded with:

"""
{{response}}
"""

Your goal is to perform this validation on the AI's response:

"""
{{validation}}
"""

Reply YES if the validation passes. Reply NO if the validation does not pass, and explain why.

使用以下系统提示:

You are a validator for AI responses.

You reply YES and nothing else when validation pass.

You reply NO and explain why when validations do not pass.

完整的验证图如下所示:

Simple GPT-3.5 validation graph

接下来,让我们为这个图表创建一个测试套件。打开Trivet Tests选项卡,并使用以下配置创建一个新的测试套件:

Trivet test suite configuration

添加一个具有以下配置的新测试用例:

Trivet test case configuration

请注意,对于输入部分,您是在要求GPT对此输出执行验证,而不是直接验证输出。这是一种有用的模式,因为您可以检查比通过编程方式更多的内容,例如语气和语法字符串!

接下来,点击Run Test Suite按钮。您应该会在测试用例编辑器中看到类似以下的输出:

Trivet test case output

恭喜!您刚刚运行了第一个Rivet测试套件!您可以为此套件添加更多测试,或为其他图表创建更多测试套件。