How to specify the LangSmith project name for each Chain?

题意:如何为每个链指定LangSmith项目名称?

问题背景:

According to the LangSmith documentation you need to set the LANGCHAIN_PROJECT environment variable to specify the project name in langsmith.

根据LangSmith的文档,您需要设置LANGCHAIN_PROJECT环境变量来指定LangSmith中的项目名称。

However, if we want to execute multiple chains within a single service but under different project names, how do we specify the project name at runtime per-chain?

然而,如果我们想在一个服务内执行多个链,但每个链使用不同的项目名称,我们如何在运行时为每个链指定项目名称?

We think we have a solution, but it required looking into the LangChain code, so we are concerned this is not the idomatic way to do it and it might cause issues when their API changes.

我们认为我们有一个解决方案,但需要查看LangChain的代码,因此我们担心这不是一种标准做法,并且当他们的API发生变化时可能会引发问题。

This is what we think we should do.        这是我们应该做的

  • Instantiate the chain.        实例化链。
  • Instantiate a custom langchain tracer but with a specific project name defined at runtime.

实例化一个自定义的langchain追踪器,但在运行时定义一个特定的项目名称。

  • Replace the chain's callbacks with the tracer.

用追踪器替换链的回调函数。

  chain = LLMChain(llm=self._chat_model, prompt=prompt, verbose=True)
        tracer = LangChainTracer(project_name="whatever")
        chain.callbacks = CallbackManager(handlers=[tracer])

Thank you in advance for any help.        提前感谢您的任何帮助。

问题解决:

You can specify project name in the @traceable decorator as an argument.

您可以在@traceable装饰器中作为参数来指定项目名称。

@traceable(
    run_type="llm",
    project_name="My Project"
)
def my_llm_call(
    ...
) -> str:

You can also put it as a part of langsmith_extra when calling the traced function. This takes precedence over the traceable project:

您还可以在调用被追踪的函数时,将其作为langsmith_extra的一部分。这会优先于可追踪的项目设置:

my_llm_call(
   ...,
   langsmith_extra={"project_name": "My Project 2"},
)

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

营赢盈英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值