crewplus 0.2.65__tar.gz → 0.2.67__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.

Files changed (26) hide show
  1. {crewplus-0.2.65 → crewplus-0.2.67}/PKG-INFO +1 -1
  2. crewplus-0.2.67/crewplus/callbacks/run_id_handler.py +99 -0
  3. {crewplus-0.2.65 → crewplus-0.2.67}/pyproject.toml +1 -1
  4. crewplus-0.2.65/crewplus/callbacks/run_id_handler.py +0 -73
  5. {crewplus-0.2.65 → crewplus-0.2.67}/LICENSE +0 -0
  6. {crewplus-0.2.65 → crewplus-0.2.67}/README.md +0 -0
  7. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/__init__.py +0 -0
  8. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/callbacks/__init__.py +0 -0
  9. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/callbacks/async_langfuse_handler.py +0 -0
  10. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/services/__init__.py +0 -0
  11. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/services/azure_chat_model.py +0 -0
  12. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/services/gemini_chat_model.py +0 -0
  13. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/services/init_services.py +0 -0
  14. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/services/model_load_balancer.py +0 -0
  15. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/services/tracing_manager.py +0 -0
  16. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/utils/__init__.py +0 -0
  17. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/utils/schema_action.py +0 -0
  18. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/utils/schema_document_updater.py +0 -0
  19. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/vectorstores/milvus/__init__.py +0 -0
  20. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/vectorstores/milvus/milvus_schema_manager.py +0 -0
  21. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/vectorstores/milvus/schema_milvus.py +0 -0
  22. {crewplus-0.2.65 → crewplus-0.2.67}/crewplus/vectorstores/milvus/vdb_service.py +0 -0
  23. {crewplus-0.2.65 → crewplus-0.2.67}/docs/GeminiChatModel.md +0 -0
  24. {crewplus-0.2.65 → crewplus-0.2.67}/docs/ModelLoadBalancer.md +0 -0
  25. {crewplus-0.2.65 → crewplus-0.2.67}/docs/VDBService.md +0 -0
  26. {crewplus-0.2.65 → crewplus-0.2.67}/docs/index.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: crewplus
3
- Version: 0.2.65
3
+ Version: 0.2.67
4
4
  Summary: Base services for CrewPlus AI applications
5
5
  Author-Email: Tim Liu <tim@opsmateai.com>
6
6
  License: MIT
@@ -0,0 +1,99 @@
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
+ from langfuse.langchain import CallbackHandler as LangfuseCallbackHandler
9
+ from .async_langfuse_handler import AsyncLangfuseCallbackHandler
10
+ from langfuse import get_client
11
+ LANGFUSE_AVAILABLE = True
12
+
13
+ # --- Custom Callback Handlers to capture the run_id ---
14
+
15
+ class RunIdCallbackHandler(LangfuseCallbackHandler):
16
+ """
17
+ A custom synchronous callback handler that captures the Langchain run_id
18
+ and adds it to the Langfuse trace metadata. It also stores the mapping
19
+ between the run_id and the generated trace_id.
20
+ """
21
+ def __init__(self, *args, **kwargs):
22
+ super().__init__(*args, **kwargs)
23
+ self.run_trace_map = {}
24
+ # Use a named logger for better context
25
+ self.logger = logging.getLogger(__name__)
26
+ self.logger.info("RunIdCallbackHandler initialized.")
27
+
28
+ def on_chain_start(
29
+ self,
30
+ serialized: Dict[str, Any],
31
+ inputs: Dict[str, Any],
32
+ run_id: UUID,
33
+ **kwargs: Any,
34
+ ) -> Any:
35
+ self.logger.debug(f"on_chain_start triggered for run_id: {run_id}")
36
+ # First, let the base handler do its work, which includes creating the trace
37
+ run = super().on_chain_start(serialized, inputs, run_id, **kwargs)
38
+ self.logger.debug(f"Base handler's on_chain_start completed. Current trace_id: {self.last_trace_id}")
39
+
40
+ try:
41
+ # The base handler sets `self.last_trace_id` when a trace is created
42
+ if self.last_trace_id:
43
+ self.run_trace_map[str(run_id)] = self.last_trace_id
44
+ self.logger.info(f"Mapping run_id '{run_id}' to trace_id '{self.last_trace_id}'.")
45
+
46
+ # Then, update the created trace with the run_id as metadata
47
+ langfuse_client = get_client()
48
+ langfuse_client.update_current_trace(
49
+ metadata={"langchain_run_id": str(run_id)}
50
+ )
51
+ self.logger.info(f"Successfully updated trace '{self.last_trace_id}' with metadata for run_id '{run_id}'.")
52
+ else:
53
+ self.logger.warning(f"Could not find 'last_trace_id' for run_id '{run_id}'. Metadata will not be updated.")
54
+
55
+ except Exception as e:
56
+ self.logger.error(f"Failed to process run_id '{run_id}' in RunIdCallbackHandler: {e}", exc_info=True)
57
+
58
+ return run
59
+
60
+ class AsyncRunIdCallbackHandler(AsyncLangfuseCallbackHandler):
61
+ """
62
+ A custom asynchronous callback handler that captures the Langchain run_id
63
+ and adds it to the Langfuse trace metadata.
64
+ """
65
+ def __init__(self, *args, **kwargs):
66
+ super().__init__(*args, **kwargs)
67
+ self.run_trace_map = {}
68
+ self.logger = logging.getLogger(__name__)
69
+ self.logger.info("AsyncRunIdCallbackHandler initialized.")
70
+
71
+ async def on_chain_start(
72
+ self,
73
+ serialized: Dict[str, Any],
74
+ inputs: Dict[str, Any],
75
+ run_id: UUID,
76
+ **kwargs: Any,
77
+ ) -> Any:
78
+ self.logger.debug(f"Async on_chain_start triggered for run_id: {run_id}")
79
+ # First, let the base handler do its work
80
+ run = await super().on_chain_start(serialized, inputs, run_id, **kwargs)
81
+ self.logger.debug(f"Async base handler's on_chain_start completed. Current trace_id: {self.last_trace_id}")
82
+
83
+ try:
84
+ if self.last_trace_id:
85
+ self.run_trace_map[str(run_id)] = self.last_trace_id
86
+ self.logger.info(f"Async: Mapping run_id '{run_id}' to trace_id '{self.last_trace_id}'.")
87
+
88
+ langfuse_client = get_client()
89
+ langfuse_client.update_current_trace(
90
+ metadata={"langchain_run_id": str(run_id)}
91
+ )
92
+ self.logger.info(f"Async: Successfully updated trace '{self.last_trace_id}' with metadata for run_id '{run_id}'.")
93
+ else:
94
+ self.logger.warning(f"Async: Could not find 'last_trace_id' for run_id '{run_id}'. Metadata will not be updated.")
95
+
96
+ except Exception as e:
97
+ self.logger.error(f"Async: Failed to process run_id '{run_id}' in AsyncRunIdCallbackHandler: {e}", exc_info=True)
98
+
99
+ return run
@@ -6,7 +6,7 @@ build-backend = "pdm.backend"
6
6
 
7
7
  [project]
8
8
  name = "crewplus"
9
- version = "0.2.65"
9
+ version = "0.2.67"
10
10
  description = "Base services for CrewPlus AI applications"
11
11
  authors = [
12
12
  { name = "Tim Liu", email = "tim@opsmateai.com" },
@@ -1,73 +0,0 @@
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
File without changes
File without changes
File without changes
File without changes