ai-pipeline-core 0.3.4__py3-none-any.whl → 0.4.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 (96) hide show
  1. ai_pipeline_core/__init__.py +64 -158
  2. ai_pipeline_core/deployment/__init__.py +6 -18
  3. ai_pipeline_core/deployment/base.py +392 -212
  4. ai_pipeline_core/deployment/contract.py +6 -10
  5. ai_pipeline_core/{utils → deployment}/deploy.py +50 -69
  6. ai_pipeline_core/deployment/helpers.py +16 -17
  7. ai_pipeline_core/{progress.py → deployment/progress.py} +23 -24
  8. ai_pipeline_core/{utils/remote_deployment.py → deployment/remote.py} +11 -14
  9. ai_pipeline_core/docs_generator/__init__.py +54 -0
  10. ai_pipeline_core/docs_generator/__main__.py +5 -0
  11. ai_pipeline_core/docs_generator/cli.py +196 -0
  12. ai_pipeline_core/docs_generator/extractor.py +324 -0
  13. ai_pipeline_core/docs_generator/guide_builder.py +644 -0
  14. ai_pipeline_core/docs_generator/trimmer.py +35 -0
  15. ai_pipeline_core/docs_generator/validator.py +114 -0
  16. ai_pipeline_core/document_store/__init__.py +13 -0
  17. ai_pipeline_core/document_store/_summary.py +9 -0
  18. ai_pipeline_core/document_store/_summary_worker.py +170 -0
  19. ai_pipeline_core/document_store/clickhouse.py +492 -0
  20. ai_pipeline_core/document_store/factory.py +38 -0
  21. ai_pipeline_core/document_store/local.py +312 -0
  22. ai_pipeline_core/document_store/memory.py +85 -0
  23. ai_pipeline_core/document_store/protocol.py +68 -0
  24. ai_pipeline_core/documents/__init__.py +12 -14
  25. ai_pipeline_core/documents/_context_vars.py +85 -0
  26. ai_pipeline_core/documents/_hashing.py +52 -0
  27. ai_pipeline_core/documents/attachment.py +85 -0
  28. ai_pipeline_core/documents/context.py +128 -0
  29. ai_pipeline_core/documents/document.py +318 -1434
  30. ai_pipeline_core/documents/mime_type.py +11 -84
  31. ai_pipeline_core/documents/utils.py +4 -12
  32. ai_pipeline_core/exceptions.py +10 -62
  33. ai_pipeline_core/images/__init__.py +32 -85
  34. ai_pipeline_core/images/_processing.py +5 -11
  35. ai_pipeline_core/llm/__init__.py +6 -4
  36. ai_pipeline_core/llm/ai_messages.py +102 -90
  37. ai_pipeline_core/llm/client.py +229 -183
  38. ai_pipeline_core/llm/model_options.py +12 -84
  39. ai_pipeline_core/llm/model_response.py +53 -99
  40. ai_pipeline_core/llm/model_types.py +8 -23
  41. ai_pipeline_core/logging/__init__.py +2 -7
  42. ai_pipeline_core/logging/logging.yml +1 -1
  43. ai_pipeline_core/logging/logging_config.py +27 -37
  44. ai_pipeline_core/logging/logging_mixin.py +15 -41
  45. ai_pipeline_core/observability/__init__.py +32 -0
  46. ai_pipeline_core/observability/_debug/__init__.py +30 -0
  47. ai_pipeline_core/observability/_debug/_auto_summary.py +94 -0
  48. ai_pipeline_core/{debug/config.py → observability/_debug/_config.py} +11 -7
  49. ai_pipeline_core/{debug/content.py → observability/_debug/_content.py} +133 -75
  50. ai_pipeline_core/{debug/processor.py → observability/_debug/_processor.py} +16 -17
  51. ai_pipeline_core/{debug/summary.py → observability/_debug/_summary.py} +113 -37
  52. ai_pipeline_core/observability/_debug/_types.py +75 -0
  53. ai_pipeline_core/{debug/writer.py → observability/_debug/_writer.py} +126 -196
  54. ai_pipeline_core/observability/_document_tracking.py +146 -0
  55. ai_pipeline_core/observability/_initialization.py +194 -0
  56. ai_pipeline_core/observability/_logging_bridge.py +57 -0
  57. ai_pipeline_core/observability/_summary.py +81 -0
  58. ai_pipeline_core/observability/_tracking/__init__.py +6 -0
  59. ai_pipeline_core/observability/_tracking/_client.py +178 -0
  60. ai_pipeline_core/observability/_tracking/_internal.py +28 -0
  61. ai_pipeline_core/observability/_tracking/_models.py +138 -0
  62. ai_pipeline_core/observability/_tracking/_processor.py +158 -0
  63. ai_pipeline_core/observability/_tracking/_service.py +311 -0
  64. ai_pipeline_core/observability/_tracking/_writer.py +229 -0
  65. ai_pipeline_core/{tracing.py → observability/tracing.py} +139 -335
  66. ai_pipeline_core/pipeline/__init__.py +10 -0
  67. ai_pipeline_core/pipeline/decorators.py +915 -0
  68. ai_pipeline_core/pipeline/options.py +16 -0
  69. ai_pipeline_core/prompt_manager.py +16 -102
  70. ai_pipeline_core/settings.py +26 -31
  71. ai_pipeline_core/testing.py +9 -0
  72. ai_pipeline_core-0.4.0.dist-info/METADATA +807 -0
  73. ai_pipeline_core-0.4.0.dist-info/RECORD +76 -0
  74. ai_pipeline_core/debug/__init__.py +0 -26
  75. ai_pipeline_core/documents/document_list.py +0 -420
  76. ai_pipeline_core/documents/flow_document.py +0 -112
  77. ai_pipeline_core/documents/task_document.py +0 -117
  78. ai_pipeline_core/documents/temporary_document.py +0 -74
  79. ai_pipeline_core/flow/__init__.py +0 -9
  80. ai_pipeline_core/flow/config.py +0 -494
  81. ai_pipeline_core/flow/options.py +0 -75
  82. ai_pipeline_core/pipeline.py +0 -718
  83. ai_pipeline_core/prefect.py +0 -63
  84. ai_pipeline_core/prompt_builder/__init__.py +0 -5
  85. ai_pipeline_core/prompt_builder/documents_prompt.jinja2 +0 -23
  86. ai_pipeline_core/prompt_builder/global_cache.py +0 -78
  87. ai_pipeline_core/prompt_builder/new_core_documents_prompt.jinja2 +0 -6
  88. ai_pipeline_core/prompt_builder/prompt_builder.py +0 -253
  89. ai_pipeline_core/prompt_builder/system_prompt.jinja2 +0 -41
  90. ai_pipeline_core/storage/__init__.py +0 -8
  91. ai_pipeline_core/storage/storage.py +0 -628
  92. ai_pipeline_core/utils/__init__.py +0 -8
  93. ai_pipeline_core-0.3.4.dist-info/METADATA +0 -569
  94. ai_pipeline_core-0.3.4.dist-info/RECORD +0 -57
  95. {ai_pipeline_core-0.3.4.dist-info → ai_pipeline_core-0.4.0.dist-info}/WHEEL +0 -0
  96. {ai_pipeline_core-0.3.4.dist-info → ai_pipeline_core-0.4.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,120 +1,36 @@
1
- """AI Pipeline Core - Production-ready framework for building AI pipelines with LLMs.
2
-
3
- @public
4
-
5
- AI Pipeline Core is a high-performance async framework for building type-safe AI pipelines.
6
- It combines document processing, LLM integration, and workflow orchestration into a unified
7
- system designed for production use.
8
-
9
- The framework enforces best practices through strong typing (Pydantic), automatic retries,
10
- and cost tracking. All I/O operations are async for maximum throughput.
11
-
12
- **CRITICAL IMPORT RULE**:
13
- Always import from the top-level package:
14
- **CORRECT**:
15
- from ai_pipeline_core import llm, pipeline_flow, FlowDocument, DocumentList
16
-
17
- **WRONG** - Never import from submodules:
18
- from ai_pipeline_core.llm import generate # NO!
19
- from ai_pipeline_core.documents import FlowDocument # NO!
20
-
21
- FRAMEWORK RULES (Use by default, unless instructed otherwise):
22
- 1. Decorators: Use @pipeline_task WITHOUT parameters, @pipeline_flow WITH config
23
- 2. Logging: Use get_pipeline_logger(__name__) - NEVER print() or logging module
24
- 3. LLM calls: Use AIMessages or str. Wrap Documents in AIMessages; do not call .text yourself
25
- 4. Options: DO NOT use options parameter - omit it entirely (defaults are optimal)
26
- 5. Documents: Create with just name and content - skip description unless needed
27
- 6. FlowConfig: OUTPUT_DOCUMENT_TYPE must differ from all INPUT_DOCUMENT_TYPES
28
- 7. Initialization: PromptManager and logger at module scope, not in functions
29
- 8. DocumentList: Use default constructor - no validation flags needed
30
- 9. setup_logging(): Only in application main(), never at import time
31
-
32
- Messages parameter type: AIMessages or str. Do not pass Document or DocumentList directly.
33
-
34
- Core Capabilities:
35
- - **Document Processing**: Type-safe handling of text, JSON, YAML, PDFs, and images
36
- - **LLM Integration**: Unified interface to any model via LiteLLM with caching
37
- - **Structured Output**: Type-safe generation with Pydantic model validation
38
- - **Workflow Orchestration**: Prefect-based flows and tasks with retries
39
- - **Observability**: Built-in monitoring and debugging capabilities
40
- - **Local Development**: Simple runner for testing without infrastructure
41
-
42
- Quick Start:
43
- >>> from ai_pipeline_core import (
44
- ... pipeline_flow, FlowDocument, DocumentList, FlowOptions, FlowConfig, llm, AIMessages
45
- ... )
46
- >>>
47
- >>> class OutputDoc(FlowDocument):
48
- ... '''Analysis result document.'''
49
- >>>
50
- >>> class MyFlowConfig(FlowConfig):
51
- ... INPUT_DOCUMENT_TYPES = []
52
- ... OUTPUT_DOCUMENT_TYPE = OutputDoc
53
- >>>
54
- >>> @pipeline_flow(config=MyFlowConfig)
55
- >>> async def analyze_flow(
56
- ... project_name: str,
57
- ... documents: DocumentList,
58
- ... flow_options: FlowOptions
59
- ... ) -> DocumentList:
60
- ... # Messages accept AIMessages or str. Wrap documents: AIMessages([doc])
61
- ... response = await llm.generate(
62
- ... "gpt-5.1",
63
- ... messages=AIMessages([documents[0]])
64
- ... )
65
- ... result = OutputDoc.create(
66
- ... name="analysis.txt",
67
- ... content=response.content
68
- ... )
69
- ... return DocumentList([result])
70
-
71
- Environment Variables (when using LiteLLM proxy):
72
- - OPENAI_BASE_URL: LiteLLM proxy endpoint (e.g., http://localhost:4000)
73
- - OPENAI_API_KEY: API key for LiteLLM proxy
74
-
75
- Note: LiteLLM proxy uses OpenAI-compatible API format, hence the OPENAI_*
76
- variable names are correct regardless of which LLM provider you're using.
77
-
78
- Optional Environment Variables:
79
- - PREFECT_API_URL: Prefect server for orchestration
80
- - PREFECT_API_KEY: Prefect API authentication key
81
- - LMNR_PROJECT_API_KEY: Laminar (LMNR) API key for tracing
82
- - LMNR_DEBUG: Set to "true" to enable debug-level traces
83
- """
1
+ """AI Pipeline Core - Production-ready framework for building AI pipelines with LLMs."""
84
2
 
85
3
  import os
86
4
  import sys
87
5
 
6
+ from prefect.context import refresh_global_settings_context
7
+ from prefect.settings import get_current_settings
8
+
88
9
  # Disable Prefect's built-in OpenTelemetry spans to prevent duplicates.
89
10
  # All tracing is handled by our @trace decorator and Laminar SDK.
90
11
  # Must be set before Prefect is imported by submodules below.
91
12
  os.environ.setdefault("PREFECT_CLOUD_ENABLE_ORCHESTRATION_TELEMETRY", "false")
92
13
 
93
14
  # If Prefect was already imported (user imported it before us), refresh its cached settings.
94
- if "prefect" in sys.modules:
95
- try:
96
- from prefect.settings import get_current_settings # noqa: PLC0415
97
-
98
- if get_current_settings().cloud.enable_orchestration_telemetry:
99
- from prefect.context import refresh_global_settings_context # noqa: PLC0415
100
-
101
- refresh_global_settings_context()
102
- except (ImportError, AttributeError):
103
- pass
15
+ if "prefect" in sys.modules and get_current_settings().cloud.enable_orchestration_telemetry:
16
+ refresh_global_settings_context()
104
17
 
105
- from . import llm, progress
106
- from .deployment import DeploymentContext, DeploymentResult, PipelineDeployment
18
+ from . import llm
19
+ from .deployment import DeploymentContext, DeploymentResult, PipelineDeployment, progress
20
+ from .deployment.remote import remote_deployment
21
+ from .document_store import DocumentStore, SummaryGenerator, create_document_store, get_document_store, set_document_store
107
22
  from .documents import (
23
+ Attachment,
108
24
  Document,
109
- DocumentList,
110
- FlowDocument,
111
- TaskDocument,
112
- TemporaryDocument,
25
+ RunContext,
26
+ TaskDocumentContext,
113
27
  canonical_name_key,
28
+ get_run_context,
114
29
  is_document_sha256,
30
+ reset_run_context,
115
31
  sanitize_url,
32
+ set_run_context,
116
33
  )
117
- from .flow import FlowConfig, FlowOptions
118
34
  from .images import (
119
35
  ImagePart,
120
36
  ImagePreset,
@@ -142,76 +58,66 @@ from .logging import (
142
58
  setup_logging,
143
59
  )
144
60
  from .logging import get_pipeline_logger as get_logger
145
- from .pipeline import pipeline_flow, pipeline_task
146
- from .prefect import disable_run_logger, prefect_test_harness
147
- from .prompt_builder import EnvironmentVariable, PromptBuilder
61
+ from .observability.tracing import TraceInfo, TraceLevel, set_trace_cost, trace
62
+ from .pipeline import FlowOptions, pipeline_flow, pipeline_task
148
63
  from .prompt_manager import PromptManager
149
64
  from .settings import Settings
150
- from .tracing import TraceInfo, TraceLevel, set_trace_cost, trace
151
- from .utils.remote_deployment import remote_deployment
65
+ from .testing import disable_run_logger, prefect_test_harness
152
66
 
153
- __version__ = "0.3.4"
67
+ __version__ = "0.4.0"
154
68
 
155
69
  __all__ = [
156
- # Config/Settings
157
- "Settings",
158
- # Logging
159
- "get_logger",
160
- "get_pipeline_logger",
161
- "LoggerMixin",
162
- "LoggingConfig",
163
- "setup_logging",
164
- "StructuredLoggerMixin",
165
- # Documents
166
- "Document",
167
- "DocumentList",
168
- "FlowDocument",
169
- "TaskDocument",
170
- "TemporaryDocument",
171
- "canonical_name_key",
172
- "is_document_sha256",
173
- "sanitize_url",
174
- # Flow/Task
175
- "FlowConfig",
176
- "FlowOptions",
177
- # Pipeline decorators (with tracing)
178
- "pipeline_task",
179
- "pipeline_flow",
180
- # Prefect decorators (clean, no tracing)
181
- "prefect_test_harness",
182
- "disable_run_logger",
183
- # Deployment
184
- "PipelineDeployment",
70
+ "AIMessageType",
71
+ "AIMessages",
72
+ "Attachment",
185
73
  "DeploymentContext",
186
74
  "DeploymentResult",
187
- "remote_deployment",
188
- "progress",
189
- # LLM
190
- "llm", # for backward compatibility
191
- "generate",
192
- "generate_structured",
75
+ "Document",
76
+ "DocumentStore",
77
+ "FlowOptions",
78
+ "ImagePart",
79
+ "ImagePreset",
80
+ "ImageProcessingConfig",
81
+ "ImageProcessingError",
82
+ "LoggerMixin",
83
+ "LoggingConfig",
193
84
  "ModelName",
194
85
  "ModelOptions",
195
86
  "ModelResponse",
87
+ "PipelineDeployment",
88
+ "ProcessedImage",
89
+ "PromptManager",
90
+ "RunContext",
91
+ "Settings",
92
+ "StructuredLoggerMixin",
196
93
  "StructuredModelResponse",
197
- "AIMessages",
198
- "AIMessageType",
199
- # Tracing
200
- "trace",
201
- "TraceLevel",
94
+ "SummaryGenerator",
95
+ "TaskDocumentContext",
202
96
  "TraceInfo",
203
- "set_trace_cost",
204
- # Prompt Builder
205
- "PromptBuilder",
206
- "EnvironmentVariable",
207
- # Images
97
+ "TraceLevel",
98
+ "canonical_name_key",
99
+ "create_document_store",
100
+ "disable_run_logger",
101
+ "generate",
102
+ "generate_structured",
103
+ "get_document_store",
104
+ "get_logger",
105
+ "get_pipeline_logger",
106
+ "get_run_context",
107
+ "is_document_sha256",
108
+ "llm",
109
+ "pipeline_flow",
110
+ "pipeline_task",
111
+ "prefect_test_harness",
208
112
  "process_image",
209
113
  "process_image_to_documents",
210
- "ImagePreset",
211
- "ImageProcessingConfig",
212
- "ProcessedImage",
213
- "ImagePart",
214
- "ImageProcessingError",
215
- # Utils
216
- "PromptManager",
114
+ "progress",
115
+ "remote_deployment",
116
+ "reset_run_context",
117
+ "sanitize_url",
118
+ "set_document_store",
119
+ "set_run_context",
120
+ "set_trace_cost",
121
+ "setup_logging",
122
+ "trace",
217
123
  ]
@@ -1,26 +1,8 @@
1
1
  """Pipeline deployment utilities for unified, type-safe deployments.
2
2
 
3
- @public
4
-
5
3
  This module provides the PipelineDeployment base class and related types
6
4
  for creating pipeline deployments that work seamlessly across local testing,
7
5
  CLI execution, and production Prefect deployments.
8
-
9
- Example:
10
- >>> from ai_pipeline_core import PipelineDeployment, DeploymentContext, DeploymentResult
11
- >>>
12
- >>> class MyResult(DeploymentResult):
13
- ... report: str
14
- >>>
15
- >>> class MyPipeline(PipelineDeployment[MyOptions, MyResult]):
16
- ... flows = [step_01, step_02]
17
- ...
18
- ... @staticmethod
19
- ... def build_result(project_name, documents, options):
20
- ... return MyResult(success=True, report="Done")
21
- >>>
22
- >>> pipeline = MyPipeline()
23
- >>> result = pipeline.run_local("test", documents, options)
24
6
  """
25
7
 
26
8
  from .base import DeploymentContext, DeploymentResult, PipelineDeployment
@@ -32,6 +14,8 @@ from .contract import (
32
14
  ProgressRun,
33
15
  RunResponse,
34
16
  )
17
+ from .progress import ProgressContext, flow_context, webhook_worker
18
+ from .progress import update as progress_update
35
19
 
36
20
  __all__ = [
37
21
  "CompletedRun",
@@ -41,6 +25,10 @@ __all__ = [
41
25
  "FailedRun",
42
26
  "PendingRun",
43
27
  "PipelineDeployment",
28
+ "ProgressContext",
44
29
  "ProgressRun",
45
30
  "RunResponse",
31
+ "flow_context",
32
+ "progress_update",
33
+ "webhook_worker",
46
34
  ]