Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/hotfixes' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
fit-alessandro-berti committed Apr 1, 2024
2 parents a8cfff1 + 91c2090 commit 4f18516
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pm4py/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,34 @@ def abstract_log_skeleton(log_skeleton, include_header: bool = True) -> str:

from pm4py.algo.querying.llm.abstractions import logske_to_descr
return logske_to_descr.apply(log_skeleton, parameters=parameters)


def explain_visualization(vis_saver, *args, connector=openai_query, **kwargs) -> str:
"""
Explains a process mining visualization by using LLMs (saving that first in a .png image, then providing the .png file to the
Large Language Model along with possibly a description of the visualization).
:param vis_saver: the visualizer (saving to disk) to be used
:param args: the mandatory arguments that should be provided to the visualization
:param connector: the connector method to the large language model
:param kwargs: optional parameters of the visualization or the connector (for example, the annotation of the visualization, or the API key)
:rtype: ``str``
.. code-block:: python3
import pm4py
log = pm4py.read_xes("tests/input_data/running-example.xes")
descr = pm4py.llm.explain_visualization(pm4py.save_vis_dotted_chart, log, api_key="sk-5HN", show_legend=False)
print(descr)
"""
F = NamedTemporaryFile(suffix=".png")
image_path = F.name
F.close()

description = vis_saver(*args, image_path, **kwargs)

parameters = copy(kwargs) if kwargs is not None else {}
parameters["image_path"] = image_path

return connector("Could you explain the included process mining visualization?\n\n" + description, **parameters)

0 comments on commit 4f18516

Please sign in to comment.