crewplus 0.2.68__py3-none-any.whl → 0.2.70__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/services/tracing_manager.py +6 -15
- {crewplus-0.2.68.dist-info → crewplus-0.2.70.dist-info}/METADATA +1 -1
- {crewplus-0.2.68.dist-info → crewplus-0.2.70.dist-info}/RECORD +6 -7
- crewplus/callbacks/run_id_handler.py +0 -131
- {crewplus-0.2.68.dist-info → crewplus-0.2.70.dist-info}/WHEEL +0 -0
- {crewplus-0.2.68.dist-info → crewplus-0.2.70.dist-info}/entry_points.txt +0 -0
- {crewplus-0.2.68.dist-info → crewplus-0.2.70.dist-info}/licenses/LICENSE +0 -0
|
@@ -9,16 +9,11 @@ import logging
|
|
|
9
9
|
try:
|
|
10
10
|
from langfuse.langchain import CallbackHandler as LangfuseCallbackHandler
|
|
11
11
|
from ..callbacks.async_langfuse_handler import AsyncLangfuseCallbackHandler
|
|
12
|
-
# Import the new custom handlers
|
|
13
|
-
from ..callbacks.run_id_handler import RunIdCallbackHandler, AsyncRunIdCallbackHandler
|
|
14
12
|
LANGFUSE_AVAILABLE = True
|
|
15
13
|
except ImportError:
|
|
16
14
|
LANGFUSE_AVAILABLE = False
|
|
17
15
|
LangfuseCallbackHandler = None
|
|
18
16
|
AsyncLangfuseCallbackHandler = None
|
|
19
|
-
# Define dummy classes for the custom handlers to prevent errors if langfuse is not installed
|
|
20
|
-
class RunIdCallbackHandler: pass
|
|
21
|
-
class AsyncRunIdCallbackHandler: pass
|
|
22
17
|
|
|
23
18
|
class TracingContext(Protocol):
|
|
24
19
|
"""
|
|
@@ -101,24 +96,20 @@ class TracingManager:
|
|
|
101
96
|
# by detecting its environment variables.
|
|
102
97
|
enable_langfuse = self.context.enable_tracing
|
|
103
98
|
if enable_langfuse is None: # Auto-detect if not explicitly set
|
|
104
|
-
self.context.logger.debug("enable_tracing is None, auto-detecting via environment variables.")
|
|
105
99
|
langfuse_env_vars = ["LANGFUSE_PUBLIC_KEY", "LANGFUSE_SECRET_KEY"]
|
|
106
100
|
enable_langfuse = any(os.getenv(var) for var in langfuse_env_vars)
|
|
107
|
-
self.context.logger.debug(f"Auto-detection result for enable_langfuse: {enable_langfuse}")
|
|
108
101
|
|
|
109
102
|
if enable_langfuse:
|
|
110
103
|
try:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
self._sync_handlers.append(LangfuseCallbackHandler())
|
|
115
|
-
self._sync_handlers.append(RunIdCallbackHandler())
|
|
104
|
+
# Create both sync and async handlers. We'll pick one at runtime.
|
|
105
|
+
sync_handler = LangfuseCallbackHandler()
|
|
106
|
+
self._sync_handlers.append(sync_handler)
|
|
116
107
|
|
|
117
108
|
if AsyncLangfuseCallbackHandler:
|
|
118
|
-
|
|
119
|
-
self._async_handlers.append(
|
|
109
|
+
async_handler = AsyncLangfuseCallbackHandler()
|
|
110
|
+
self._async_handlers.append(async_handler)
|
|
120
111
|
|
|
121
|
-
self.context.logger.info(f"Langfuse tracing enabled for {self.context.get_model_identifier()}
|
|
112
|
+
self.context.logger.info(f"Langfuse tracing enabled for {self.context.get_model_identifier()}")
|
|
122
113
|
except Exception as e:
|
|
123
114
|
self.context.logger.warning(f"Failed to initialize Langfuse: {e}", exc_info=True)
|
|
124
115
|
else:
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
crewplus-0.2.
|
|
2
|
-
crewplus-0.2.
|
|
3
|
-
crewplus-0.2.
|
|
4
|
-
crewplus-0.2.
|
|
1
|
+
crewplus-0.2.70.dist-info/METADATA,sha256=M2xMdWJbR5BsBLfIGxner83D2vLfE5ui-hmEmhcVMUQ,5424
|
|
2
|
+
crewplus-0.2.70.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
|
|
3
|
+
crewplus-0.2.70.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
|
4
|
+
crewplus-0.2.70.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=T_YqmGmUp2_DIc01dlVY-aC43NKcevfRejAWN-lft6M,5266
|
|
9
8
|
crewplus/services/__init__.py,sha256=V1CG8b2NOmRzNgQH7BPl4KVxWSYJH5vfEsW1wVErKNE,375
|
|
10
9
|
crewplus/services/azure_chat_model.py,sha256=iWzJ2GQFSNmwJx-2O5_xKPSB6VVc-7T6bcfFI8_WezA,5521
|
|
11
10
|
crewplus/services/gemini_chat_model.py,sha256=DYqz01H2TIHiCDQesSozVfOsMigno6QGwOtIweg7UHk,40103
|
|
12
11
|
crewplus/services/init_services.py,sha256=tc1ti8Yufo2ixlJpwg8uH0KmoyQ4EqxCOe4uTEWnlRM,2413
|
|
13
12
|
crewplus/services/model_load_balancer.py,sha256=Q9Gx3GrbKworU-Ytxeqp0ggHSgZ1Q6brtTk-nCl4sak,12095
|
|
14
|
-
crewplus/services/tracing_manager.py,sha256=
|
|
13
|
+
crewplus/services/tracing_manager.py,sha256=_C4zYj6o_k5mDWY7vM8UeaVaXp8SqrkvYOb0Jj-y3sY,7566
|
|
15
14
|
crewplus/utils/__init__.py,sha256=2Gk1n5srFJQnFfBuYTxktdtKOVZyNrFcNaZKhXk35Pw,142
|
|
16
15
|
crewplus/utils/schema_action.py,sha256=GDaBoVFQD1rXqrLVSMTfXYW1xcUu7eDcHsn57XBSnIg,422
|
|
17
16
|
crewplus/utils/schema_document_updater.py,sha256=frvffxn2vbi71fHFPoGb9hq7gH2azmmdq17p-Fumnvg,7322
|
|
@@ -23,4 +22,4 @@ docs/GeminiChatModel.md,sha256=zZYyl6RmjZTUsKxxMiC9O4yV70MC4TD-IGUmWhIDBKA,8677
|
|
|
23
22
|
docs/ModelLoadBalancer.md,sha256=aGHES1dcXPz4c7Y8kB5-vsCNJjriH2SWmjBkSGoYKiI,4398
|
|
24
23
|
docs/VDBService.md,sha256=Dw286Rrf_fsi13jyD3Bo4Sy7nZ_G7tYm7d8MZ2j9hxk,9375
|
|
25
24
|
docs/index.md,sha256=3tlc15uR8lzFNM5WjdoZLw0Y9o1P1gwgbEnOdIBspqc,1643
|
|
26
|
-
crewplus-0.2.
|
|
25
|
+
crewplus-0.2.70.dist-info/RECORD,,
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
# File: crewplus/callbacks/run_id_handler.py
|
|
2
|
-
|
|
3
|
-
from typing import Any, Dict, List
|
|
4
|
-
from uuid import UUID
|
|
5
|
-
import logging
|
|
6
|
-
|
|
7
|
-
# Langfuse imports with graceful fallback
|
|
8
|
-
from langfuse.langchain import CallbackHandler as LangfuseCallbackHandler
|
|
9
|
-
from .async_langfuse_handler import AsyncLangfuseCallbackHandler
|
|
10
|
-
from langfuse import get_client
|
|
11
|
-
from langchain_core.messages import BaseMessage
|
|
12
|
-
#from langchain_core.outputs import LLMResult
|
|
13
|
-
LANGFUSE_AVAILABLE = True
|
|
14
|
-
|
|
15
|
-
# --- Custom Callback Handlers to capture the run_id ---
|
|
16
|
-
|
|
17
|
-
class RunIdCallbackHandler(LangfuseCallbackHandler):
|
|
18
|
-
"""
|
|
19
|
-
A custom handler that injects the LangChain run_id into the metadata
|
|
20
|
-
before the Langfuse observation is created.
|
|
21
|
-
"""
|
|
22
|
-
def __init__(self, *args, **kwargs):
|
|
23
|
-
super().__init__(*args, **kwargs)
|
|
24
|
-
self.run_trace_map = {}
|
|
25
|
-
# Use a named logger for better context
|
|
26
|
-
self.logger = logging.getLogger(__name__)
|
|
27
|
-
self.logger.info("RunIdCallbackHandler initialized.")
|
|
28
|
-
|
|
29
|
-
def _inject_run_id_to_metadata(self, run_id: UUID, kwargs: Dict[str, Any]) -> Dict[str, Any]:
|
|
30
|
-
"""Helper to safely add the run_id to the metadata in kwargs."""
|
|
31
|
-
metadata = kwargs.get("metadata") or {}
|
|
32
|
-
metadata["langchain_run_id"] = str(run_id)
|
|
33
|
-
kwargs["metadata"] = metadata
|
|
34
|
-
return kwargs
|
|
35
|
-
|
|
36
|
-
def on_chain_start(
|
|
37
|
-
self,
|
|
38
|
-
serialized: Dict[str, Any],
|
|
39
|
-
inputs: Dict[str, Any],
|
|
40
|
-
*,
|
|
41
|
-
run_id: UUID,
|
|
42
|
-
**kwargs: Any,
|
|
43
|
-
) -> Any:
|
|
44
|
-
self.logger.debug(f"[on_chain_start] Intercepted run_id: {run_id}")
|
|
45
|
-
kwargs = self._inject_run_id_to_metadata(run_id, kwargs)
|
|
46
|
-
|
|
47
|
-
# Call the base handler with the modified kwargs
|
|
48
|
-
result = super().on_chain_start(serialized, inputs, run_id=run_id, **kwargs)
|
|
49
|
-
|
|
50
|
-
# We still map the trace_id for easy retrieval in tests
|
|
51
|
-
if self.last_trace_id:
|
|
52
|
-
self.run_trace_map[str(run_id)] = self.last_trace_id
|
|
53
|
-
self.logger.info(f"[on_chain_start] Mapped run_id '{run_id}' to trace_id '{self.last_trace_id}'.")
|
|
54
|
-
|
|
55
|
-
return result
|
|
56
|
-
|
|
57
|
-
def on_chat_model_start(
|
|
58
|
-
self,
|
|
59
|
-
serialized: Dict[str, Any],
|
|
60
|
-
messages: List[List[BaseMessage]],
|
|
61
|
-
*,
|
|
62
|
-
run_id: UUID,
|
|
63
|
-
parent_run_id: UUID | None = None,
|
|
64
|
-
**kwargs: Any,
|
|
65
|
-
) -> Any:
|
|
66
|
-
self.logger.debug(f"[on_chat_model_start] Intercepted run_id: {run_id}")
|
|
67
|
-
|
|
68
|
-
# Only inject the run_id if this is the root of the trace
|
|
69
|
-
if parent_run_id is None:
|
|
70
|
-
kwargs = self._inject_run_id_to_metadata(run_id, kwargs)
|
|
71
|
-
|
|
72
|
-
# Call the base handler with potentially modified kwargs
|
|
73
|
-
result = super().on_chat_model_start(serialized, messages, run_id=run_id, parent_run_id=parent_run_id, **kwargs)
|
|
74
|
-
|
|
75
|
-
if parent_run_id is None and self.last_trace_id:
|
|
76
|
-
self.run_trace_map[str(run_id)] = self.last_trace_id
|
|
77
|
-
self.logger.info(f"[on_chat_model_start] Mapped root run_id '{run_id}' to trace_id '{self.last_trace_id}'.")
|
|
78
|
-
|
|
79
|
-
return result
|
|
80
|
-
|
|
81
|
-
# You would similarly update the AsyncRunIdCallbackHandler if you use it
|
|
82
|
-
class AsyncRunIdCallbackHandler(AsyncLangfuseCallbackHandler):
|
|
83
|
-
"""
|
|
84
|
-
An async custom handler that injects the LangChain run_id into the metadata
|
|
85
|
-
before the Langfuse observation is created.
|
|
86
|
-
"""
|
|
87
|
-
def __init__(self, *args, **kwargs):
|
|
88
|
-
super().__init__(*args, **kwargs)
|
|
89
|
-
self.run_trace_map = {}
|
|
90
|
-
self.logger = logging.getLogger(__name__)
|
|
91
|
-
self.logger.info("AsyncRunIdCallbackHandler initialized.")
|
|
92
|
-
|
|
93
|
-
def _inject_run_id_to_metadata(self, run_id: UUID, kwargs: Dict[str, Any]) -> Dict[str, Any]:
|
|
94
|
-
"""Helper to safely add the run_id to the metadata in kwargs."""
|
|
95
|
-
metadata = kwargs.get("metadata") or {}
|
|
96
|
-
metadata["langchain_run_id"] = str(run_id)
|
|
97
|
-
kwargs["metadata"] = metadata
|
|
98
|
-
return kwargs
|
|
99
|
-
|
|
100
|
-
async def on_chain_start(
|
|
101
|
-
self,
|
|
102
|
-
serialized: Dict[str, Any],
|
|
103
|
-
inputs: Dict[str, Any],
|
|
104
|
-
*,
|
|
105
|
-
run_id: UUID,
|
|
106
|
-
**kwargs: Any,
|
|
107
|
-
) -> Any:
|
|
108
|
-
self.logger.debug(f"Async [on_chain_start] Intercepted run_id: {run_id}")
|
|
109
|
-
kwargs = self._inject_run_id_to_metadata(run_id, kwargs)
|
|
110
|
-
result = await super().on_chain_start(serialized, inputs, run_id=run_id, **kwargs)
|
|
111
|
-
if self.last_trace_id:
|
|
112
|
-
self.run_trace_map[str(run_id)] = self.last_trace_id
|
|
113
|
-
return result
|
|
114
|
-
|
|
115
|
-
async def on_chat_model_start(
|
|
116
|
-
self,
|
|
117
|
-
serialized: Dict[str, Any],
|
|
118
|
-
messages: List[List[BaseMessage]],
|
|
119
|
-
*,
|
|
120
|
-
run_id: UUID,
|
|
121
|
-
parent_run_id: UUID | None = None,
|
|
122
|
-
**kwargs: Any,
|
|
123
|
-
) -> Any:
|
|
124
|
-
self.logger.debug(f"Async [on_chat_model_start] Intercepted run_id: {run_id}")
|
|
125
|
-
if parent_run_id is None:
|
|
126
|
-
kwargs = self._inject_run_id_to_metadata(run_id, kwargs)
|
|
127
|
-
result = await super().on_chat_model_start(serialized, messages, run_id=run_id, parent_run_id=parent_run_id, **kwargs)
|
|
128
|
-
|
|
129
|
-
if parent_run_id is None and self.last_trace_id:
|
|
130
|
-
self.run_trace_map[str(run_id)] = self.last_trace_id
|
|
131
|
-
return result
|
|
File without changes
|
|
File without changes
|
|
File without changes
|