欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > How to specify the LangSmith project name for each Chain?

How to specify the LangSmith project name for each Chain?

2025/2/5 19:57:43 来源:https://blog.csdn.net/suiusoar/article/details/140862631  浏览:    关键词: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"},
)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com