LangChain
Instrumenting your Langchain applications with Parea AI
Parea AI works seamlessly with LangChain. LangChain provides a callbacks system to hook into the various stages of your LLM application.
With Parea’s PareaAILangchainTracer
you can automatically subscribe to all exposed LangChain events.
Quickstart
Add the PareaAILangchainTracer
as a callback when running your Langchain model/chain/agent:
First initialize Parea
and the PareaAILangchainTracer
. Follow these steps to get an API key.
Then initialize the tracer and add it as a callback to your LangChain application.
Where to set callbacks
There are two ways callbacks can be passed - as constructor callbacks and as request callbacks.
- Constructor callbacks are defined in the constructor of an object and apply to all calls made on that specific object. The scope is limited to the object itself.
- Request callbacks are defined in the run() or apply() methods used for sending a request. They are applied to a specific request and all sub-requests it contains. For example, passing a handler to the chain.run() method will be used for that particular request and any subsequent sub-requests triggered. Additional details here.
Below are some examples of how to set callbacks in different scenarios.
Visualizing your traces
Every time you run a LangChain component with tracing, the call hierarchy for the run is saved and can be visualized in the app on the Logs tab. You can drill down into the components inputs and outputs, parameters, response time, token usage, and other important metadata.
Evaluating a Langchain RAG application
Below is an example of how to use the PareaAILangchainTracer
and Langchain to evaluate a RAG chain. The code can be found in the cookbook here.
Tracing LangChain code together with other code
If you want to observe or test LangChain code and other code together, the trace
decorator plays well with that and will associate any traces, LLM calls, and LangChain logs.
You can see a schematic example below:
The full working example can be found below:
Was this page helpful?