langfuse
Langfuse integration module
This module contains the Langfuse integration for the Eleanor Framework and includes callback that includes key generation metrics (logprobs and perplexity). Additionally, tis module includes utilities that weill emit the trace URL to the logs making it easier for developers to troubleshoot generation problems.
Warning
Due to the customizations implemented here it is not recommended to use tracing tool integration provided by the LiteLLM proxy.
Danger
As of langchain-openai==0.1.23
, the LangChain OpenAI client does not support
n
generation callbacks properly and a monkeypatch is needed. See:
https://github.com/langchain-ai/langchain/issues/19185
Attributes
Classes
EleanorLangfuseCallback
Bases: CallbackHandler
Custom LangFuse callback handler for Eleanor Framework.
Functions
on_llm_end
on_llm_end(
response: LLMResult,
*,
run_id: UUID,
parent_run_id: Optional[UUID] = None,
**kwargs: Any
) -> Any
Handle the ‘on_llm_end’ event.
Update the LangFuse trace with Eleanor Framework specific information.
Parameters:
-
response
(LLMResult
) –The response object containing the LLM result.
-
run_id
(UUID
) –The ID of the current run.
-
parent_run_id
(Optional[UUID]
, default:None
) –The ID of the parent run. Defaults to None.
-
**kwargs
(Any
, default:{}
) –Additional keyword arguments.
Returns:
-
Any
(Any
) –The result of the event handling.
GenerationMetrics
Bases: BaseModel
Attributes
NMetrics
Bases: BaseModel
Attributes
logprobs
class-attribute
instance-attribute
ResponseMetrics
Bases: BaseModel
Attributes
generations
class-attribute
instance-attribute
generations: List[GenerationMetrics] = Field(
default_factory=list
)
Functions
append_trace_tag
Add a new trace tag to the list of tags, if it doesn’t already exist.
Note
This method copies the list of tags before appending the new tag to it and is non-destructive.
Parameters:
-
new_tag
(str
) –The new tag to add.
-
tags
(List[str] | None
) –The list of tags to append to.
Returns:
-
List[str]
–List[str]: The updated list of tags.
build_langfuse_trace_url
Build the URL for retrieving a Langfuse trace based on the given trace ID.
Parameters:
-
trace_id
(str
) –The ID of the trace.
Returns:
-
str
(str | None
) –The complete URL for retrieving the Langfuse trace.
new_trace_id
Generates a new trace ID.
Returns:
-
str
(str
) –The generated trace ID.