From 22a24c8477549175b36e1793b02e462ce5bef6dc Mon Sep 17 00:00:00 2001 From: ZanSara Date: Mon, 16 Oct 2023 17:02:50 +0100 Subject: [PATCH] chore: `HuggingFaceLocalGenerator` telemetry (#6070) * add telemetry to pipelines 2.0 * only collect data if telemetry is on * reno * add downsampling * typing * manual tests * pylint * simplify code * Update haystack/preview/telemetry/__init__.py * look for _telemetry_data * rather index by component type * black * mypy * error handling * comment * review feedback & small improvements * defaultdict * stray changes * try-catch * method instead of attribute * fixes * remove print statements * lint * invert condition * always send the first event of the day * collect specs * track 2nd and 3rd events too * send first event and then max 1 event a minute * rename constant * black * add telemetry details to HuggingFaceLocalGenerator * add test * check if the model is a string --------- Co-authored-by: Stefano Fiorucci <44616784+anakin87@users.noreply.github.com> --- .../generators/hugging_face/hugging_face_local.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/haystack/preview/components/generators/hugging_face/hugging_face_local.py b/haystack/preview/components/generators/hugging_face/hugging_face_local.py index 0f64aae856..7938edc887 100644 --- a/haystack/preview/components/generators/hugging_face/hugging_face_local.py +++ b/haystack/preview/components/generators/hugging_face/hugging_face_local.py @@ -110,6 +110,14 @@ def __init__( self.generation_kwargs = generation_kwargs self.pipeline = None + def _get_telemetry_data(self) -> Dict[str, Any]: + """ + Data that is sent to Posthog for usage analytics. + """ + if isinstance(self.pipeline_kwargs["model"], str): + return {"model": self.pipeline_kwargs["model"]} + return {"model": f"[object of type {type(self.pipeline_kwargs['model'])}]"} + def warm_up(self): if self.pipeline is None: self.pipeline = pipeline(**self.pipeline_kwargs)