|
95 | 95 | Prompt_Chat, |
96 | 96 | Prompt_Text, |
97 | 97 | ScoreBody, |
| 98 | + TraceBody, |
98 | 99 | ) |
99 | 100 | from langfuse.batch_evaluation import ( |
100 | 101 | BatchEvaluationResult, |
@@ -1839,6 +1840,39 @@ def create_score( |
1839 | 1840 | f"Error creating score: Failed to process score event for trace_id={trace_id}, name={name}. Error: {e}" |
1840 | 1841 | ) |
1841 | 1842 |
|
| 1843 | + def _create_trace_tags_via_ingestion( |
| 1844 | + self, |
| 1845 | + *, |
| 1846 | + trace_id: str, |
| 1847 | + tags: List[str], |
| 1848 | + ) -> None: |
| 1849 | + """Private helper to enqueue trace tag updates via ingestion API events.""" |
| 1850 | + if not self._tracing_enabled: |
| 1851 | + return |
| 1852 | + |
| 1853 | + if len(tags) == 0: |
| 1854 | + return |
| 1855 | + |
| 1856 | + try: |
| 1857 | + new_body = TraceBody( |
| 1858 | + id=trace_id, |
| 1859 | + tags=tags, |
| 1860 | + ) |
| 1861 | + |
| 1862 | + event = { |
| 1863 | + "id": self.create_trace_id(), |
| 1864 | + "type": "trace-create", |
| 1865 | + "timestamp": _get_timestamp(), |
| 1866 | + "body": new_body, |
| 1867 | + } |
| 1868 | + |
| 1869 | + if self._resources is not None: |
| 1870 | + self._resources.add_trace_task(event) |
| 1871 | + except Exception as e: |
| 1872 | + langfuse_logger.exception( |
| 1873 | + f"Error updating trace tags: Failed to process trace update event for trace_id={trace_id}. Error: {e}" |
| 1874 | + ) |
| 1875 | + |
1842 | 1876 | @overload |
1843 | 1877 | def score_current_span( |
1844 | 1878 | self, |
@@ -2866,8 +2900,10 @@ def run_batched_evaluation( |
2866 | 2900 | max_retries: int = 3, |
2867 | 2901 | evaluators: List[EvaluatorFunction], |
2868 | 2902 | composite_evaluator: Optional[CompositeEvaluatorFunction] = None, |
2869 | | - max_concurrency: int = 50, |
| 2903 | + max_concurrency: int = 5, |
2870 | 2904 | metadata: Optional[Dict[str, Any]] = None, |
| 2905 | + _add_observation_scores_to_trace: bool = False, |
| 2906 | + _additional_trace_tags: Optional[List[str]] = None, |
2871 | 2907 | resume_from: Optional[BatchEvaluationResumeToken] = None, |
2872 | 2908 | verbose: bool = False, |
2873 | 2909 | ) -> BatchEvaluationResult: |
@@ -2909,7 +2945,7 @@ def run_batched_evaluation( |
2909 | 2945 | items matching the filter. Useful for testing or limiting evaluation runs. |
2910 | 2946 | Default: None (process all). |
2911 | 2947 | max_concurrency: Maximum number of items to evaluate concurrently. Controls |
2912 | | - parallelism and resource usage. Default: 50. |
| 2948 | + parallelism and resource usage. Default: 5. |
2913 | 2949 | composite_evaluator: Optional function that creates a composite score from |
2914 | 2950 | item-level evaluations. Receives the original item and its evaluations, |
2915 | 2951 | returns a single Evaluation. Useful for weighted averages or combined metrics. |
@@ -3078,6 +3114,8 @@ def composite_evaluator(*, item, evaluations): |
3078 | 3114 | max_concurrency=max_concurrency, |
3079 | 3115 | composite_evaluator=composite_evaluator, |
3080 | 3116 | metadata=metadata, |
| 3117 | + _add_observation_scores_to_trace=_add_observation_scores_to_trace, |
| 3118 | + _additional_trace_tags=_additional_trace_tags, |
3081 | 3119 | max_retries=max_retries, |
3082 | 3120 | verbose=verbose, |
3083 | 3121 | resume_from=resume_from, |
|
0 commit comments