ai-pipeline-core 0.1.14__py3-none-any.whl → 0.2.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.
Files changed (31) hide show
  1. ai_pipeline_core/__init__.py +21 -13
  2. ai_pipeline_core/documents/document.py +93 -50
  3. ai_pipeline_core/documents/document_list.py +70 -23
  4. ai_pipeline_core/documents/flow_document.py +2 -6
  5. ai_pipeline_core/documents/task_document.py +0 -4
  6. ai_pipeline_core/documents/temporary_document.py +1 -8
  7. ai_pipeline_core/flow/config.py +174 -5
  8. ai_pipeline_core/llm/__init__.py +1 -1
  9. ai_pipeline_core/llm/ai_messages.py +14 -4
  10. ai_pipeline_core/llm/client.py +116 -59
  11. ai_pipeline_core/llm/model_options.py +2 -5
  12. ai_pipeline_core/llm/model_response.py +17 -16
  13. ai_pipeline_core/llm/model_types.py +0 -4
  14. ai_pipeline_core/logging/__init__.py +0 -2
  15. ai_pipeline_core/logging/logging_config.py +0 -6
  16. ai_pipeline_core/logging/logging_mixin.py +2 -10
  17. ai_pipeline_core/pipeline.py +45 -68
  18. ai_pipeline_core/prefect.py +12 -3
  19. ai_pipeline_core/prompt_manager.py +6 -7
  20. ai_pipeline_core/settings.py +13 -5
  21. ai_pipeline_core/simple_runner/__init__.py +1 -11
  22. ai_pipeline_core/simple_runner/cli.py +13 -12
  23. ai_pipeline_core/simple_runner/simple_runner.py +34 -189
  24. ai_pipeline_core/storage/__init__.py +8 -0
  25. ai_pipeline_core/storage/storage.py +628 -0
  26. ai_pipeline_core/tracing.py +3 -26
  27. {ai_pipeline_core-0.1.14.dist-info → ai_pipeline_core-0.2.0.dist-info}/METADATA +19 -17
  28. ai_pipeline_core-0.2.0.dist-info/RECORD +38 -0
  29. ai_pipeline_core-0.1.14.dist-info/RECORD +0 -36
  30. {ai_pipeline_core-0.1.14.dist-info → ai_pipeline_core-0.2.0.dist-info}/WHEEL +0 -0
  31. {ai_pipeline_core-0.1.14.dist-info → ai_pipeline_core-0.2.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,7 +1,5 @@
1
1
  """Tracing utilities that integrate Laminar (``lmnr``) with our code-base.
2
2
 
3
- @public
4
-
5
3
  This module centralizes:
6
4
  - ``TraceInfo`` - a small helper object for propagating contextual metadata.
7
5
  - ``trace`` decorator - augments a callable with Laminar tracing, automatic
@@ -29,8 +27,6 @@ R = TypeVar("R")
29
27
  TraceLevel = Literal["always", "debug", "off"]
30
28
  """Control level for tracing activation.
31
29
 
32
- @public
33
-
34
30
  Values:
35
31
  - "always": Always trace (default, production mode)
36
32
  - "debug": Only trace when LMNR_DEBUG == "true"
@@ -51,16 +47,12 @@ class TraceInfo(BaseModel):
51
47
 
52
48
  Attributes:
53
49
  session_id: Unique identifier for the current session/conversation.
54
- Falls back to LMNR_SESSION_ID environment variable.
55
50
  user_id: Identifier for the user triggering the operation.
56
- Falls back to LMNR_USER_ID environment variable.
57
51
  metadata: Key-value pairs for additional trace context.
58
52
  Useful for filtering and searching in LMNR dashboard.
59
53
  tags: List of tags for categorizing traces (e.g., ["production", "v2"]).
60
54
 
61
55
  Environment fallbacks:
62
- - LMNR_SESSION_ID: Default session_id if not explicitly set
63
- - LMNR_USER_ID: Default user_id if not explicitly set
64
56
  - LMNR_DEBUG: Controls debug-level tracing when set to "true"
65
57
 
66
58
  Note: These variables are read directly by the tracing layer and are
@@ -102,8 +94,8 @@ class TraceInfo(BaseModel):
102
94
 
103
95
  Returns:
104
96
  Dictionary with keys:
105
- - session_id: From field or LMNR_SESSION_ID env var
106
- - user_id: From field or LMNR_USER_ID env var
97
+ - session_id: From field or environment variable fallback
98
+ - user_id: From field or environment variable fallback
107
99
  - metadata: Dictionary of custom metadata (if set)
108
100
  - tags: List of tags (if set)
109
101
 
@@ -212,15 +204,13 @@ def trace(
212
204
  ) -> Callable[[Callable[P, R]], Callable[P, R]] | Callable[P, R]:
213
205
  """Add Laminar observability tracing to any function.
214
206
 
215
- @public
216
-
217
207
  The trace decorator integrates functions with Laminar (LMNR) for
218
208
  distributed tracing, performance monitoring, and debugging. It
219
209
  automatically handles both sync and async functions, propagates
220
210
  trace context, and provides fine-grained control over what gets traced.
221
211
 
222
212
  USAGE GUIDELINE - Defaults First:
223
- In 90% of cases, use WITHOUT any parameters.
213
+ By default, use WITHOUT any parameters unless instructed otherwise.
224
214
  The defaults are optimized for most use cases.
225
215
 
226
216
  Args:
@@ -306,8 +296,6 @@ def trace(
306
296
 
307
297
  Environment variables:
308
298
  - LMNR_DEBUG: Set to "true" to enable debug-level traces
309
- - LMNR_SESSION_ID: Default session ID if not in TraceInfo
310
- - LMNR_USER_ID: Default user ID if not in TraceInfo
311
299
  - LMNR_PROJECT_API_KEY: Required for trace submission
312
300
 
313
301
  Performance:
@@ -320,11 +308,6 @@ def trace(
320
308
  - Works with both sync and async functions
321
309
  - Preserves function signature and metadata
322
310
  - Thread-safe and async-safe
323
-
324
- See Also:
325
- - TraceInfo: Container for trace metadata
326
- - pipeline_task: Task decorator with built-in tracing
327
- - pipeline_flow: Flow decorator with built-in tracing
328
311
  """
329
312
  if level == "off":
330
313
  if func:
@@ -541,12 +524,6 @@ def set_trace_cost(cost: float | str) -> None:
541
524
  - Multiple calls overwrite the previous cost (not cumulative)
542
525
  - If called outside a traced context (no active span), it has no effect
543
526
  and does not raise an error
544
-
545
- See Also:
546
- - trace: Decorator for adding tracing to functions
547
- - ModelResponse.get_laminar_metadata: Access LLM generation costs
548
- - pipeline_task: Task decorator with built-in tracing and optional trace_cost parameter
549
- - pipeline_flow: Flow decorator with built-in tracing and optional trace_cost parameter
550
527
  """
551
528
  # Parse string format if provided
552
529
  if isinstance(cost, str):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ai-pipeline-core
3
- Version: 0.1.14
3
+ Version: 0.2.0
4
4
  Summary: Core utilities for AI-powered processing pipelines using prefect
5
5
  Project-URL: Homepage, https://github.com/bbarwik/ai-pipeline-core
6
6
  Project-URL: Repository, https://github.com/bbarwik/ai-pipeline-core
@@ -22,6 +22,7 @@ Requires-Dist: httpx>=0.28.1
22
22
  Requires-Dist: jinja2>=3.1.6
23
23
  Requires-Dist: lmnr>=0.7.6
24
24
  Requires-Dist: openai>=1.99.9
25
+ Requires-Dist: prefect-gcp[cloud-storage]>=0.6.10
25
26
  Requires-Dist: prefect>=3.4.13
26
27
  Requires-Dist: pydantic-settings>=2.10.1
27
28
  Requires-Dist: pydantic>=2.11.7
@@ -111,15 +112,13 @@ class AnalysisConfig(FlowConfig):
111
112
  INPUT_DOCUMENT_TYPES = [InputDoc]
112
113
  OUTPUT_DOCUMENT_TYPE = OutputDoc
113
114
 
114
- # Create pipeline flow
115
- @pipeline_flow
115
+ # Create pipeline flow with required config
116
+ @pipeline_flow(config=AnalysisConfig)
116
117
  async def analyze_flow(
117
118
  project_name: str,
118
119
  documents: DocumentList,
119
120
  flow_options: FlowOptions
120
121
  ) -> DocumentList:
121
- config = AnalysisConfig()
122
-
123
122
  # Process documents
124
123
  outputs = []
125
124
  for doc in documents:
@@ -136,7 +135,7 @@ async def analyze_flow(
136
135
  outputs.append(output)
137
136
 
138
137
  # RECOMMENDED: Always validate output
139
- return config.create_and_validate_output(outputs)
138
+ return AnalysisConfig.create_and_validate_output(outputs)
140
139
  ```
141
140
 
142
141
  ### Structured Output
@@ -289,15 +288,15 @@ class ProcessingConfig(FlowConfig):
289
288
  INPUT_DOCUMENT_TYPES = [RawDataDocument]
290
289
  OUTPUT_DOCUMENT_TYPE = ProcessedDocument # Must be different!
291
290
 
292
- # Use in flows for validation
293
- @pipeline_flow
294
- async def process(
295
- config: ProcessingConfig,
296
- documents: DocumentList,
297
- flow_options: FlowOptions
298
- ) -> DocumentList:
299
- # ... processing logic ...
300
- return config.create_and_validate_output(outputs)
291
+ # Use in flows for validation
292
+ @pipeline_flow(config=ProcessingConfig)
293
+ async def process(
294
+ project_name: str,
295
+ documents: DocumentList,
296
+ flow_options: FlowOptions
297
+ ) -> DocumentList:
298
+ # ... processing logic ...
299
+ return ProcessingConfig.create_and_validate_output(outputs)
301
300
  ```
302
301
 
303
302
  ### Pipeline Decorators
@@ -313,7 +312,7 @@ async def process_chunk(data: str) -> str:
313
312
  set_trace_cost(0.05) # Track costs (new in v0.1.14)
314
313
  return result
315
314
 
316
- @pipeline_flow # Full observability and orchestration
315
+ @pipeline_flow(config=MyFlowConfig) # Full observability and orchestration
317
316
  async def main_flow(
318
317
  project_name: str,
319
318
  documents: DocumentList,
@@ -339,6 +338,9 @@ LMNR_DEBUG=true # Enable debug traces
339
338
  # Optional: Orchestration
340
339
  PREFECT_API_URL=http://localhost:4200/api
341
340
  PREFECT_API_KEY=your-prefect-key
341
+
342
+ # Optional: Storage (for Google Cloud Storage)
343
+ GCS_SERVICE_ACCOUNT_FILE=/path/to/service-account.json # GCS auth file
342
344
  ```
343
345
 
344
346
  ### Settings Management
@@ -366,7 +368,7 @@ print(settings.app_name)
366
368
 
367
369
  ### Framework Rules (90% Use Cases)
368
370
 
369
- 1. **Decorators**: Use `@trace`, `@pipeline_task`, `@pipeline_flow` WITHOUT parameters
371
+ 1. **Decorators**: Use `@pipeline_task` WITHOUT parameters, `@pipeline_flow` WITH config
370
372
  2. **Logging**: Use `get_pipeline_logger(__name__)` - NEVER `print()` or `logging` module
371
373
  3. **LLM calls**: Use `AIMessages` or `str`. Wrap Documents in `AIMessages`
372
374
  4. **Options**: Omit `ModelOptions` unless specifically needed (defaults are optimal)
@@ -0,0 +1,38 @@
1
+ ai_pipeline_core/__init__.py,sha256=BBZn5MBlfCWAq1nFwNxsKnvBLfmPB43TnSEH7edde64,5720
2
+ ai_pipeline_core/exceptions.py,sha256=vx-XLTw2fJSPs-vwtXVYtqoQUcOc0JeI7UmHqRqQYWU,1569
3
+ ai_pipeline_core/pipeline.py,sha256=z3zTHAvDkXAsTJEzkpw1gXonNH8hioNAN2wUybGa1j0,28372
4
+ ai_pipeline_core/prefect.py,sha256=91ZgLJHsDsRUW77CpNmkKxYs3RCJuucPM3pjKmNBeDg,2199
5
+ ai_pipeline_core/prompt_manager.py,sha256=p7D0vv_nMmny0rmvxrVyYmXPRjmPJo9qI-pRZe4__Bk,11690
6
+ ai_pipeline_core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ ai_pipeline_core/settings.py,sha256=-a9jVGg77xifj2SagCR9shXfzXUd-2MlrlquEu4htG8,5035
8
+ ai_pipeline_core/tracing.py,sha256=gy5E4OVr3KX-wZ4zWkk3RSER5Ulw8Q_qyp9YoEMCRj4,21963
9
+ ai_pipeline_core/documents/__init__.py,sha256=WHStvGZiSyybOcMTYxSV24U6MA3Am_0_Az5p-DuMFrk,738
10
+ ai_pipeline_core/documents/document.py,sha256=dCbKcgemW8nWHEUJdK5MqSe3XTIo-voi6td4hqWqvSw,62270
11
+ ai_pipeline_core/documents/document_list.py,sha256=iiW8p5p8PhoUgMJnCnPE5GF5xpf6lWJKIzDyYEf6BkM,13738
12
+ ai_pipeline_core/documents/flow_document.py,sha256=g9wlRJRJgy4RsrrZ_P5Qu6kj0FuUFfhfUsRFgtq4NIM,3918
13
+ ai_pipeline_core/documents/mime_type.py,sha256=DkW88K95el5nAmhC00XLS0G3WpDXgs5IRsBWbKiqG3Y,7995
14
+ ai_pipeline_core/documents/task_document.py,sha256=40tFavBLX3FhK9-CRsuOH-3gUZ0zvEkqv9XcMFr8ySk,4077
15
+ ai_pipeline_core/documents/temporary_document.py,sha256=Sam344Mm5AlZTm3_l01YdDWeF26F6pR2tytGRL1doQY,2711
16
+ ai_pipeline_core/documents/utils.py,sha256=ZyJNjFN7ihWno0K7dJZed7twYmmPLA0z40UzFw1A3A8,5465
17
+ ai_pipeline_core/flow/__init__.py,sha256=2BfWYMOPYW5teGzwo-qzpn_bom1lxxry0bPsjVgcsCk,188
18
+ ai_pipeline_core/flow/config.py,sha256=3PCDph2n8dj-txqAvd9Wflbi_6lmfXFR9rUhM-szGSQ,18887
19
+ ai_pipeline_core/flow/options.py,sha256=2rKR2GifhXcyw8avI_oiEDMLC2jm5Qzpw8z56pbxUMo,2285
20
+ ai_pipeline_core/llm/__init__.py,sha256=tSj3Mll8SebivP4J5khdXhM9fnbujnbRh0i5yQRoDJQ,857
21
+ ai_pipeline_core/llm/ai_messages.py,sha256=eSmMwTqGvtBeMoWuukzciQRDIIAfs-cnEXjlaADIYkw,9027
22
+ ai_pipeline_core/llm/client.py,sha256=pxedLnxb9dEu5I9XHTFgXEYWxMv7HOVHhESxIw1hANA,22946
23
+ ai_pipeline_core/llm/model_options.py,sha256=YT_lHazZPa0IbHOuLbWXerRODEDb62sKFM97olSxcAU,7693
24
+ ai_pipeline_core/llm/model_response.py,sha256=xKJPsqFHtOGfqpKlsGzyBHPbqjEjNfP-Ix3lGVdiTjQ,15289
25
+ ai_pipeline_core/llm/model_types.py,sha256=HrQCe_R86yWv5z_83yB-zoMFp6M5Ee9nSeimZmckqtA,2791
26
+ ai_pipeline_core/logging/__init__.py,sha256=Nz6-ghAoENsgNmLD2ma9TW9M0U2_QfxuQ5DDW6Vt6M0,651
27
+ ai_pipeline_core/logging/logging.yml,sha256=YTW48keO_K5bkkb-KXGM7ZuaYKiquLsjsURei8Ql0V4,1353
28
+ ai_pipeline_core/logging/logging_config.py,sha256=pV2x6GgMPXrzPH27sicCSXfw56beio4C2JKCJ3NsXrg,6207
29
+ ai_pipeline_core/logging/logging_mixin.py,sha256=OTye2pbUbG5oYZkI06TNkGCEa4y0ldePz5IAfdmNUPU,8090
30
+ ai_pipeline_core/simple_runner/__init__.py,sha256=9krT-CcDAZ0jB2MjWqFYhaK5qtUDMpB5qWzjRLa4Zhk,322
31
+ ai_pipeline_core/simple_runner/cli.py,sha256=yVyuxLY2RZvdNwmwT5LCe-km2nQJzWTPI0vSWn4_yms,9344
32
+ ai_pipeline_core/simple_runner/simple_runner.py,sha256=f6cIodYkul-Apu1d63T6kR5DZpiaCWpphUcEPp5XjFo,9102
33
+ ai_pipeline_core/storage/__init__.py,sha256=tcIkjJ3zPBLCyetwiJDewBvS2sbRJrDlBh3gEsQm08E,184
34
+ ai_pipeline_core/storage/storage.py,sha256=ClMr419Y-eU2RuOjZYd51dC0stWQk28Vb56PvQaoUwc,20007
35
+ ai_pipeline_core-0.2.0.dist-info/METADATA,sha256=3U4rWNVFQ_Agwpv6NH2e4k0falKwNpDHn-6GncwbcSs,14556
36
+ ai_pipeline_core-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
37
+ ai_pipeline_core-0.2.0.dist-info/licenses/LICENSE,sha256=kKj8mfbdWwkyG3U6n7ztB3bAZlEwShTkAsvaY657i3I,1074
38
+ ai_pipeline_core-0.2.0.dist-info/RECORD,,
@@ -1,36 +0,0 @@
1
- ai_pipeline_core/__init__.py,sha256=jDITXj2wA7lQ46IT9TOvmjg7Ug2aY_QPkuLYfYQEd2E,5484
2
- ai_pipeline_core/exceptions.py,sha256=vx-XLTw2fJSPs-vwtXVYtqoQUcOc0JeI7UmHqRqQYWU,1569
3
- ai_pipeline_core/pipeline.py,sha256=dq-v4IYEaBNt290y545E5JuUahe_k3ffI2_rrGjD-GQ,29384
4
- ai_pipeline_core/prefect.py,sha256=CC8qeIpVqzNq8m6YWNIcRYeDEqkcAFiNjFwcuwwKO0k,2064
5
- ai_pipeline_core/prompt_manager.py,sha256=XZwah5fp3GyZ0e0na_yOs6m4ngCcotysh-K_cU2U978,11572
6
- ai_pipeline_core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- ai_pipeline_core/settings.py,sha256=X8m13zUHWte953l3or45wG8o7ZQ4X-XBe6umk4PlkMQ,4598
8
- ai_pipeline_core/tracing.py,sha256=uXQdP7GIvTghiqyG3XIgES_DbWfkxU0guSqfiazkc0Q,22877
9
- ai_pipeline_core/documents/__init__.py,sha256=WHStvGZiSyybOcMTYxSV24U6MA3Am_0_Az5p-DuMFrk,738
10
- ai_pipeline_core/documents/document.py,sha256=2UfLx4t7k0lV1v2R67mykeEwRAuyAPOCCjvfUOmPDiI,60450
11
- ai_pipeline_core/documents/document_list.py,sha256=SnWzRqCloI8A6e1HIxaKKbaSkPbL2RrqtkjQKY8H6dI,11354
12
- ai_pipeline_core/documents/flow_document.py,sha256=GbOa8mjo6xy5t6EUY7E857S0q5nFBgC1yYQdD7gr-Ls,4043
13
- ai_pipeline_core/documents/mime_type.py,sha256=DkW88K95el5nAmhC00XLS0G3WpDXgs5IRsBWbKiqG3Y,7995
14
- ai_pipeline_core/documents/task_document.py,sha256=h2jAE3k9-2MJ_MjDrH8UtJRXxNuoxACWBfHu2xEHsN4,4226
15
- ai_pipeline_core/documents/temporary_document.py,sha256=1Jpi5ozEes4nudilptnXyXatImZDNAhGL7Jd3cQXM3g,2845
16
- ai_pipeline_core/documents/utils.py,sha256=ZyJNjFN7ihWno0K7dJZed7twYmmPLA0z40UzFw1A3A8,5465
17
- ai_pipeline_core/flow/__init__.py,sha256=2BfWYMOPYW5teGzwo-qzpn_bom1lxxry0bPsjVgcsCk,188
18
- ai_pipeline_core/flow/config.py,sha256=4JVc30tztSW9sYufWLN3hx6qSeR1VX31H1aI9I2jIrA,12114
19
- ai_pipeline_core/flow/options.py,sha256=2rKR2GifhXcyw8avI_oiEDMLC2jm5Qzpw8z56pbxUMo,2285
20
- ai_pipeline_core/llm/__init__.py,sha256=kLMoOj_JQgvGZXZXU-5u9QzLAu2sq5ixMCyEqk2jKKc,857
21
- ai_pipeline_core/llm/ai_messages.py,sha256=udzFwUFfQgJeu1JzpqVuBr0QHdWXvuhfJEEgedSHauY,8383
22
- ai_pipeline_core/llm/client.py,sha256=PZkNaBe1x20ecPTI30PjUjuo26vB76Tam422X3bWhzk,19454
23
- ai_pipeline_core/llm/model_options.py,sha256=_wAUM3d7b_1oBeSpDjcyyx_wZmvBMobGOyF0JEgLTPg,7660
24
- ai_pipeline_core/llm/model_response.py,sha256=TUgEi8CLQ1Bw3vvQeNzX3j9YYjuToNZseaMJ7Uaf4GI,15224
25
- ai_pipeline_core/llm/model_types.py,sha256=JjaJSDY3TTL-ifSLKVNBEV1KJtBIJTr1QwIh9ZnD-is,2895
26
- ai_pipeline_core/logging/__init__.py,sha256=4iXN4jNiOXLfCYGH3wZB0-Zf-SlU-gQ07f1AyP2H5-s,660
27
- ai_pipeline_core/logging/logging.yml,sha256=YTW48keO_K5bkkb-KXGM7ZuaYKiquLsjsURei8Ql0V4,1353
28
- ai_pipeline_core/logging/logging_config.py,sha256=QYI-vz9BqNA02RxoIWPdKhomZpZJkXeFINIuu08O3hY,6242
29
- ai_pipeline_core/logging/logging_mixin.py,sha256=UFd_CfyJ6YP_XVA-CrpAszOr8g1FH8RwRIwiY23kRG0,8131
30
- ai_pipeline_core/simple_runner/__init__.py,sha256=OXKFOu3rRcqXCWwBBxnZ7Vz8KRFF5g-G3eJq-vm3CUY,521
31
- ai_pipeline_core/simple_runner/cli.py,sha256=sbIvv_d401o8h-b5JlcIJQhwzte1sttdmUi2a3As-wY,9357
32
- ai_pipeline_core/simple_runner/simple_runner.py,sha256=1FC1x0WlOUbOiMbiOtkDQdY0d5NswDbx0FSzrNmewCA,15067
33
- ai_pipeline_core-0.1.14.dist-info/METADATA,sha256=vzEIlKku7IF-tY0ho30lP8yMaFBWHOASlLa7CaQRsjw,14351
34
- ai_pipeline_core-0.1.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
35
- ai_pipeline_core-0.1.14.dist-info/licenses/LICENSE,sha256=kKj8mfbdWwkyG3U6n7ztB3bAZlEwShTkAsvaY657i3I,1074
36
- ai_pipeline_core-0.1.14.dist-info/RECORD,,