crewplus 0.2.63__tar.gz → 0.2.65__tar.gz
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-0.2.63 → crewplus-0.2.65}/PKG-INFO +1 -1
- crewplus-0.2.65/crewplus/callbacks/run_id_handler.py +73 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/services/tracing_manager.py +11 -5
- {crewplus-0.2.63 → crewplus-0.2.65}/pyproject.toml +1 -1
- {crewplus-0.2.63 → crewplus-0.2.65}/LICENSE +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/README.md +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/__init__.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/callbacks/__init__.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/callbacks/async_langfuse_handler.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/services/__init__.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/services/azure_chat_model.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/services/gemini_chat_model.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/services/init_services.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/services/model_load_balancer.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/utils/__init__.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/utils/schema_action.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/utils/schema_document_updater.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/vectorstores/milvus/__init__.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/vectorstores/milvus/milvus_schema_manager.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/vectorstores/milvus/schema_milvus.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/crewplus/vectorstores/milvus/vdb_service.py +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/docs/GeminiChatModel.md +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/docs/ModelLoadBalancer.md +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/docs/VDBService.md +0 -0
- {crewplus-0.2.63 → crewplus-0.2.65}/docs/index.md +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# File: crewplus/callbacks/run_id_handler.py
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict
|
|
4
|
+
from uuid import UUID
|
|
5
|
+
import logging
|
|
6
|
+
|
|
7
|
+
# Langfuse imports with graceful fallback
|
|
8
|
+
try:
|
|
9
|
+
from langfuse.langchain import CallbackHandler as LangfuseCallbackHandler
|
|
10
|
+
from .async_langfuse_handler import AsyncLangfuseCallbackHandler
|
|
11
|
+
from langfuse import get_client
|
|
12
|
+
LANGFUSE_AVAILABLE = True
|
|
13
|
+
except ImportError:
|
|
14
|
+
LANGFUSE_AVAILABLE = False
|
|
15
|
+
# Define dummy base classes if langfuse is not available to avoid runtime errors
|
|
16
|
+
class LangfuseCallbackHandler: pass
|
|
17
|
+
class AsyncLangfuseCallbackHandler: pass
|
|
18
|
+
get_client = None
|
|
19
|
+
|
|
20
|
+
# --- Custom Callback Handlers to capture the run_id ---
|
|
21
|
+
if LANGFUSE_AVAILABLE:
|
|
22
|
+
class RunIdCallbackHandler(LangfuseCallbackHandler):
|
|
23
|
+
"""
|
|
24
|
+
A custom synchronous callback handler that captures the Langchain run_id
|
|
25
|
+
and adds it to the Langfuse trace metadata.
|
|
26
|
+
"""
|
|
27
|
+
def on_chain_start(
|
|
28
|
+
self,
|
|
29
|
+
serialized: Dict[str, Any],
|
|
30
|
+
inputs: Dict[str, Any],
|
|
31
|
+
run_id: UUID,
|
|
32
|
+
**kwargs: Any,
|
|
33
|
+
) -> Any:
|
|
34
|
+
# First, let the base handler do its work, which includes creating the trace
|
|
35
|
+
run = super().on_chain_start(serialized, inputs, run_id, **kwargs)
|
|
36
|
+
|
|
37
|
+
try:
|
|
38
|
+
# Then, update the created trace with the run_id as metadata
|
|
39
|
+
langfuse_client = get_client()
|
|
40
|
+
langfuse_client.update_current_trace(
|
|
41
|
+
metadata={"langchain_run_id": str(run_id)}
|
|
42
|
+
)
|
|
43
|
+
except Exception as e:
|
|
44
|
+
logging.getLogger(__name__).warning(f"Failed to add run_id to Langfuse trace: {e}")
|
|
45
|
+
|
|
46
|
+
return run
|
|
47
|
+
|
|
48
|
+
class AsyncRunIdCallbackHandler(AsyncLangfuseCallbackHandler):
|
|
49
|
+
"""
|
|
50
|
+
A custom asynchronous callback handler that captures the Langchain run_id
|
|
51
|
+
and adds it to the Langfuse trace metadata.
|
|
52
|
+
"""
|
|
53
|
+
async def on_chain_start(
|
|
54
|
+
self,
|
|
55
|
+
serialized: Dict[str, Any],
|
|
56
|
+
inputs: Dict[str, Any],
|
|
57
|
+
run_id: UUID,
|
|
58
|
+
**kwargs: Any,
|
|
59
|
+
) -> Any:
|
|
60
|
+
# First, let the base handler do its work, which includes creating the trace
|
|
61
|
+
run = await super().on_chain_start(serialized, inputs, run_id, **kwargs)
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
# The get_client() is thread-safe and can be used in async contexts
|
|
65
|
+
# for this type of single, atomic update.
|
|
66
|
+
langfuse_client = get_client()
|
|
67
|
+
langfuse_client.update_current_trace(
|
|
68
|
+
metadata={"langchain_run_id": str(run_id)}
|
|
69
|
+
)
|
|
70
|
+
except Exception as e:
|
|
71
|
+
logging.getLogger(__name__).warning(f"Failed to add run_id to async Langfuse trace: {e}")
|
|
72
|
+
|
|
73
|
+
return run
|
|
@@ -9,11 +9,16 @@ 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
|
|
12
14
|
LANGFUSE_AVAILABLE = True
|
|
13
15
|
except ImportError:
|
|
14
16
|
LANGFUSE_AVAILABLE = False
|
|
15
17
|
LangfuseCallbackHandler = None
|
|
16
18
|
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
|
|
17
22
|
|
|
18
23
|
class TracingContext(Protocol):
|
|
19
24
|
"""
|
|
@@ -98,13 +103,14 @@ class TracingManager:
|
|
|
98
103
|
|
|
99
104
|
if enable_langfuse:
|
|
100
105
|
try:
|
|
101
|
-
# Create
|
|
102
|
-
|
|
103
|
-
self._sync_handlers.append(
|
|
106
|
+
# Create and add both the standard and the run_id-capturing handlers.
|
|
107
|
+
# The standard handler creates the trace, and the custom one updates it.
|
|
108
|
+
self._sync_handlers.append(LangfuseCallbackHandler())
|
|
109
|
+
self._sync_handlers.append(RunIdCallbackHandler())
|
|
104
110
|
|
|
105
111
|
if AsyncLangfuseCallbackHandler:
|
|
106
|
-
|
|
107
|
-
self._async_handlers.append(
|
|
112
|
+
self._async_handlers.append(AsyncLangfuseCallbackHandler())
|
|
113
|
+
self._async_handlers.append(AsyncRunIdCallbackHandler())
|
|
108
114
|
|
|
109
115
|
self.context.logger.info(f"Langfuse tracing enabled for {self.context.get_model_identifier()}")
|
|
110
116
|
except Exception as e:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|