Advertisement

How to specify the LangSmith project name for each Chain?

阅读量:

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

问题背景:

As per the LangSmith documentation, it is necessary to configure the LANGCHAIN_PROJECT environment variable to specify the project name within langsmith.

按照LangSmith的官方文档规定, 建议您需设置 LANGCHAIN_PROJECT 环境变量名以明确标识该项目的名称。

But if we want to run multiple subtasks within a single service while they belong to different project scopes, how can we set the chain name at runtime for each subtask?

但是,在一个服务中同时执行多个链的情况下,并且其中每个链都采用了不同的项目名称,请问如何在运行时给每个链分配相应的项目名称?

We believe we have found a solution, but it was necessary for us to delve into the LangChain codebase. We are worried that this isn’t the most idiomatic approach and could potentially lead to problems if their API undergoes modifications.

我们相信我们的解决方案是可行的 但我们必须查阅LangChain的代码以确保一切正常 因此我们对此表示担忧认为它不符合常规 这可能带来问题当他们的API发生变化时

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

  • Create an instance of the chain.
    • Create an instance of a custom LangChain tracer, ensuring that the project name is specifically defined during 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 incorporate this feature into langsmith_extra upon invoking the traced function. It has higher priority than the traceable project.

另外一种方法是在调用被追踪函数时将该功能包含在langsmith_extra中。这种做法会比直接配置可追踪项目设置更为高效。

复制代码
 my_llm_call(

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

全部评论 (0)

还没有任何评论哟~