lucidicai 2.1.2__py3-none-any.whl → 3.0.0__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.
- lucidicai/__init__.py +32 -390
- lucidicai/api/client.py +260 -92
- lucidicai/api/resources/__init__.py +16 -1
- lucidicai/api/resources/dataset.py +422 -82
- lucidicai/api/resources/event.py +399 -27
- lucidicai/api/resources/experiment.py +108 -0
- lucidicai/api/resources/feature_flag.py +78 -0
- lucidicai/api/resources/prompt.py +84 -0
- lucidicai/api/resources/session.py +545 -38
- lucidicai/client.py +395 -480
- lucidicai/core/config.py +73 -48
- lucidicai/core/errors.py +3 -3
- lucidicai/sdk/bound_decorators.py +321 -0
- lucidicai/sdk/context.py +20 -2
- lucidicai/sdk/decorators.py +283 -74
- lucidicai/sdk/event.py +538 -36
- lucidicai/sdk/event_builder.py +2 -4
- lucidicai/sdk/features/dataset.py +408 -232
- lucidicai/sdk/features/feature_flag.py +344 -3
- lucidicai/sdk/init.py +50 -279
- lucidicai/sdk/session.py +502 -0
- lucidicai/sdk/shutdown_manager.py +103 -46
- lucidicai/session_obj.py +321 -0
- lucidicai/telemetry/context_capture_processor.py +13 -6
- lucidicai/telemetry/extract.py +60 -63
- lucidicai/telemetry/litellm_bridge.py +3 -44
- lucidicai/telemetry/lucidic_exporter.py +143 -131
- lucidicai/telemetry/openai_agents_instrumentor.py +2 -2
- lucidicai/telemetry/openai_patch.py +7 -6
- lucidicai/telemetry/telemetry_manager.py +183 -0
- lucidicai/telemetry/utils/model_pricing.py +21 -30
- lucidicai/telemetry/utils/provider.py +77 -0
- lucidicai/utils/images.py +30 -14
- lucidicai/utils/queue.py +2 -2
- lucidicai/utils/serialization.py +27 -0
- {lucidicai-2.1.2.dist-info → lucidicai-3.0.0.dist-info}/METADATA +1 -1
- {lucidicai-2.1.2.dist-info → lucidicai-3.0.0.dist-info}/RECORD +39 -30
- {lucidicai-2.1.2.dist-info → lucidicai-3.0.0.dist-info}/WHEEL +0 -0
- {lucidicai-2.1.2.dist-info → lucidicai-3.0.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Prompt resource API operations."""
|
|
2
|
+
import logging
|
|
3
|
+
from typing import Any, Dict, Optional
|
|
4
|
+
|
|
5
|
+
from ..client import HttpClient
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger("Lucidic")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PromptResource:
|
|
11
|
+
"""Handle prompt-related API operations."""
|
|
12
|
+
|
|
13
|
+
def __init__(self, http: HttpClient, production: bool = False):
|
|
14
|
+
"""Initialize prompt resource.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
http: HTTP client instance
|
|
18
|
+
production: Whether to suppress errors in production mode
|
|
19
|
+
"""
|
|
20
|
+
self.http = http
|
|
21
|
+
self._production = production
|
|
22
|
+
|
|
23
|
+
def get(
|
|
24
|
+
self,
|
|
25
|
+
prompt_name: str,
|
|
26
|
+
variables: Optional[Dict[str, Any]] = None,
|
|
27
|
+
label: str = "production",
|
|
28
|
+
) -> str:
|
|
29
|
+
"""Get a prompt from the prompt database.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
prompt_name: Name of the prompt.
|
|
33
|
+
variables: Variables to interpolate into the prompt.
|
|
34
|
+
label: Prompt version label (default: "production").
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
The prompt content with variables interpolated.
|
|
38
|
+
"""
|
|
39
|
+
try:
|
|
40
|
+
response = self.http.get(
|
|
41
|
+
"getprompt",
|
|
42
|
+
{"prompt_name": prompt_name, "label": label},
|
|
43
|
+
)
|
|
44
|
+
prompt = response.get("prompt_content", "")
|
|
45
|
+
|
|
46
|
+
# Replace variables
|
|
47
|
+
if variables:
|
|
48
|
+
for key, value in variables.items():
|
|
49
|
+
prompt = prompt.replace(f"{{{key}}}", str(value))
|
|
50
|
+
|
|
51
|
+
return prompt
|
|
52
|
+
except Exception as e:
|
|
53
|
+
if self._production:
|
|
54
|
+
logger.error(f"[PromptResource] Failed to get prompt: {e}")
|
|
55
|
+
return ""
|
|
56
|
+
raise
|
|
57
|
+
|
|
58
|
+
async def aget(
|
|
59
|
+
self,
|
|
60
|
+
prompt_name: str,
|
|
61
|
+
variables: Optional[Dict[str, Any]] = None,
|
|
62
|
+
label: str = "production",
|
|
63
|
+
) -> str:
|
|
64
|
+
"""Get a prompt from the prompt database (asynchronous).
|
|
65
|
+
|
|
66
|
+
See get() for full documentation.
|
|
67
|
+
"""
|
|
68
|
+
try:
|
|
69
|
+
response = await self.http.aget(
|
|
70
|
+
"getprompt",
|
|
71
|
+
{"prompt_name": prompt_name, "label": label},
|
|
72
|
+
)
|
|
73
|
+
prompt = response.get("prompt_content", "")
|
|
74
|
+
|
|
75
|
+
if variables:
|
|
76
|
+
for key, value in variables.items():
|
|
77
|
+
prompt = prompt.replace(f"{{{key}}}", str(value))
|
|
78
|
+
|
|
79
|
+
return prompt
|
|
80
|
+
except Exception as e:
|
|
81
|
+
if self._production:
|
|
82
|
+
logger.error(f"[PromptResource] Failed to get prompt: {e}")
|
|
83
|
+
return ""
|
|
84
|
+
raise
|