TruLens
TruLens is an open-source package that provides instrumentation and evaluation tools for large language model (LLM) based applications.
本页面介绍如何使用TruLens评估和跟踪基于langchain构建的LLM应用程序。
安装与设置
安装 trulens-eval Python 包。
pip install trulens-eval
快速入门
在TruLens 文档中查看集成详细信息。
跟踪
创建您的LLM链后,您可以使用TruLens进行评估和跟踪。 TruLens有许多开箱即用的反馈功能, 并且还是一个可扩展的LLM评估框架。
创建反馈函数:
from trulens_eval.feedback import Feedback, Huggingface,
# Initialize HuggingFace-based feedback function collection class:
hugs = Huggingface()
openai = OpenAI()
# Define a language match feedback function using HuggingFace.
lang_match = Feedback(hugs.language_match).on_input_output()
# By default this will check language match on the main app input and main app
# output.
# Question/answer relevance between overall question and answer.
qa_relevance = Feedback(openai.relevance).on_input_output()
# By default this will evaluate feedback on main app input and main app output.
# Toxicity of input
toxicity = Feedback(openai.toxicity).on_input()
链式调用
在为评估您的大型语言模型(LLM)设置反馈函数后,您可以使用 TruChain 包装您的应用程序,以获取对 LLM 应用程序的详细跟踪、日志记录和评估。
注意:有关 chain 创建的代码,请参见
TruLens 文档。
from trulens_eval import TruChain
# wrap your chain with TruChain
truchain = TruChain(
chain,
app_id='Chain1_ChatApplication',
feedbacks=[lang_match, qa_relevance, toxicity]
)
# Note: any `feedbacks` specified here will be evaluated and logged whenever the chain is used.
truchain("que hora es?")
评估
现在你可以探索基于LLM的应用程序了!
这样做将帮助你一眼了解你的LLM应用程序的表现如何。当你迭代新版本的LLM应用程序时,你可以比较它们在所有不同质量指标上的表现。你还可以在记录级别查看评估结果,并探索每条记录的链元数据。
from trulens_eval import Tru
tru = Tru()
tru.run_dashboard() # open a Streamlit app to explore
有关TruLens的更多信息,请访问 trulens.org