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.
Files changed (90) hide show
  1. ai_pipeline_core/__init__.py +83 -119
  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 +14 -15
  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 +349 -1062
  30. ai_pipeline_core/documents/mime_type.py +40 -85
  31. ai_pipeline_core/documents/utils.py +62 -7
  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 +5 -3
  36. ai_pipeline_core/llm/ai_messages.py +284 -73
  37. ai_pipeline_core/llm/client.py +462 -209
  38. ai_pipeline_core/llm/model_options.py +86 -53
  39. ai_pipeline_core/llm/model_response.py +187 -241
  40. ai_pipeline_core/llm/model_types.py +34 -54
  41. ai_pipeline_core/logging/__init__.py +2 -9
  42. ai_pipeline_core/logging/logging.yml +1 -1
  43. ai_pipeline_core/logging/logging_config.py +27 -43
  44. ai_pipeline_core/logging/logging_mixin.py +17 -51
  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/observability/tracing.py +640 -0
  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 +26 -105
  70. ai_pipeline_core/settings.py +41 -32
  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.1.12.dist-info → ai_pipeline_core-0.4.1.dist-info}/WHEEL +1 -1
  75. ai_pipeline_core/documents/document_list.py +0 -240
  76. ai_pipeline_core/documents/flow_document.py +0 -128
  77. ai_pipeline_core/documents/task_document.py +0 -133
  78. ai_pipeline_core/documents/temporary_document.py +0 -95
  79. ai_pipeline_core/flow/__init__.py +0 -9
  80. ai_pipeline_core/flow/config.py +0 -314
  81. ai_pipeline_core/flow/options.py +0 -75
  82. ai_pipeline_core/pipeline.py +0 -717
  83. ai_pipeline_core/prefect.py +0 -54
  84. ai_pipeline_core/simple_runner/__init__.py +0 -24
  85. ai_pipeline_core/simple_runner/cli.py +0 -255
  86. ai_pipeline_core/simple_runner/simple_runner.py +0 -385
  87. ai_pipeline_core/tracing.py +0 -475
  88. ai_pipeline_core-0.1.12.dist-info/METADATA +0 -450
  89. ai_pipeline_core-0.1.12.dist-info/RECORD +0 -36
  90. {ai_pipeline_core-0.1.12.dist-info → ai_pipeline_core-0.4.1.dist-info}/licenses/LICENSE +0 -0
@@ -1,7 +1,5 @@
1
1
  """Configuration options for LLM generation.
2
2
 
3
- @public
4
-
5
3
  Provides the ModelOptions class for configuring model behavior,
6
4
  retry logic, and advanced features like web search and reasoning.
7
5
  """
@@ -12,9 +10,7 @@ from pydantic import BaseModel
12
10
 
13
11
 
14
12
  class ModelOptions(BaseModel):
15
- """Configuration options for LLM generation requests.
16
-
17
- @public
13
+ r"""Configuration options for LLM generation requests.
18
14
 
19
15
  ModelOptions encapsulates all configuration parameters for model
20
16
  generation, including model behavior settings, retry logic, and
@@ -45,9 +41,13 @@ class ModelOptions(BaseModel):
45
41
 
46
42
  retries: Number of retry attempts on failure (default: 3).
47
43
 
48
- retry_delay_seconds: Seconds to wait between retries (default: 10).
44
+ retry_delay_seconds: Seconds to wait between retries (default: 20).
45
+
46
+ timeout: Maximum seconds to wait for response (default: 600).
49
47
 
50
- timeout: Maximum seconds to wait for response (default: 300).
48
+ cache_ttl: Cache TTL for context messages (default: "300s").
49
+ String format like "60s", "5m", or None to disable caching.
50
+ Applied to the last context message for efficient token reuse.
51
51
 
52
52
  service_tier: API tier selection for performance/cost trade-offs.
53
53
  "auto": Let API choose
