Integration Azure Openai Langchain
description: This cookbook demonstate use of Langfuse with Azure OpenAI and Langchain for prompt versioning and evaluations. category: Integrations
Langfuse Tracing and Prompt Management for Azure OpenAI and Langchain
This cookbook demonstate use of Langfuse with Azure OpenAI and Langchain for prompt versioning and evaluations.
Setup
Note: This guide uses our Python SDK v2. We have a new, improved SDK available based on OpenTelemetry. Please check out the SDK v3 for a more powerful and simpler to use SDK.
We'll use the native Langfuse integration for Langchain. Learn more it in the documentation.
Langchain imports
Simple example
✨ Done. Go to the Langfuse Dashboard to explore the trace of this run.
Example using Langfuse Prompt Management and Langchain
Learn more about Langfuse Prompt Management in the docs.
In your production environment, you can then fetch the production version of the prompt. The Langfuse client caches the prompt to improve performance. You can configure this behavior via a custom TTL or disable it completely.
We do not use the native Langfuse prompt.compile() but use the raw prompt.prompt as Langchain will insert the prompt variables (if any).
Multiple Langchain runs in same Langfuse trace
Langchain setup
Run the chain multiple times within the same Langfuse trace.
Adding scores
When evaluating traces of your LLM application in Langfuse, you need to add scores to the trace. For simplicity, we'll add a mocked score. Check out the docs for more information on complex score types.
Get the trace_id. We use the previous run where we created the trace using langfuse.trace(). You can also get the trace_id via langfuse_handler.get_trace_id().