ai-pipeline-core 0.2.6__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.
Files changed (94) hide show
  1. ai_pipeline_core/__init__.py +78 -125
  2. ai_pipeline_core/deployment/__init__.py +34 -0
  3. ai_pipeline_core/deployment/base.py +861 -0
  4. ai_pipeline_core/deployment/contract.py +80 -0
  5. ai_pipeline_core/deployment/deploy.py +561 -0
  6. ai_pipeline_core/deployment/helpers.py +97 -0
  7. ai_pipeline_core/deployment/progress.py +126 -0
  8. ai_pipeline_core/deployment/remote.py +116 -0
  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 +37 -82
  31. ai_pipeline_core/documents/utils.py +4 -12
  32. ai_pipeline_core/exceptions.py +10 -62
  33. ai_pipeline_core/images/__init__.py +309 -0
  34. ai_pipeline_core/images/_processing.py +151 -0
  35. ai_pipeline_core/llm/__init__.py +6 -4
  36. ai_pipeline_core/llm/ai_messages.py +130 -81
  37. ai_pipeline_core/llm/client.py +327 -193
  38. ai_pipeline_core/llm/model_options.py +14 -86
  39. ai_pipeline_core/llm/model_response.py +60 -103
  40. ai_pipeline_core/llm/model_types.py +16 -34
  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/observability/_debug/_config.py +95 -0
  49. ai_pipeline_core/observability/_debug/_content.py +764 -0
  50. ai_pipeline_core/observability/_debug/_processor.py +98 -0
  51. ai_pipeline_core/observability/_debug/_summary.py +312 -0
  52. ai_pipeline_core/observability/_debug/_types.py +75 -0
  53. ai_pipeline_core/observability/_debug/_writer.py +843 -0
  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 -283
  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.1.dist-info/METADATA +807 -0
  73. ai_pipeline_core-0.4.1.dist-info/RECORD +76 -0
  74. {ai_pipeline_core-0.2.6.dist-info → ai_pipeline_core-0.4.1.dist-info}/WHEEL +1 -1
  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 -483
  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/simple_runner/__init__.py +0 -14
  85. ai_pipeline_core/simple_runner/cli.py +0 -254
  86. ai_pipeline_core/simple_runner/simple_runner.py +0 -247
  87. ai_pipeline_core/storage/__init__.py +0 -8
  88. ai_pipeline_core/storage/storage.py +0 -628
  89. ai_pipeline_core/utils/__init__.py +0 -8
  90. ai_pipeline_core/utils/deploy.py +0 -373
  91. ai_pipeline_core/utils/remote_deployment.py +0 -269
  92. ai_pipeline_core-0.2.6.dist-info/METADATA +0 -500
  93. ai_pipeline_core-0.2.6.dist-info/RECORD +0 -41
  94. {ai_pipeline_core-0.2.6.dist-info → ai_pipeline_core-0.4.1.dist-info}/licenses/LICENSE +0 -0
@@ -1,99 +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
- @public
3
+ import os
4
+ import sys
4
5
 
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.
6
+ from prefect.context import refresh_global_settings_context
7
+ from prefect.settings import get_current_settings
8
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.
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
- **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",
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
- """
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()
84
17
 
85
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
86
22
  from .documents import (
23
+ Attachment,
87
24
  Document,
88
- DocumentList,
89
- FlowDocument,
90
- TaskDocument,
91
- TemporaryDocument,
25
+ RunContext,
26
+ TaskDocumentContext,
92
27
  canonical_name_key,
28
+ get_run_context,
93
29
  is_document_sha256,
30
+ reset_run_context,
94
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,
95
42
  )
96
- from .flow import FlowConfig, FlowOptions
97
43
  from .llm import (
98
44
  AIMessages,
99
45
  AIMessageType,
@@ -112,59 +58,66 @@ from .logging import (
112
58
  setup_logging,
113
59
  )
114
60
  from .logging import get_pipeline_logger as get_logger
115
- from .pipeline import pipeline_flow, pipeline_task
116
- from .prefect import disable_run_logger, prefect_test_harness
61
+ from .observability.tracing import TraceInfo, TraceLevel, set_trace_cost, trace
62
+ from .pipeline import FlowOptions, pipeline_flow, pipeline_task
117
63
  from .prompt_manager import PromptManager
118
64
  from .settings import Settings
119
- from .tracing import TraceInfo, TraceLevel, set_trace_cost, trace
65
+ from .testing import disable_run_logger, prefect_test_harness
120
66
 
121
- __version__ = "0.2.6"
67
+ __version__ = "0.4.1"
122
68
 
123
69
  __all__ = [
124
- # Config/Settings
125
- "Settings",
126
- # Logging
127
- "get_logger",
128
- "get_pipeline_logger",
129
- "LoggerMixin",
130
- "LoggingConfig",
131
- "setup_logging",
132
- "StructuredLoggerMixin",
133
- # Documents
70
+ "AIMessageType",
71
+ "AIMessages",
72
+ "Attachment",
73
+ "DeploymentContext",
74
+ "DeploymentResult",
134
75
  "Document",
135
- "DocumentList",
136
- "FlowDocument",
137
- "TaskDocument",
138
- "TemporaryDocument",
139
- "canonical_name_key",
140
- "is_document_sha256",
141
- "sanitize_url",
142
- # Flow/Task
143
- "FlowConfig",
76
+ "DocumentStore",
144
77
  "FlowOptions",
145
- # Pipeline decorators (with tracing)
146
- "pipeline_task",
147
- "pipeline_flow",
148
- # Prefect decorators (clean, no tracing)
149
- "prefect_test_harness",
150
- "disable_run_logger",
151
- # LLM
152
- "llm", # for backward compatibility
153
- "generate",
154
- "generate_structured",
78
+ "ImagePart",
79
+ "ImagePreset",
80
+ "ImageProcessingConfig",
81
+ "ImageProcessingError",
82
+ "LoggerMixin",
83
+ "LoggingConfig",
155
84
  "ModelName",
156
85
  "ModelOptions",
157
86
  "ModelResponse",
87
+ "PipelineDeployment",
88
+ "ProcessedImage",
89
+ "PromptManager",
90
+ "RunContext",
91
+ "Settings",
92
+ "StructuredLoggerMixin",
158
93
  "StructuredModelResponse",
159
- "AIMessages",
160
- "AIMessageType",
161
- # Tracing
162
- "trace",
163
- "TraceLevel",
94
+ "SummaryGenerator",
95
+ "TaskDocumentContext",
164
96
  "TraceInfo",
165
- "set_trace_cost",
166
- # Utils
167
- "PromptManager",
97
+ "TraceLevel",
98
+ "canonical_name_key",
99
+ "create_document_store",
100
+ "disable_run_logger",
168
101
  "generate",
169
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",
170
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
+ ]