MlflowLogger#

class langchain_community.callbacks.mlflow_callback.MlflowLogger(**kwargs: Any)[source]#

Callback Handler that logs metrics and artifacts to mlflow server.

Parameters:
  • name (str) – Name of the run.

  • experiment (str) – Name of the experiment.

  • tags (dict) – Tags to be attached for the run.

  • tracking_uri (str) – MLflow tracking server uri.

  • kwargs (Any)

This handler implements the helper functions to initialize, log metrics and artifacts to the mlflow server.

Methods

__init__(**kwargs)

artifact(path)

To upload the file from given path as artifact.

finish_run()

To finish the run.

html(html, filename)

To log the input html string as html file artifact.

jsonf(data, filename)

To log the input data as json file artifact.

langchain_artifact(chain)

metric(key, value)

To log metric to mlflow server.

metrics(data[, step])

To log all metrics in the input dict.

start_run(name, tags[, run_id])

If run_id is provided, it will reuse the run with the given run_id.

table(name, dataframe)

To log the input pandas dataframe as a html table

text(text, filename)

To log the input text as text file artifact.

__init__(**kwargs: Any)[source]#
Parameters:

kwargs (Any)

artifact(path: str) None[source]#

To upload the file from given path as artifact.

Parameters:

path (str)

Return type:

None

finish_run() None[source]#

To finish the run.

Return type:

None

html(html: str, filename: str) None[source]#

To log the input html string as html file artifact.

Parameters:
  • html (str)

  • filename (str)

Return type:

None

jsonf(data: Dict[str, Any], filename: str) None[source]#

To log the input data as json file artifact.

Parameters:
  • data (Dict[str, Any])

  • filename (str)

Return type:

None

langchain_artifact(chain: Any) None[source]#
Parameters:

chain (Any)

Return type:

None

metric(key: str, value: float) None[source]#

To log metric to mlflow server.

Parameters:
  • key (str)

  • value (float)

Return type:

None

metrics(data: Dict[str, float] | Dict[str, int], step: int | None = 0) None[source]#

To log all metrics in the input dict.

Parameters:
  • data (Dict[str, float] | Dict[str, int])

  • step (int | None)

Return type:

None

start_run(name: str, tags: Dict[str, str], run_id: str | None = None) None[source]#

If run_id is provided, it will reuse the run with the given run_id. Otherwise, it starts a new run, auto generates the random suffix for name.

Parameters:
  • name (str)

  • tags (Dict[str, str])

  • run_id (str | None)

Return type:

None

table(name: str, dataframe: Any) None[source]#

To log the input pandas dataframe as a html table

Parameters:
  • name (str)

  • dataframe (Any)

Return type:

None

text(text: str, filename: str) None[source]#

To log the input text as text file artifact.

Parameters:
  • text (str)

  • filename (str)

Return type:

None