ai-pipeline-core 0.1.12__py3-none-any.whl → 0.4.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.
- ai_pipeline_core/__init__.py +83 -119
- ai_pipeline_core/deployment/__init__.py +34 -0
- ai_pipeline_core/deployment/base.py +861 -0
- ai_pipeline_core/deployment/contract.py +80 -0
- ai_pipeline_core/deployment/deploy.py +561 -0
- ai_pipeline_core/deployment/helpers.py +97 -0
- ai_pipeline_core/deployment/progress.py +126 -0
- ai_pipeline_core/deployment/remote.py +116 -0
- 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 +14 -15
- 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 +349 -1062
- ai_pipeline_core/documents/mime_type.py +40 -85
- ai_pipeline_core/documents/utils.py +62 -7
- ai_pipeline_core/exceptions.py +10 -62
- ai_pipeline_core/images/__init__.py +309 -0
- ai_pipeline_core/images/_processing.py +151 -0
- ai_pipeline_core/llm/__init__.py +5 -3
- ai_pipeline_core/llm/ai_messages.py +284 -73
- ai_pipeline_core/llm/client.py +462 -209
- ai_pipeline_core/llm/model_options.py +86 -53
- ai_pipeline_core/llm/model_response.py +187 -241
- ai_pipeline_core/llm/model_types.py +34 -54
- ai_pipeline_core/logging/__init__.py +2 -9
- ai_pipeline_core/logging/logging.yml +1 -1
- ai_pipeline_core/logging/logging_config.py +27 -43
- ai_pipeline_core/logging/logging_mixin.py +17 -51
- 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/observability/_debug/_config.py +95 -0
- ai_pipeline_core/observability/_debug/_content.py +764 -0
- ai_pipeline_core/observability/_debug/_processor.py +98 -0
- ai_pipeline_core/observability/_debug/_summary.py +312 -0
- ai_pipeline_core/observability/_debug/_types.py +75 -0
- ai_pipeline_core/observability/_debug/_writer.py +843 -0
- 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/observability/tracing.py +640 -0
- 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 +26 -105
- ai_pipeline_core/settings.py +41 -32
- ai_pipeline_core/testing.py +9 -0
- ai_pipeline_core-0.4.1.dist-info/METADATA +807 -0
- ai_pipeline_core-0.4.1.dist-info/RECORD +76 -0
- {ai_pipeline_core-0.1.12.dist-info → ai_pipeline_core-0.4.1.dist-info}/WHEEL +1 -1
- ai_pipeline_core/documents/document_list.py +0 -240
- ai_pipeline_core/documents/flow_document.py +0 -128
- ai_pipeline_core/documents/task_document.py +0 -133
- ai_pipeline_core/documents/temporary_document.py +0 -95
- ai_pipeline_core/flow/__init__.py +0 -9
- ai_pipeline_core/flow/config.py +0 -314
- ai_pipeline_core/flow/options.py +0 -75
- ai_pipeline_core/pipeline.py +0 -717
- ai_pipeline_core/prefect.py +0 -54
- ai_pipeline_core/simple_runner/__init__.py +0 -24
- ai_pipeline_core/simple_runner/cli.py +0 -255
- ai_pipeline_core/simple_runner/simple_runner.py +0 -385
- ai_pipeline_core/tracing.py +0 -475
- ai_pipeline_core-0.1.12.dist-info/METADATA +0 -450
- ai_pipeline_core-0.1.12.dist-info/RECORD +0 -36
- {ai_pipeline_core-0.1.12.dist-info → ai_pipeline_core-0.4.1.dist-info}/licenses/LICENSE +0 -0
ai_pipeline_core/__init__.py
CHANGED
|
@@ -1,96 +1,45 @@
|
|
|
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
|
|
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 (90% Use Cases):
|
|
22
|
-
1. Decorators: Use @trace, @pipeline_task, @pipeline_flow WITHOUT parameters
|
|
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: Omit ModelOptions unless specifically needed (defaults are optimal)
|
|
26
|
-
5. Documents: Create with just name and content - skip description
|
|
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**: Distributed tracing via Laminar (LMNR) for debugging
|
|
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, llm, AIMessages
|
|
45
|
-
... )
|
|
46
|
-
>>>
|
|
47
|
-
>>> class OutputDoc(FlowDocument):
|
|
48
|
-
... '''Analysis result document.'''
|
|
49
|
-
>>>
|
|
50
|
-
>>> @pipeline_flow
|
|
51
|
-
>>> async def analyze_flow(
|
|
52
|
-
... project_name: str,
|
|
53
|
-
... documents: DocumentList,
|
|
54
|
-
... flow_options: FlowOptions
|
|
55
|
-
... ) -> DocumentList:
|
|
56
|
-
... # Messages accept AIMessages or str. Wrap documents: AIMessages([doc])
|
|
57
|
-
... response = await llm.generate(
|
|
58
|
-
... model="gpt-5",
|
|
59
|
-
... messages=AIMessages([documents[0]])
|
|
60
|
-
... )
|
|
61
|
-
... result = OutputDoc.create(
|
|
62
|
-
... name="analysis.txt",
|
|
63
|
-
... content=response.content
|
|
64
|
-
... )
|
|
65
|
-
... return DocumentList([result])
|
|
66
|
-
|
|
67
|
-
Environment Variables (when using LiteLLM proxy):
|
|
68
|
-
- OPENAI_BASE_URL: LiteLLM proxy endpoint (e.g., http://localhost:4000)
|
|
69
|
-
- OPENAI_API_KEY: API key for LiteLLM proxy
|
|
70
|
-
|
|
71
|
-
Note: LiteLLM proxy uses OpenAI-compatible API format, hence the OPENAI_*
|
|
72
|
-
variable names are correct regardless of which LLM provider you're using.
|
|
73
|
-
|
|
74
|
-
Optional Environment Variables:
|
|
75
|
-
- PREFECT_API_URL: Prefect server for orchestration
|
|
76
|
-
- PREFECT_API_KEY: Prefect API authentication key
|
|
77
|
-
- LMNR_PROJECT_API_KEY: Laminar (LMNR) API key for tracing
|
|
78
|
-
- LMNR_DEBUG: Set to "true" to enable debug-level traces
|
|
79
|
-
- LMNR_SESSION_ID: Default session ID for traces
|
|
80
|
-
- LMNR_USER_ID: Default user ID for traces
|
|
81
|
-
"""
|
|
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()
|
|
82
17
|
|
|
83
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
|
|
84
22
|
from .documents import (
|
|
23
|
+
Attachment,
|
|
85
24
|
Document,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
TaskDocument,
|
|
89
|
-
TemporaryDocument,
|
|
25
|
+
RunContext,
|
|
26
|
+
TaskDocumentContext,
|
|
90
27
|
canonical_name_key,
|
|
28
|
+
get_run_context,
|
|
29
|
+
is_document_sha256,
|
|
30
|
+
reset_run_context,
|
|
91
31
|
sanitize_url,
|
|
32
|
+
set_run_context,
|
|
33
|
+
)
|
|
34
|
+
from .images import (
|
|
35
|
+
ImagePart,
|
|
36
|
+
ImagePreset,
|
|
37
|
+
ImageProcessingConfig,
|
|
38
|
+
ImageProcessingError,
|
|
39
|
+
ProcessedImage,
|
|
40
|
+
process_image,
|
|
41
|
+
process_image_to_documents,
|
|
92
42
|
)
|
|
93
|
-
from .flow import FlowConfig, FlowOptions
|
|
94
43
|
from .llm import (
|
|
95
44
|
AIMessages,
|
|
96
45
|
AIMessageType,
|
|
@@ -98,6 +47,8 @@ from .llm import (
|
|
|
98
47
|
ModelOptions,
|
|
99
48
|
ModelResponse,
|
|
100
49
|
StructuredModelResponse,
|
|
50
|
+
generate,
|
|
51
|
+
generate_structured,
|
|
101
52
|
)
|
|
102
53
|
from .logging import (
|
|
103
54
|
LoggerMixin,
|
|
@@ -107,53 +58,66 @@ from .logging import (
|
|
|
107
58
|
setup_logging,
|
|
108
59
|
)
|
|
109
60
|
from .logging import get_pipeline_logger as get_logger
|
|
110
|
-
from .
|
|
111
|
-
from .
|
|
61
|
+
from .observability.tracing import TraceInfo, TraceLevel, set_trace_cost, trace
|
|
62
|
+
from .pipeline import FlowOptions, pipeline_flow, pipeline_task
|
|
112
63
|
from .prompt_manager import PromptManager
|
|
113
64
|
from .settings import Settings
|
|
114
|
-
from .
|
|
65
|
+
from .testing import disable_run_logger, prefect_test_harness
|
|
115
66
|
|
|
116
|
-
__version__ = "0.1
|
|
67
|
+
__version__ = "0.4.1"
|
|
117
68
|
|
|
118
69
|
__all__ = [
|
|
119
|
-
|
|
120
|
-
"
|
|
121
|
-
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
"LoggerMixin",
|
|
125
|
-
"LoggingConfig",
|
|
126
|
-
"setup_logging",
|
|
127
|
-
"StructuredLoggerMixin",
|
|
128
|
-
# Documents
|
|
70
|
+
"AIMessageType",
|
|
71
|
+
"AIMessages",
|
|
72
|
+
"Attachment",
|
|
73
|
+
"DeploymentContext",
|
|
74
|
+
"DeploymentResult",
|
|
129
75
|
"Document",
|
|
130
|
-
"
|
|
131
|
-
"FlowDocument",
|
|
132
|
-
"TaskDocument",
|
|
133
|
-
"TemporaryDocument",
|
|
134
|
-
"canonical_name_key",
|
|
135
|
-
"sanitize_url",
|
|
136
|
-
# Flow/Task
|
|
137
|
-
"FlowConfig",
|
|
76
|
+
"DocumentStore",
|
|
138
77
|
"FlowOptions",
|
|
139
|
-
|
|
140
|
-
"
|
|
141
|
-
"
|
|
142
|
-
|
|
143
|
-
"
|
|
144
|
-
"
|
|
145
|
-
# LLM
|
|
146
|
-
"llm",
|
|
78
|
+
"ImagePart",
|
|
79
|
+
"ImagePreset",
|
|
80
|
+
"ImageProcessingConfig",
|
|
81
|
+
"ImageProcessingError",
|
|
82
|
+
"LoggerMixin",
|
|
83
|
+
"LoggingConfig",
|
|
147
84
|
"ModelName",
|
|
148
85
|
"ModelOptions",
|
|
149
86
|
"ModelResponse",
|
|
87
|
+
"PipelineDeployment",
|
|
88
|
+
"ProcessedImage",
|
|
89
|
+
"PromptManager",
|
|
90
|
+
"RunContext",
|
|
91
|
+
"Settings",
|
|
92
|
+
"StructuredLoggerMixin",
|
|
150
93
|
"StructuredModelResponse",
|
|
151
|
-
"
|
|
152
|
-
"
|
|
153
|
-
# Tracing
|
|
154
|
-
"trace",
|
|
155
|
-
"TraceLevel",
|
|
94
|
+
"SummaryGenerator",
|
|
95
|
+
"TaskDocumentContext",
|
|
156
96
|
"TraceInfo",
|
|
157
|
-
|
|
158
|
-
"
|
|
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",
|
|
112
|
+
"process_image",
|
|
113
|
+
"process_image_to_documents",
|
|
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",
|
|
159
123
|
]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Pipeline deployment utilities for unified, type-safe deployments.
|
|
2
|
+
|
|
3
|
+
This module provides the PipelineDeployment base class and related types
|
|
4
|
+
for creating pipeline deployments that work seamlessly across local testing,
|
|
5
|
+
CLI execution, and production Prefect deployments.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .base import DeploymentContext, DeploymentResult, PipelineDeployment
|
|
9
|
+
from .contract import (
|
|
10
|
+
CompletedRun,
|
|
11
|
+
DeploymentResultData,
|
|
12
|
+
FailedRun,
|
|
13
|
+
PendingRun,
|
|
14
|
+
ProgressRun,
|
|
15
|
+
RunResponse,
|
|
16
|
+
)
|
|
17
|
+
from .progress import ProgressContext, flow_context, webhook_worker
|
|
18
|
+
from .progress import update as progress_update
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"CompletedRun",
|
|
22
|
+
"DeploymentContext",
|
|
23
|
+
"DeploymentResult",
|
|
24
|
+
"DeploymentResultData",
|
|
25
|
+
"FailedRun",
|
|
26
|
+
"PendingRun",
|
|
27
|
+
"PipelineDeployment",
|
|
28
|
+
"ProgressContext",
|
|
29
|
+
"ProgressRun",
|
|
30
|
+
"RunResponse",
|
|
31
|
+
"flow_context",
|
|
32
|
+
"progress_update",
|
|
33
|
+
"webhook_worker",
|
|
34
|
+
]
|