crewplus 0.2.64__py3-none-any.whl → 0.2.66__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of crewplus might be problematic. Click here for more details.
- crewplus/callbacks/run_id_handler.py +49 -16
- {crewplus-0.2.64.dist-info → crewplus-0.2.66.dist-info}/METADATA +1 -1
- {crewplus-0.2.64.dist-info → crewplus-0.2.66.dist-info}/RECORD +6 -6
- {crewplus-0.2.64.dist-info → crewplus-0.2.66.dist-info}/WHEEL +0 -0
- {crewplus-0.2.64.dist-info → crewplus-0.2.66.dist-info}/entry_points.txt +0 -0
- {crewplus-0.2.64.dist-info → crewplus-0.2.66.dist-info}/licenses/LICENSE +0 -0
|
@@ -22,8 +22,16 @@ if LANGFUSE_AVAILABLE:
|
|
|
22
22
|
class RunIdCallbackHandler(LangfuseCallbackHandler):
|
|
23
23
|
"""
|
|
24
24
|
A custom synchronous callback handler that captures the Langchain run_id
|
|
25
|
-
and adds it to the Langfuse trace metadata.
|
|
25
|
+
and adds it to the Langfuse trace metadata. It also stores the mapping
|
|
26
|
+
between the run_id and the generated trace_id.
|
|
26
27
|
"""
|
|
28
|
+
def __init__(self, *args, **kwargs):
|
|
29
|
+
super().__init__(*args, **kwargs)
|
|
30
|
+
self.run_trace_map = {}
|
|
31
|
+
# Use a named logger for better context
|
|
32
|
+
self.logger = logging.getLogger(__name__)
|
|
33
|
+
self.logger.info("RunIdCallbackHandler initialized.")
|
|
34
|
+
|
|
27
35
|
def on_chain_start(
|
|
28
36
|
self,
|
|
29
37
|
serialized: Dict[str, Any],
|
|
@@ -31,17 +39,28 @@ if LANGFUSE_AVAILABLE:
|
|
|
31
39
|
run_id: UUID,
|
|
32
40
|
**kwargs: Any,
|
|
33
41
|
) -> Any:
|
|
42
|
+
self.logger.debug(f"on_chain_start triggered for run_id: {run_id}")
|
|
34
43
|
# First, let the base handler do its work, which includes creating the trace
|
|
35
44
|
run = super().on_chain_start(serialized, inputs, run_id, **kwargs)
|
|
45
|
+
self.logger.debug(f"Base handler's on_chain_start completed. Current trace_id: {self.last_trace_id}")
|
|
36
46
|
|
|
37
47
|
try:
|
|
38
|
-
#
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
# The base handler sets `self.last_trace_id` when a trace is created
|
|
49
|
+
if self.last_trace_id:
|
|
50
|
+
self.run_trace_map[str(run_id)] = self.last_trace_id
|
|
51
|
+
self.logger.info(f"Mapping run_id '{run_id}' to trace_id '{self.last_trace_id}'.")
|
|
52
|
+
|
|
53
|
+
# Then, update the created trace with the run_id as metadata
|
|
54
|
+
langfuse_client = get_client()
|
|
55
|
+
langfuse_client.update_current_trace(
|
|
56
|
+
metadata={"langchain_run_id": str(run_id)}
|
|
57
|
+
)
|
|
58
|
+
self.logger.info(f"Successfully updated trace '{self.last_trace_id}' with metadata for run_id '{run_id}'.")
|
|
59
|
+
else:
|
|
60
|
+
self.logger.warning(f"Could not find 'last_trace_id' for run_id '{run_id}'. Metadata will not be updated.")
|
|
61
|
+
|
|
43
62
|
except Exception as e:
|
|
44
|
-
|
|
63
|
+
self.logger.error(f"Failed to process run_id '{run_id}' in RunIdCallbackHandler: {e}", exc_info=True)
|
|
45
64
|
|
|
46
65
|
return run
|
|
47
66
|
|
|
@@ -50,6 +69,12 @@ if LANGFUSE_AVAILABLE:
|
|
|
50
69
|
A custom asynchronous callback handler that captures the Langchain run_id
|
|
51
70
|
and adds it to the Langfuse trace metadata.
|
|
52
71
|
"""
|
|
72
|
+
def __init__(self, *args, **kwargs):
|
|
73
|
+
super().__init__(*args, **kwargs)
|
|
74
|
+
self.run_trace_map = {}
|
|
75
|
+
self.logger = logging.getLogger(__name__)
|
|
76
|
+
self.logger.info("AsyncRunIdCallbackHandler initialized.")
|
|
77
|
+
|
|
53
78
|
async def on_chain_start(
|
|
54
79
|
self,
|
|
55
80
|
serialized: Dict[str, Any],
|
|
@@ -57,17 +82,25 @@ if LANGFUSE_AVAILABLE:
|
|
|
57
82
|
run_id: UUID,
|
|
58
83
|
**kwargs: Any,
|
|
59
84
|
) -> Any:
|
|
60
|
-
|
|
85
|
+
self.logger.debug(f"Async on_chain_start triggered for run_id: {run_id}")
|
|
86
|
+
# First, let the base handler do its work
|
|
61
87
|
run = await super().on_chain_start(serialized, inputs, run_id, **kwargs)
|
|
62
|
-
|
|
88
|
+
self.logger.debug(f"Async base handler's on_chain_start completed. Current trace_id: {self.last_trace_id}")
|
|
89
|
+
|
|
63
90
|
try:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
91
|
+
if self.last_trace_id:
|
|
92
|
+
self.run_trace_map[str(run_id)] = self.last_trace_id
|
|
93
|
+
self.logger.info(f"Async: Mapping run_id '{run_id}' to trace_id '{self.last_trace_id}'.")
|
|
94
|
+
|
|
95
|
+
langfuse_client = get_client()
|
|
96
|
+
langfuse_client.update_current_trace(
|
|
97
|
+
metadata={"langchain_run_id": str(run_id)}
|
|
98
|
+
)
|
|
99
|
+
self.logger.info(f"Async: Successfully updated trace '{self.last_trace_id}' with metadata for run_id '{run_id}'.")
|
|
100
|
+
else:
|
|
101
|
+
self.logger.warning(f"Async: Could not find 'last_trace_id' for run_id '{run_id}'. Metadata will not be updated.")
|
|
102
|
+
|
|
70
103
|
except Exception as e:
|
|
71
|
-
|
|
104
|
+
self.logger.error(f"Async: Failed to process run_id '{run_id}' in AsyncRunIdCallbackHandler: {e}", exc_info=True)
|
|
72
105
|
|
|
73
106
|
return run
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
crewplus-0.2.
|
|
2
|
-
crewplus-0.2.
|
|
3
|
-
crewplus-0.2.
|
|
4
|
-
crewplus-0.2.
|
|
1
|
+
crewplus-0.2.66.dist-info/METADATA,sha256=nfG_3A6490ii2Hmp9cfDZgWd_aIOebzVa7cyhAsCDao,5424
|
|
2
|
+
crewplus-0.2.66.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
|
|
3
|
+
crewplus-0.2.66.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
|
4
|
+
crewplus-0.2.66.dist-info/licenses/LICENSE,sha256=2_NHSHRTKB_cTcT_GXgcenOCtIZku8j343mOgAguTfc,1087
|
|
5
5
|
crewplus/__init__.py,sha256=m46HkZL1Y4toD619NL47Sn2Qe084WFFSFD7e6VoYKZc,284
|
|
6
6
|
crewplus/callbacks/__init__.py,sha256=YG7ieeb91qEjp1zF0-inEN7mjZ7yT_D2yzdWFT8Z1Ws,63
|
|
7
7
|
crewplus/callbacks/async_langfuse_handler.py,sha256=A4uFeLpvOUdc58M7sZoE65_C1V98u0QCvx5jUquM0pM,7006
|
|
8
|
-
crewplus/callbacks/run_id_handler.py,sha256=
|
|
8
|
+
crewplus/callbacks/run_id_handler.py,sha256=UurImqJYJg_EnOKB8nzBmG377KL4wI7fl8lz-98_VXY,4964
|
|
9
9
|
crewplus/services/__init__.py,sha256=V1CG8b2NOmRzNgQH7BPl4KVxWSYJH5vfEsW1wVErKNE,375
|
|
10
10
|
crewplus/services/azure_chat_model.py,sha256=iWzJ2GQFSNmwJx-2O5_xKPSB6VVc-7T6bcfFI8_WezA,5521
|
|
11
11
|
crewplus/services/gemini_chat_model.py,sha256=DYqz01H2TIHiCDQesSozVfOsMigno6QGwOtIweg7UHk,40103
|
|
@@ -23,4 +23,4 @@ docs/GeminiChatModel.md,sha256=zZYyl6RmjZTUsKxxMiC9O4yV70MC4TD-IGUmWhIDBKA,8677
|
|
|
23
23
|
docs/ModelLoadBalancer.md,sha256=aGHES1dcXPz4c7Y8kB5-vsCNJjriH2SWmjBkSGoYKiI,4398
|
|
24
24
|
docs/VDBService.md,sha256=Dw286Rrf_fsi13jyD3Bo4Sy7nZ_G7tYm7d8MZ2j9hxk,9375
|
|
25
25
|
docs/index.md,sha256=3tlc15uR8lzFNM5WjdoZLw0Y9o1P1gwgbEnOdIBspqc,1643
|
|
26
|
-
crewplus-0.2.
|
|
26
|
+
crewplus-0.2.66.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|