Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.
feature/feature-flag-reporting-manager (#62) (#63)
Thomas Hebrardafacc525daab
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9e1328d89..31fbf8f12 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,5 +1,14 @@# Changelog+## [v0.2.14] - 2025-06-06++- Added a feature flag for the `ReportingManager` in the config:+```bash+[pipelex]+[pipelex.feature_config]+is_reporting_enabled = true+```+## [v0.2.13] - 2025-06-06- Added Discord badge on the Readme. Join the community! -> https://discord.gg/SReshKQjWtdiff --git a/pipelex/cogt/config_cogt.py b/pipelex/cogt/config_cogt.pyindex 11e475638..8fb24e62a 100644--- a/pipelex/cogt/config_cogt.py+++ b/pipelex/cogt/config_cogt.py@@ -9,15 +9,6 @@ from pipelex.cogt.llm.llm_models.llm_platform import LLMPlatformfrom pipelex.tools.config.models import ConfigModel-class CogtReportConfig(ConfigModel):- is_log_costs_to_console: bool- is_generate_cost_report_file_enabled: bool- cost_report_dir_path: str- cost_report_base_name: str- cost_report_extension: str- cost_report_unit_scale: float--class OcrConfig(ConfigModel):ocr_handles: List[str]page_output_text_file_name: str@@ -70,7 +61,6 @@ class InferenceManagerConfig(ConfigModel):class Cogt(ConfigModel):inference_manager_config: InferenceManagerConfig- cogt_report_config: CogtReportConfigllm_config: LLMConfigimgg_config: ImggConfigocr_config: OcrConfigdiff --git a/pipelex/config.py b/pipelex/config.pyindex 7ecaa0fc6..1870cf754 100644--- a/pipelex/config.py+++ b/pipelex/config.py@@ -46,6 +46,16 @@ class PromptingConfig(ConfigModel):class FeatureConfig(ConfigModel):is_pipeline_tracking_enabled: boolis_activity_tracking_enabled: bool+ is_reporting_enabled: bool+++class ReportingConfig(ConfigModel):+ is_log_costs_to_console: bool+ is_generate_cost_report_file_enabled: bool+ cost_report_dir_path: str+ cost_report_base_name: str+ cost_report_extension: str+ cost_report_unit_scale: floatclass Pipelex(ConfigModel):@@ -61,6 +71,7 @@ class Pipelex(ConfigModel):prompting_config: PromptingConfigpipe_run_config: PipeRunConfig+ reporting_config: ReportingConfigclass PipelexConfig(ConfigRoot):diff --git a/pipelex/pipelex.py b/pipelex/pipelex.pyindex 8e990bf39..50a3d5a82 100644--- a/pipelex/pipelex.py+++ b/pipelex/pipelex.py@@ -26,6 +26,7 @@ from pipelex.pipeline.activity.activity_manager_protocol import ActivityManagerNfrom pipelex.pipeline.pipeline_manager import PipelineManagerfrom pipelex.pipeline.track.pipeline_tracker import PipelineTrackerfrom pipelex.pipeline.track.pipeline_tracker_protocol import PipelineTrackerNoOp, PipelineTrackerProtocol+from pipelex.reporting.reporting_manager import ReportingManagerfrom pipelex.reporting.reporting_protocol import ReportingNoOp, ReportingProtocolfrom pipelex.test_extras.registry_test_models import PipelexTestModelsfrom pipelex.tools.config.models import ConfigRoot@@ -121,7 +122,11 @@ class Pipelex:self.inference_manager = inference_manager or InferenceManager()self.pipelex_hub.set_inference_manager(self.inference_manager)- self.reporting_delegate = reporting_delegate or ReportingNoOp()+ self.reporting_delegate: ReportingProtocol+ if get_config().pipelex.feature_config.is_reporting_enabled:+ self.reporting_delegate = reporting_delegate or ReportingManager(reporting_config=get_config().pipelex.reporting_config)+ else:+ self.reporting_delegate = ReportingNoOp()self.pipelex_hub.set_report_delegate(self.reporting_delegate)# pipelex librariesdiff --git a/pipelex/pipelex.toml b/pipelex/pipelex.tomlindex a67c11ad8..114b49eb4 100644--- a/pipelex/pipelex.toml+++ b/pipelex/pipelex.toml@@ -7,6 +7,15 @@ extra_env_files = []# WIP/Experimental feature flagsis_pipeline_tracking_enabled = falseis_activity_tracking_enabled = false+is_reporting_enabled = true++[pipelex.reporting_config]+is_log_costs_to_console = false+is_generate_cost_report_file_enabled = true+cost_report_dir_path = "reports"+cost_report_base_name = "cost_report"+cost_report_extension = "xlsx"+cost_report_unit_scale = 1.0##################################################################################################### Log config@@ -74,14 +83,6 @@ is_auto_setup_preset_llm = trueis_auto_setup_preset_imgg = trueis_auto_setup_preset_ocr = true-[cogt.cogt_report_config]-is_log_costs_to_console = false-is_generate_cost_report_file_enabled = true-cost_report_dir_path = "reports"-cost_report_base_name = "cost_report"-cost_report_extension = "xlsx"-cost_report_unit_scale = 1.0-[cogt.llm_config]default_max_images = 100diff --git a/pipelex/reporting/reporting_manager.py b/pipelex/reporting/reporting_manager.pyindex d53fef332..761e5582a 100644--- a/pipelex/reporting/reporting_manager.py+++ b/pipelex/reporting/reporting_manager.py@@ -4,12 +4,12 @@ from pydantic import Field, RootModelfrom typing_extensions import overridefrom pipelex import log-from pipelex.cogt.config_cogt import CogtReportConfigfrom pipelex.cogt.exceptions import ReportingManagerErrorfrom pipelex.cogt.inference.cost_registry import CostRegistryfrom pipelex.cogt.inference.inference_job_abstract import InferenceJobAbstractfrom pipelex.cogt.llm.llm_job import LLMJobfrom pipelex.cogt.llm.llm_report import LLMTokenCostReport, LLMTokensUsage+from pipelex.config import ReportingConfigfrom pipelex.pipeline.pipeline_models import SpecialPipelineIdfrom pipelex.reporting.reporting_protocol import ReportingProtocolfrom pipelex.tools.misc.file_utils import ensure_path, get_incremental_file_path@@ -28,9 +28,9 @@ class UsageRegistry(RootModel[LLMUsageRegistryRoot]):class ReportingManager(ReportingProtocol):- def __init__(self, report_config: CogtReportConfig):+ def __init__(self, reporting_config: ReportingConfig):self._usage_registries: Dict[str, UsageRegistry] = {}- self._report_config = report_config+ self._reporting_config = reporting_config############################################################# Manager lifecycle@@ -63,13 +63,13 @@ class ReportingManager(ReportingProtocol):llm_token_cost_report: Optional[LLMTokenCostReport] = None- if self._report_config.is_log_costs_to_console:+ if self._reporting_config.is_log_costs_to_console:llm_token_cost_report = CostRegistry.complete_cost_report(llm_tokens_usage=llm_tokens_usage)pipeline_run_id = llm_job.job_metadata.pipeline_run_idself._get_registry(pipeline_run_id).add_tokens_usage(llm_tokens_usage)- if self._report_config.is_log_costs_to_console:+ if self._reporting_config.is_log_costs_to_console:log.verbose(llm_token_cost_report, title="Token Cost report")############################################################@@ -96,19 +96,19 @@ class ReportingManager(ReportingProtocol):def generate_report(self, pipeline_run_id: Optional[str] = None):pipeline_run_id = pipeline_run_id or SpecialPipelineId.UNTITLEDcost_report_file_path: Optional[str] = None- if self._report_config.is_generate_cost_report_file_enabled:- ensure_path(self._report_config.cost_report_dir_path)+ if self._reporting_config.is_generate_cost_report_file_enabled:+ ensure_path(self._reporting_config.cost_report_dir_path)cost_report_file_path = get_incremental_file_path(- base_path=self._report_config.cost_report_dir_path,- base_name=self._report_config.cost_report_base_name,- extension=self._report_config.cost_report_extension,+ base_path=self._reporting_config.cost_report_dir_path,+ base_name=self._reporting_config.cost_report_base_name,+ extension=self._reporting_config.cost_report_extension,)registry = self._get_registry(pipeline_run_id)CostRegistry.generate_report(pipeline_run_id=pipeline_run_id,llm_tokens_usages=registry.get_current_tokens_usage(),- unit_scale=self._report_config.cost_report_unit_scale,+ unit_scale=self._reporting_config.cost_report_unit_scale,cost_report_file_path=cost_report_file_path,)diff --git a/pyproject.toml b/pyproject.tomlindex 37c25eb22..f8861dac3 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -1,6 +1,6 @@[project]name = "pipelex"-version = "0.2.13"+version = "0.2.14"description = "Pipelex is an open-source dev tool based on a simple declarative language that lets you define replicable, structured, composable LLM pipelines."authors = [{ name = "Evotis S.A.S.", email = "[email protected]" }]maintainers = [{ name = "Pipelex staff", email = "[email protected]" }]