lucidicai 3.3.0__py3-none-any.whl → 3.3.1__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 CHANGED
@@ -38,7 +38,7 @@ from .core.errors import (
38
38
  from .integrations.livekit import setup_livekit
39
39
 
40
40
  # Version
41
- __version__ = "3.3.0"
41
+ __version__ = "3.3.1"
42
42
 
43
43
  # All exports
44
44
  __all__ = [
@@ -1,30 +1,57 @@
1
1
  """Prompt resource API operations."""
2
2
  import logging
3
- from typing import Any, Dict, Optional
3
+ import time
4
+ from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING
4
5
 
5
6
  from ..client import HttpClient
6
7
 
8
+ if TYPE_CHECKING:
9
+ from ...core.config import SDKConfig
10
+
7
11
  logger = logging.getLogger("Lucidic")
8
12
 
9
13
 
10
14
  class PromptResource:
11
15
  """Handle prompt-related API operations."""
12
16
 
13
- def __init__(self, http: HttpClient, production: bool = False):
17
+ def __init__(self, http: HttpClient, config: "SDKConfig", production: bool = False):
14
18
  """Initialize prompt resource.
15
19
 
16
20
  Args:
17
21
  http: HTTP client instance
22
+ config: SDK configuration
18
23
  production: Whether to suppress errors in production mode
19
24
  """
20
25
  self.http = http
26
+ self._config = config
21
27
  self._production = production
28
+ self._cache: Dict[Tuple[str, str], Dict[str, Any]] = {}
29
+
30
+ def _is_cache_valid(self, cache_key: Tuple[str, str], cache_ttl: int) -> bool:
31
+ """Check if a cached prompt is still valid.
32
+
33
+ Args:
34
+ cache_key: The (prompt_name, label) tuple
35
+ cache_ttl: Cache TTL in seconds (-1 = indefinite, 0 = no cache)
36
+
37
+ Returns:
38
+ True if cache is valid, False otherwise
39
+ """
40
+ if cache_ttl == 0:
41
+ return False
42
+ if cache_key not in self._cache:
43
+ return False
44
+ if cache_ttl == -1:
45
+ return True
46
+ cached = self._cache[cache_key]
47
+ return (time.time() - cached["timestamp"]) < cache_ttl
22
48
 
23
49
  def get(
24
50
  self,
25
51
  prompt_name: str,
26
52
  variables: Optional[Dict[str, Any]] = None,
27
53
  label: str = "production",
54
+ cache_ttl: int = 0,
28
55
  ) -> str:
29
56
  """Get a prompt from the prompt database.
30
57
 
@@ -32,21 +59,36 @@ class PromptResource:
32
59
  prompt_name: Name of the prompt.
33
60
  variables: Variables to interpolate into the prompt.
34
61
  label: Prompt version label (default: "production").
62
+ cache_ttl: Cache TTL in seconds. 0 = no cache, -1 = cache indefinitely,
63
+ positive value = seconds before refetching.
35
64
 
36
65
  Returns:
37
66
  The prompt content with variables interpolated.
38
67
  """
39
68
  try:
40
- response = self.http.get(
41
- "getprompt",
42
- {"prompt_name": prompt_name, "label": label},
43
- )
44
- prompt = response.get("prompt_content", "")
69
+ cache_key = (prompt_name, label)
70
+
71
+ # Check cache
72
+ if self._is_cache_valid(cache_key, cache_ttl):
73
+ prompt = self._cache[cache_key]["content"]
74
+ else:
75
+ response = self.http.get(
76
+ "getprompt",
77
+ {"prompt_name": prompt_name, "label": label, "agent_id": self._config.agent_id},
78
+ )
79
+ prompt = response.get("prompt_content", "")
80
+
81
+ # Store in cache if caching is enabled
82
+ if cache_ttl != 0:
83
+ self._cache[cache_key] = {
84
+ "content": prompt,
85
+ "timestamp": time.time(),
86
+ }
45
87
 
46
88
  # Replace variables
47
89
  if variables:
48
90
  for key, value in variables.items():
49
- prompt = prompt.replace(f"{{{key}}}", str(value))
91
+ prompt = prompt.replace(f"{{{{{key}}}}}", str(value))
50
92
 
51
93
  return prompt
52
94
  except Exception as e:
@@ -60,21 +102,35 @@ class PromptResource:
60
102
  prompt_name: str,
61
103
  variables: Optional[Dict[str, Any]] = None,
62
104
  label: str = "production",
105
+ cache_ttl: int = 0,
63
106
  ) -> str:
64
107
  """Get a prompt from the prompt database (asynchronous).
65
108
 
66
109
  See get() for full documentation.
67
110
  """
68
111
  try:
69
- response = await self.http.aget(
70
- "getprompt",
71
- {"prompt_name": prompt_name, "label": label},
72
- )
73
- prompt = response.get("prompt_content", "")
112
+ cache_key = (prompt_name, label)
113
+
114
+ # Check cache
115
+ if self._is_cache_valid(cache_key, cache_ttl):
116
+ prompt = self._cache[cache_key]["content"]
117
+ else:
118
+ response = await self.http.aget(
119
+ "getprompt",
120
+ {"prompt_name": prompt_name, "label": label, "agent_id": self._config.agent_id},
121
+ )
122
+ prompt = response.get("prompt_content", "")
123
+
124
+ # Store in cache if caching is enabled
125
+ if cache_ttl != 0:
126
+ self._cache[cache_key] = {
127
+ "content": prompt,
128
+ "timestamp": time.time(),
129
+ }
74
130
 
75
131
  if variables:
76
132
  for key, value in variables.items():
77
- prompt = prompt.replace(f"{{{key}}}", str(value))
133
+ prompt = prompt.replace(f"{{{{{key}}}}}", str(value))
78
134
 
79
135
  return prompt
80
136
  except Exception as e:
lucidicai/client.py CHANGED
@@ -155,7 +155,7 @@ class LucidicAI:
155
155
  "events": EventResource(self._http, self._production),
156
156
  "datasets": DatasetResource(self._http, self._config.agent_id, self._production),
157
157
  "experiments": ExperimentResource(self._http, self._config.agent_id, self._production),
158
- "prompts": PromptResource(self._http, self._production),
158
+ "prompts": PromptResource(self._http, self._config, self._production),
159
159
  "feature_flags": FeatureFlagResource(self._http, self._config.agent_id, self._production),
160
160
  "evals": EvalsResource(self._http, self._production),
161
161
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lucidicai
3
- Version: 3.3.0
3
+ Version: 3.3.1
4
4
  Summary: Lucidic AI Python SDK
5
5
  Author: Andy Liang
6
6
  Author-email: andy@lucidic.ai
@@ -1,6 +1,6 @@
1
- lucidicai/__init__.py,sha256=gdk3Y-cq-RaTbhBcBE77saBwHSbIvqaScU9gNoTi7_g,1284
1
+ lucidicai/__init__.py,sha256=Dur2YTPgHbjFM09QQ36SHOHE0B62uFb5dIUHKo4oy7g,1284
2
2
  lucidicai/action.py,sha256=sPRd1hTIVXDqnvG9ZXWEipUFh0bsXcE0Fm7RVqmVccM,237
3
- lucidicai/client.py,sha256=LC9KPhZgTnt5klntHoyCQWWpRUE-X58lM80uAaWBNiU,15090
3
+ lucidicai/client.py,sha256=BGKP91_Oj5kHQU0osYf1T_BWakL8KIhs0AgUc5X99sU,15104
4
4
  lucidicai/constants.py,sha256=zN8O7TjoRHRlaGa9CZUWppS73rhzKGwaEkF9XMTV0Cg,1160
5
5
  lucidicai/context.py,sha256=ruEXAndSv0gQ-YEXLlC4Fx6NNbaylfp_dZxbpwmLZSA,4622
6
6
  lucidicai/dataset.py,sha256=wu25X02JyWkht_yQabgQpGZFfzbNTxG6tf5k9ol8Amo,4005
@@ -26,7 +26,7 @@ lucidicai/api/resources/evals.py,sha256=_3nLE6dMLht844mWw7kl_hctjv5JIuC6MP06YWUg
26
26
  lucidicai/api/resources/event.py,sha256=GTIU5sIbLNTWAHk4rB120xWTRkhnraz9JNfamEygyNo,14267
27
27
  lucidicai/api/resources/experiment.py,sha256=fOIKJ5d89bHJBVZ3wjbhY_6XF3kLHz9TE3BVPA5pNpA,3563
28
28
  lucidicai/api/resources/feature_flag.py,sha256=ii412DIkZCEAhrXdGydcpQKveqGlFq4NlgdmWQnU83c,2259
29
- lucidicai/api/resources/prompt.py,sha256=tdMVTaLc3DDRbd_R8Xd5mkvpdwQONfr8OwkJRTE0atE,2495
29
+ lucidicai/api/resources/prompt.py,sha256=5pIV3vTfOQkovQpINohDVseY678E04CWz2E5V4NA-i8,4625
30
30
  lucidicai/api/resources/session.py,sha256=jW_bftHdunhLHl_3-k0nqB5FrtLhlFeCF0tMFE82nNw,20761
31
31
  lucidicai/core/__init__.py,sha256=b0YQkd8190Y_GgwUcmf0tOiSLARd7L4kq4jwfhhGAyI,39
32
32
  lucidicai/core/config.py,sha256=q4h-yR35Ay_3znL7vavri6ScfeM69RjHShNNzjoQthc,10194
@@ -93,7 +93,7 @@ lucidicai/utils/images.py,sha256=z8mlIKgFfrIbuk-l4L2rB62uw_uPO79sHPXPY7eLu2A,128
93
93
  lucidicai/utils/logger.py,sha256=R3B3gSee64F6UVHUrShihBq_O7W7bgfrBiVDXTO3Isg,4777
94
94
  lucidicai/utils/queue.py,sha256=8DQwnGw7pINEJ0dNSkB0PhdPW-iBQQ-YZg23poe4umE,17323
95
95
  lucidicai/utils/serialization.py,sha256=KdOREZd7XBxFBAZ86DePMfYPzSVyKr4RcgUa82aFxrs,820
96
- lucidicai-3.3.0.dist-info/METADATA,sha256=p8D3cXfEzfEC4HnYYz68keBQwzNDOkSqifh8H13m1t4,902
97
- lucidicai-3.3.0.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
98
- lucidicai-3.3.0.dist-info/top_level.txt,sha256=vSSdM3lclF4I5tyVC0xxUk8eIRnnYXMe1hW-eO91HUo,10
99
- lucidicai-3.3.0.dist-info/RECORD,,
96
+ lucidicai-3.3.1.dist-info/METADATA,sha256=-VsGzxsuN4ux1cLJN6jcbEO2cOv2G756BdsAWY8uiio,902
97
+ lucidicai-3.3.1.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
98
+ lucidicai-3.3.1.dist-info/top_level.txt,sha256=vSSdM3lclF4I5tyVC0xxUk8eIRnnYXMe1hW-eO91HUo,10
99
+ lucidicai-3.3.1.dist-info/RECORD,,