ai-pipeline-core 0.3.3__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.
- ai_pipeline_core/__init__.py +70 -144
- ai_pipeline_core/deployment/__init__.py +6 -18
- ai_pipeline_core/deployment/base.py +392 -212
- ai_pipeline_core/deployment/contract.py +6 -10
- ai_pipeline_core/{utils → deployment}/deploy.py +50 -69
- ai_pipeline_core/deployment/helpers.py +16 -17
- ai_pipeline_core/{progress.py → deployment/progress.py} +23 -24
- ai_pipeline_core/{utils/remote_deployment.py → deployment/remote.py} +11 -14
- ai_pipeline_core/docs_generator/__init__.py +54 -0
- ai_pipeline_core/docs_generator/__main__.py +5 -0
- ai_pipeline_core/docs_generator/cli.py +196 -0
- ai_pipeline_core/docs_generator/extractor.py +324 -0
- ai_pipeline_core/docs_generator/guide_builder.py +644 -0
- ai_pipeline_core/docs_generator/trimmer.py +35 -0
- ai_pipeline_core/docs_generator/validator.py +114 -0
- ai_pipeline_core/document_store/__init__.py +13 -0
- ai_pipeline_core/document_store/_summary.py +9 -0
- ai_pipeline_core/document_store/_summary_worker.py +170 -0
- ai_pipeline_core/document_store/clickhouse.py +492 -0
- ai_pipeline_core/document_store/factory.py +38 -0
- ai_pipeline_core/document_store/local.py +312 -0
- ai_pipeline_core/document_store/memory.py +85 -0
- ai_pipeline_core/document_store/protocol.py +68 -0
- ai_pipeline_core/documents/__init__.py +12 -14
- ai_pipeline_core/documents/_context_vars.py +85 -0
- ai_pipeline_core/documents/_hashing.py +52 -0
- ai_pipeline_core/documents/attachment.py +85 -0
- ai_pipeline_core/documents/context.py +128 -0
- ai_pipeline_core/documents/document.py +318 -1434
- ai_pipeline_core/documents/mime_type.py +37 -82
- ai_pipeline_core/documents/utils.py +4 -12
- ai_pipeline_core/exceptions.py +10 -62
- ai_pipeline_core/images/__init__.py +32 -85
- ai_pipeline_core/images/_processing.py +5 -11
- ai_pipeline_core/llm/__init__.py +6 -4
- ai_pipeline_core/llm/ai_messages.py +106 -81
- ai_pipeline_core/llm/client.py +267 -158
- ai_pipeline_core/llm/model_options.py +12 -84
- ai_pipeline_core/llm/model_response.py +53 -99
- ai_pipeline_core/llm/model_types.py +8 -23
- ai_pipeline_core/logging/__init__.py +2 -7
- ai_pipeline_core/logging/logging.yml +1 -1
- ai_pipeline_core/logging/logging_config.py +27 -37
- ai_pipeline_core/logging/logging_mixin.py +15 -41
- ai_pipeline_core/observability/__init__.py +32 -0
- ai_pipeline_core/observability/_debug/__init__.py +30 -0
- ai_pipeline_core/observability/_debug/_auto_summary.py +94 -0
- ai_pipeline_core/{debug/config.py → observability/_debug/_config.py} +11 -7
- ai_pipeline_core/{debug/content.py → observability/_debug/_content.py} +134 -75
- ai_pipeline_core/{debug/processor.py → observability/_debug/_processor.py} +16 -17
- ai_pipeline_core/{debug/summary.py → observability/_debug/_summary.py} +113 -37
- ai_pipeline_core/observability/_debug/_types.py +75 -0
- ai_pipeline_core/{debug/writer.py → observability/_debug/_writer.py} +126 -196
- ai_pipeline_core/observability/_document_tracking.py +146 -0
- ai_pipeline_core/observability/_initialization.py +194 -0
- ai_pipeline_core/observability/_logging_bridge.py +57 -0
- ai_pipeline_core/observability/_summary.py +81 -0
- ai_pipeline_core/observability/_tracking/__init__.py +6 -0
- ai_pipeline_core/observability/_tracking/_client.py +178 -0
- ai_pipeline_core/observability/_tracking/_internal.py +28 -0
- ai_pipeline_core/observability/_tracking/_models.py +138 -0
- ai_pipeline_core/observability/_tracking/_processor.py +158 -0
- ai_pipeline_core/observability/_tracking/_service.py +311 -0
- ai_pipeline_core/observability/_tracking/_writer.py +229 -0
- ai_pipeline_core/{tracing.py → observability/tracing.py} +139 -335
- ai_pipeline_core/pipeline/__init__.py +10 -0
- ai_pipeline_core/pipeline/decorators.py +915 -0
- ai_pipeline_core/pipeline/options.py +16 -0
- ai_pipeline_core/prompt_manager.py +16 -102
- ai_pipeline_core/settings.py +26 -31
- ai_pipeline_core/testing.py +9 -0
- ai_pipeline_core-0.4.0.dist-info/METADATA +807 -0
- ai_pipeline_core-0.4.0.dist-info/RECORD +76 -0
- ai_pipeline_core/debug/__init__.py +0 -26
- ai_pipeline_core/documents/document_list.py +0 -420
- ai_pipeline_core/documents/flow_document.py +0 -112
- ai_pipeline_core/documents/task_document.py +0 -117
- ai_pipeline_core/documents/temporary_document.py +0 -74
- ai_pipeline_core/flow/__init__.py +0 -9
- ai_pipeline_core/flow/config.py +0 -494
- ai_pipeline_core/flow/options.py +0 -75
- ai_pipeline_core/pipeline.py +0 -718
- ai_pipeline_core/prefect.py +0 -63
- ai_pipeline_core/prompt_builder/__init__.py +0 -5
- ai_pipeline_core/prompt_builder/documents_prompt.jinja2 +0 -23
- ai_pipeline_core/prompt_builder/global_cache.py +0 -78
- ai_pipeline_core/prompt_builder/new_core_documents_prompt.jinja2 +0 -6
- ai_pipeline_core/prompt_builder/prompt_builder.py +0 -253
- ai_pipeline_core/prompt_builder/system_prompt.jinja2 +0 -41
- ai_pipeline_core/storage/__init__.py +0 -8
- ai_pipeline_core/storage/storage.py +0 -628
- ai_pipeline_core/utils/__init__.py +0 -8
- ai_pipeline_core-0.3.3.dist-info/METADATA +0 -569
- ai_pipeline_core-0.3.3.dist-info/RECORD +0 -57
- {ai_pipeline_core-0.3.3.dist-info → ai_pipeline_core-0.4.0.dist-info}/WHEEL +0 -0
- {ai_pipeline_core-0.3.3.dist-info → ai_pipeline_core-0.4.0.dist-info}/licenses/LICENSE +0 -0
ai_pipeline_core/__init__.py
CHANGED
|
@@ -1,100 +1,36 @@
|
|
|
1
|
-
"""AI Pipeline Core - Production-ready framework for building AI pipelines with LLMs.
|
|
1
|
+
"""AI Pipeline Core - Production-ready framework for building AI pipelines with LLMs."""
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
system designed for production use.
|
|
6
|
+
from prefect.context import refresh_global_settings_context
|
|
7
|
+
from prefect.settings import get_current_settings
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
# Disable Prefect's built-in OpenTelemetry spans to prevent duplicates.
|
|
10
|
+
# All tracing is handled by our @trace decorator and Laminar SDK.
|
|
11
|
+
# Must be set before Prefect is imported by submodules below.
|
|
12
|
+
os.environ.setdefault("PREFECT_CLOUD_ENABLE_ORCHESTRATION_TELEMETRY", "false")
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
from ai_pipeline_core import llm, pipeline_flow, FlowDocument, DocumentList
|
|
14
|
+
# If Prefect was already imported (user imported it before us), refresh its cached settings.
|
|
15
|
+
if "prefect" in sys.modules and get_current_settings().cloud.enable_orchestration_telemetry:
|
|
16
|
+
refresh_global_settings_context()
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
"""
|
|
84
|
-
|
|
85
|
-
from . import llm, progress
|
|
86
|
-
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
|
|
87
22
|
from .documents import (
|
|
23
|
+
Attachment,
|
|
88
24
|
Document,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
TaskDocument,
|
|
92
|
-
TemporaryDocument,
|
|
25
|
+
RunContext,
|
|
26
|
+
TaskDocumentContext,
|
|
93
27
|
canonical_name_key,
|
|
28
|
+
get_run_context,
|
|
94
29
|
is_document_sha256,
|
|
30
|
+
reset_run_context,
|
|
95
31
|
sanitize_url,
|
|
32
|
+
set_run_context,
|
|
96
33
|
)
|
|
97
|
-
from .flow import FlowConfig, FlowOptions
|
|
98
34
|
from .images import (
|
|
99
35
|
ImagePart,
|
|
100
36
|
ImagePreset,
|
|
@@ -122,76 +58,66 @@ from .logging import (
|
|
|
122
58
|
setup_logging,
|
|
123
59
|
)
|
|
124
60
|
from .logging import get_pipeline_logger as get_logger
|
|
125
|
-
from .
|
|
126
|
-
from .
|
|
127
|
-
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
|
|
128
63
|
from .prompt_manager import PromptManager
|
|
129
64
|
from .settings import Settings
|
|
130
|
-
from .
|
|
131
|
-
from .utils.remote_deployment import remote_deployment
|
|
65
|
+
from .testing import disable_run_logger, prefect_test_harness
|
|
132
66
|
|
|
133
|
-
__version__ = "0.
|
|
67
|
+
__version__ = "0.4.0"
|
|
134
68
|
|
|
135
69
|
__all__ = [
|
|
136
|
-
|
|
137
|
-
"
|
|
138
|
-
|
|
139
|
-
"get_logger",
|
|
140
|
-
"get_pipeline_logger",
|
|
141
|
-
"LoggerMixin",
|
|
142
|
-
"LoggingConfig",
|
|
143
|
-
"setup_logging",
|
|
144
|
-
"StructuredLoggerMixin",
|
|
145
|
-
# Documents
|
|
146
|
-
"Document",
|
|
147
|
-
"DocumentList",
|
|
148
|
-
"FlowDocument",
|
|
149
|
-
"TaskDocument",
|
|
150
|
-
"TemporaryDocument",
|
|
151
|
-
"canonical_name_key",
|
|
152
|
-
"is_document_sha256",
|
|
153
|
-
"sanitize_url",
|
|
154
|
-
# Flow/Task
|
|
155
|
-
"FlowConfig",
|
|
156
|
-
"FlowOptions",
|
|
157
|
-
# Pipeline decorators (with tracing)
|
|
158
|
-
"pipeline_task",
|
|
159
|
-
"pipeline_flow",
|
|
160
|
-
# Prefect decorators (clean, no tracing)
|
|
161
|
-
"prefect_test_harness",
|
|
162
|
-
"disable_run_logger",
|
|
163
|
-
# Deployment
|
|
164
|
-
"PipelineDeployment",
|
|
70
|
+
"AIMessageType",
|
|
71
|
+
"AIMessages",
|
|
72
|
+
"Attachment",
|
|
165
73
|
"DeploymentContext",
|
|
166
74
|
"DeploymentResult",
|
|
167
|
-
"
|
|
168
|
-
"
|
|
169
|
-
|
|
170
|
-
"
|
|
171
|
-
"
|
|
172
|
-
"
|
|
75
|
+
"Document",
|
|
76
|
+
"DocumentStore",
|
|
77
|
+
"FlowOptions",
|
|
78
|
+
"ImagePart",
|
|
79
|
+
"ImagePreset",
|
|
80
|
+
"ImageProcessingConfig",
|
|
81
|
+
"ImageProcessingError",
|
|
82
|
+
"LoggerMixin",
|
|
83
|
+
"LoggingConfig",
|
|
173
84
|
"ModelName",
|
|
174
85
|
"ModelOptions",
|
|
175
86
|
"ModelResponse",
|
|
87
|
+
"PipelineDeployment",
|
|
88
|
+
"ProcessedImage",
|
|
89
|
+
"PromptManager",
|
|
90
|
+
"RunContext",
|
|
91
|
+
"Settings",
|
|
92
|
+
"StructuredLoggerMixin",
|
|
176
93
|
"StructuredModelResponse",
|
|
177
|
-
"
|
|
178
|
-
"
|
|
179
|
-
# Tracing
|
|
180
|
-
"trace",
|
|
181
|
-
"TraceLevel",
|
|
94
|
+
"SummaryGenerator",
|
|
95
|
+
"TaskDocumentContext",
|
|
182
96
|
"TraceInfo",
|
|
183
|
-
"
|
|
184
|
-
|
|
185
|
-
"
|
|
186
|
-
"
|
|
187
|
-
|
|
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",
|
|
188
112
|
"process_image",
|
|
189
113
|
"process_image_to_documents",
|
|
190
|
-
"
|
|
191
|
-
"
|
|
192
|
-
"
|
|
193
|
-
"
|
|
194
|
-
"
|
|
195
|
-
|
|
196
|
-
"
|
|
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",
|
|
197
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
|
]
|