跳到主要内容
有时,在不将任何结果上传到 LangSmith 的情况下在本地运行评估会很有帮助。例如,如果您正在快速迭代提示并想在几个示例上进行冒烟测试,或者如果您正在验证您的目标和评估器函数是否定义正确,您可能不想记录这些评估。 您可以通过使用 LangSmith Python SDK 并将 upload_results=False 传递给 evaluate() / aevaluate() 来实现这一点。 这将像往常一样运行您的应用程序和评估器,并返回相同的输出,但不会将任何内容记录到 LangSmith。这不仅包括实验结果,还包括应用程序和评估器跟踪。

示例

让我们看一个例子: 需要 langsmith>=0.2.0。此示例还使用 pandas
from langsmith import Client

# 1. Create and/or select your dataset
ls_client = Client()
dataset = ls_client.clone_public_dataset(
    "https://smith.langchain.com/public/a63525f9-bdf2-4512-83e3-077dc9417f96/d"
)

# 2. Define an evaluator
def is_concise(outputs: dict, reference_outputs: dict) -> bool:
    return len(outputs["answer"]) < (3 * len(reference_outputs["answer"]))

# 3. Define the interface to your app
def chatbot(inputs: dict) -> dict:
    return {"answer": inputs["question"] + " is a good question. I don't know the answer."}

# 4. Run an evaluation
experiment = ls_client.evaluate(
    chatbot,
    data=dataset,
    evaluators=[is_concise],
    experiment_prefix="my-first-experiment",
    # 'upload_results' is the relevant arg.
    upload_results=False
)

# 5. Analyze results locally
results = list(experiment)

# Check if 'is_concise' returned False.
failed = [r for r in results if not r["evaluation_results"]["results"][0].score]

# Explore the failed inputs and outputs.
for r in failed:
    print(r["example"].inputs)
    print(r["run"].outputs)

# Explore the results as a Pandas DataFrame.
# Must have 'pandas' installed.
df = experiment.to_pandas()
df[["inputs.question", "outputs.answer", "reference.answer", "feedback.is_concise"]]
{'question': 'What is the largest mammal?'}
{'answer': "What is the largest mammal? is a good question. I don't know the answer."}
{'question': 'What do mammals and birds have in common?'}
{'answer': "What do mammals and birds have in common? is a good question. I don't know the answer."}
inputs.questionoutputs.answerreference.answerfeedback.is_concise
0最大的哺乳动物是什么?最大的哺乳动物是什么?这是一个好问题。我不知道答案。蓝鲸False
1哺乳动物和鸟类有什么共同点?哺乳动物和鸟类有什么共同点?这是一个好问题。我不知道答案。它们都是温血动物False

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.