langsmith功能总结
1、平台基础功能
- Tracing(追踪)
- Debugging(调试)
- Testing(测试)
- Evaluation(评价)
- Langchain Hub
(1)Tracing&Debugging功能(最核心模块—服务于LLM应用开发者)
- View Runs&Trees:将每次大模型的运行结果通过树状图的形式呈现(呈现部分:Chain、Tool、Retriever、Prompt、LLM、Parser等)
- Share Run:将运行的结果展示,便于公共开发
- Run Playground(调试功能):在线上平台,在线完成对Prompt与LLM(Model)的调试
- 在线上完成LLM的参数调整如:Input、Prompt、Model等
- 在Langsmith线上界面即可完成实时的运行
- Upsert Dataset:将大语言模型此次的运行的输入与输出存储到Dataset中
演示代码
下面展示一些内联代码片
。
from langchain.llms import OpenAI
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain.chains import SimpleSequentialChain
import os
# langsmith代理
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_PROJECT"] = "填入自己的langchain project"
os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"
os.environ["LANGCHAIN_API_KEY"] = "填入自己的langsmithAPI"
# openai代理
os.environ["OPENAI_API_KEY"] = "选择自己的API"
# 定义第一个chain
llm = OpenAI(temperature=.7)
template = """You are a playwright. Given the title of play, it is your job to write a synopsis for that title.
Title: {title}
Playwright: This is a synopsis for the above play:"""
prompt_template = PromptTemplate(input_variables=["title"], template=template)
synopsis_chain = LLMChain(llm=llm, prompt=prompt_template)
# 定义第二个chain
llm = OpenAI(temperature=.7)
template = """You are a play critic from the New York Times. Given the synopsis of play, it is your job to write a review for that play.
Play Synopsis:
{synopsis}
Review from a New York Times play critic of the above play:"""
prompt_template = PromptTemplate(input_variables=["synopsis"], template=template)
review_chain = LLMChain(llm=llm, prompt=prompt_template)
# 通过简单顺序链组合两个LLMChain
overall_chain = SimpleSequentialChain(chains=[synopsis_chain, review_chain], verbose=True)
# 执行顺序链
review = overall_chain.run("Tragedy at sunset on the beach")
View Runs&Trees
langsmith界面
- Traces–表示此项目追踪的大模型运行
- LLM Calls–表示记录大模型(LLM)调用次数
- Monitor–可视化的展示大模型应用的相关信息如模型运行时间、token调用数等
- Setup–指导如何使用langsmith,并如何将代码插入大模型应用的代码中(上述展示代码已经展示)
如图为运行的LLM的反馈结果,通过选择LLM等相应的节点,并点击playground,可以对节点的参数进行微调(如下图),微调完成后点击Start,从而得到自己目标节点的Output
(2)Testing&Evaluation功能(服务于数据工程师)
现阶段提供数据集类型:
- LLM(Text inputs and outputs)
- Chat(chat model inputs and outputs)
- Key-Value(For chains,agents and tools)
①具体功能
- 管理数据集
- 导入:支持csv格式
- 导出:支持csv、OpenAI JSONL格式
- Feedbacks–汇总和存储数据集(由开发者选择模型的输入、输出是是否符合预期,符合则收录入Feedbacks中)
- 在网页上可视化的选择提供的数据集(见下图:左侧为可选择的数据集,右侧为langsmith生成的大模型实例)