@@ -62,40 +62,48 @@ class ModelOptions(BaseModel):
62
62
  max_completion_tokens: Maximum tokens to generate.
63
63
  None uses model default.
64
64
 
65
+ stop: Stop sequences that halt generation when encountered.
66
+ Can be a single string or list of strings.
67
+ When the model generates any of these sequences, it stops immediately.
68
+ Maximum of 4 stop sequences supported by most providers.
69
+
65
70
  response_format: Pydantic model class for structured output.
66
71
  Pass a Pydantic model; the client converts it to JSON Schema.
67
- Set automatically by generate_structured(). Provider support varies.
68
-
69
- Example:
70
- >>> # Basic configuration
71
- >>> options = ModelOptions(
72
- ... temperature=0.7,
73
- ... max_completion_tokens=1000
74
- ... )
75
- >>>
76
- >>> # With system prompt
77
- >>> options = ModelOptions(
78
- ... system_prompt="You are a helpful coding assistant",
79
- ... temperature=0.3 # Lower for code generation
80
- ... )
81
- >>>
82
- >>> # For search-enabled models
83
- >>> options = ModelOptions(
84
- ... search_context_size="high", # Get more search results
85
- ... max_completion_tokens=2000
86
- ... )
87
- >>>
88
- >>> # For reasoning models
89
- >>> options = ModelOptions(
90
- ... reasoning_effort="high", # Deep reasoning
91
- ... timeout=600 # More time for complex reasoning
92
- ... )
93
-
94
- Note:
95
- - Not all options apply to all models
96
- - search_context_size only works with search models
97
- - reasoning_effort only works with models that support explicit reasoning
98
- - response_format is set internally by generate_structured()
72
+ Set automatically by generate_structured().
73
+ Structured output support varies by provider and model.
74
+
75
+ verbosity: Controls output verbosity for models that support it.
76
+ Literal["low", "medium", "high"] | None
77
+ "low": Minimal output
78
+ "medium": Standard output
79
+ "high": Detailed output
80
+ Note: Only some models support verbosity control.
81
+
82
+ usage_tracking: Enable token usage tracking in API responses (default: True).
83
+ When enabled, adds {"usage": {"include": True}} to extra_body.
84
+ Disable for providers that don't support usage tracking.
85
+
86
+ user: User identifier for cost tracking and monitoring.
87
+ A unique identifier representing the end-user, which can help track costs
88
+ and detect abuse. Maximum length is typically 256 characters.
89
+ Useful for multi-tenant applications or per-user billing.
90
+
91
+ metadata: Custom metadata tags for tracking and observability.
92
+ Dictionary of string key-value pairs for tagging requests.
93
+ Useful for tracking experiments, versions, or custom attributes.
94
+ Maximum of 16 key-value pairs, each key/value max 64 characters.
95
+ Passed through to LMNR tracing and API provider metadata.
96
+
97
+ extra_body: Additional provider-specific parameters to pass in request body.
98
+ Dictionary of custom parameters not covered by standard options.
99
+ Merged with usage_tracking if both are set.
100
+ Useful for beta features or provider-specific capabilities.
101
+
102
+ Not all options apply to all models. search_context_size only works with search models,
103
+ reasoning_effort only works with models that support explicit reasoning, and
104
+ response_format is set internally by generate_structured(). cache_ttl accepts formats
105
+ like "120s", "5m", "1h" or None (default: "300s"). Stop sequences are limited to 4 by
106
+ most providers.
99
107
  """
100
108
 
101
109
  temperature: float | None = None
@@ -103,13 +111,21 @@ class ModelOptions(BaseModel):
103
111
  search_context_size: Literal["low", "medium", "high"] | None = None
104
112
  reasoning_effort: Literal["low", "medium", "high"] | None = None
105
113
  retries: int = 3
106
- retry_delay_seconds: int = 10
107
- timeout: int = 300
114
+ retry_delay_seconds: int = 20
115
+ timeout: int = 600
116
+ cache_ttl: str | None = "300s"
108
117
  service_tier: Literal["auto", "default", "flex", "scale", "priority"] | None = None
109
118
  max_completion_tokens: int | None = None
119
+ stop: str | list[str] | None = None
110
120
  response_format: type[BaseModel] | None = None
111
-
112
- def to_openai_completion_kwargs(self) -> dict[str, Any]:
121
+ verbosity: Literal["low", "medium", "high"] | None = None
122
+ stream: bool = False
123
+ usage_tracking: bool = True
124
+ user: str | None = None
125
+ metadata: dict[str, str] | None = None
126
+ extra_body: dict[str, Any] | None = None
127
+
128
+ def to_openai_completion_kwargs(self) -> dict[str, Any]: # noqa: C901
113
129
  """Convert options to OpenAI API completion parameters.
