According the LangSmith documentation you need to set the LANGCHAIN_PROJECT
environment variable to specify the project name in 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.
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.
- 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.