114
130
 
115
131
  Transforms ModelOptions fields into the format expected by
@@ -125,38 +141,42 @@ class ModelOptions(BaseModel):
125
141
  API parameter mapping:
126
142
  - temperature -> temperature
127
143
  - max_completion_tokens -> max_completion_tokens
144
+ - stop -> stop (string or list of strings)
128
145
  - reasoning_effort -> reasoning_effort
129
146
  - search_context_size -> web_search_options.search_context_size
130
147
  - response_format -> response_format
131
148
  - service_tier -> service_tier
149
+ - verbosity -> verbosity
150
+ - user -> user (for cost tracking)
151
+ - metadata -> metadata (for tracking/observability)
152
+ - extra_body -> extra_body (merged with usage tracking)
132
153
 
133
154
  Web Search Structure:
134
155
  When search_context_size is set, creates:
135
156
  {"web_search_options": {"search_context_size": "low|medium|high"}}
136
157
  Non-search models silently ignore this parameter.
137
158
 
138
- Example:
139
- >>> options = ModelOptions(temperature=0.5, timeout=60)
140
- >>> kwargs = options.to_openai_completion_kwargs()
141
- >>> kwargs
142
- {'timeout': 60, 'extra_body': {}, 'temperature': 0.5}
143
-
144
- Note:
145
- - system_prompt is handled separately in _process_messages()
146
- - retries and retry_delay_seconds are used by retry logic
147
- - extra_body is always included for potential extensions
159
+ system_prompt is handled separately in _process_messages().
160
+ retries and retry_delay_seconds are used by retry logic.
161
+ extra_body always includes usage tracking for cost monitoring.
148
162
  """
149
163
  kwargs: dict[str, Any] = {
150
164
  "timeout": self.timeout,
151
165
  "extra_body": {},
152
166
  }
153
167
 
168
+ if self.extra_body:
169
+ kwargs["extra_body"] = self.extra_body
170
+
154
171
  if self.temperature:
155
172
  kwargs["temperature"] = self.temperature
156
173
 
157
174
  if self.max_completion_tokens:
158
175
  kwargs["max_completion_tokens"] = self.max_completion_tokens
159
176
 
177
+ if self.stop:
178
+ kwargs["stop"] = self.stop
179
+
160
180
  if self.reasoning_effort:
161
181
  kwargs["reasoning_effort"] = self.reasoning_effort
162
182
 
@@ -169,4 +189,17 @@ class ModelOptions(BaseModel):
169
189
  if self.service_tier:
170
190
  kwargs["service_tier"] = self.service_tier
171
191
 
192
+ if self.verbosity:
193
+ kwargs["verbosity"] = self.verbosity
194
+
195
+ if self.user:
196
+ kwargs["user"] = self.user
197
+
198
+ if self.metadata:
199
+ kwargs["metadata"] = self.metadata
200
+
201
+ if self.usage_tracking:
202
+ kwargs["extra_body"]["usage"] = {"include": True}
203
+ kwargs["stream_options"] = {"include_usage": True}
204
+
172
205
  return kwargs