ai-pipeline-core 0.2.8__py3-none-any.whl → 0.2.9__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 +1 -1
- ai_pipeline_core/llm/client.py +21 -20
- ai_pipeline_core/llm/model_response.py +6 -3
- {ai_pipeline_core-0.2.8.dist-info → ai_pipeline_core-0.2.9.dist-info}/METADATA +1 -1
- {ai_pipeline_core-0.2.8.dist-info → ai_pipeline_core-0.2.9.dist-info}/RECORD +7 -7
- {ai_pipeline_core-0.2.8.dist-info → ai_pipeline_core-0.2.9.dist-info}/WHEEL +0 -0
- {ai_pipeline_core-0.2.8.dist-info → ai_pipeline_core-0.2.9.dist-info}/licenses/LICENSE +0 -0
ai_pipeline_core/__init__.py
CHANGED
ai_pipeline_core/llm/client.py
CHANGED
|
@@ -45,31 +45,30 @@ def _process_messages(
|
|
|
45
45
|
|
|
46
46
|
Internal function that combines context and messages into a single
|
|
47
47
|
list of API-compatible messages. Applies caching directives to
|
|
48
|
-
context messages for efficiency.
|
|
48
|
+
system prompt and context messages for efficiency.
|
|
49
49
|
|
|
50
50
|
Args:
|
|
51
51
|
context: Messages to be cached (typically expensive/static content).
|
|
52
52
|
messages: Regular messages without caching (dynamic queries).
|
|
53
53
|
system_prompt: Optional system instructions for the model.
|
|
54
|
-
cache_ttl: Cache TTL for context messages (e.g. "120s", "300s", "1h").
|
|
54
|
+
cache_ttl: Cache TTL for system and context messages (e.g. "120s", "300s", "1h").
|
|
55
55
|
Set to None or empty string to disable caching.
|
|
56
56
|
|
|
57
57
|
Returns:
|
|
58
58
|
List of formatted messages ready for API calls, with:
|
|
59
|
-
- System prompt at the beginning (if provided)
|
|
60
|
-
- Context messages with cache_control on
|
|
59
|
+
- System prompt at the beginning with cache_control (if provided and cache_ttl set)
|
|
60
|
+
- Context messages with cache_control on all messages (if cache_ttl set)
|
|
61
61
|
- Regular messages without caching
|
|
62
62
|
|
|
63
63
|
System Prompt Location:
|
|
64
64
|
The system prompt parameter is always injected as the FIRST message
|
|
65
|
-
with role="system". It is
|
|
66
|
-
system prompts without breaking cache efficiency.
|
|
65
|
+
with role="system". It is cached along with context when cache_ttl is set.
|
|
67
66
|
|
|
68
67
|
Cache behavior:
|
|
69
|
-
|
|
68
|
+
All system and context messages get ephemeral caching with specified TTL
|
|
70
69
|
to reduce token usage on repeated calls with same context.
|
|
71
70
|
If cache_ttl is None or empty string (falsy), no caching is applied.
|
|
72
|
-
|
|
71
|
+
All system and context messages receive cache_control to maximize cache efficiency.
|
|
73
72
|
|
|
74
73
|
Note:
|
|
75
74
|
This is an internal function used by _generate_with_retry().
|
|
@@ -79,26 +78,28 @@ def _process_messages(
|
|
|
79
78
|
|
|
80
79
|
# Add system prompt if provided
|
|
81
80
|
if system_prompt:
|
|
82
|
-
processed_messages.append({
|
|
81
|
+
processed_messages.append({
|
|
82
|
+
"role": "system",
|
|
83
|
+
"content": [{"type": "text", "text": system_prompt}],
|
|
84
|
+
})
|
|
83
85
|
|
|
84
86
|
# Process context messages with caching if provided
|
|
85
87
|
if context:
|
|
86
88
|
# Use AIMessages.to_prompt() for context
|
|
87
89
|
context_messages = context.to_prompt()
|
|
90
|
+
processed_messages.extend(context_messages)
|
|
88
91
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"type": "ephemeral",
|
|
93
|
-
"ttl": cache_ttl,
|
|
94
|
-
}
|
|
95
|
-
assert isinstance(context_messages[-1]["content"], list) # type: ignore
|
|
96
|
-
context_messages[-1]["content"][-1]["cache_control"] = { # type: ignore
|
|
92
|
+
if cache_ttl:
|
|
93
|
+
for message in processed_messages:
|
|
94
|
+
message["cache_control"] = { # type: ignore
|
|
97
95
|
"type": "ephemeral",
|
|
98
96
|
"ttl": cache_ttl,
|
|
99
97
|
}
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
if isinstance(message["content"], list): # type: ignore
|
|
99
|
+
message["content"][-1]["cache_control"] = { # type: ignore
|
|
100
|
+
"type": "ephemeral",
|
|
101
|
+
"ttl": cache_ttl,
|
|
102
|
+
}
|
|
102
103
|
|
|
103
104
|
# Process regular messages without caching
|
|
104
105
|
if messages:
|
|
@@ -156,7 +157,7 @@ def _model_name_to_openrouter_model(model: ModelName) -> str:
|
|
|
156
157
|
if model == "grok-4-fast-search":
|
|
157
158
|
return "x-ai/grok-4-fast:online"
|
|
158
159
|
if model == "sonar-pro-search":
|
|
159
|
-
return "perplexity/sonar-
|
|
160
|
+
return "perplexity/sonar-pro-search"
|
|
160
161
|
if model.startswith("gemini"):
|
|
161
162
|
return f"google/{model}"
|
|
162
163
|
elif model.startswith("gpt"):
|
|
@@ -88,10 +88,13 @@ class ModelResponse(ChatCompletion):
|
|
|
88
88
|
data = chat_completion.model_dump()
|
|
89
89
|
|
|
90
90
|
# fixes issue where the role is "assistantassistant" instead of "assistant"
|
|
91
|
+
valid_finish_reasons = {"stop", "length", "tool_calls", "content_filter", "function_call"}
|
|
91
92
|
for i in range(len(data["choices"])):
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
data["choices"][i]["message"]["role"] = "assistant"
|
|
94
|
+
# Only update finish_reason if it's not already a valid value
|
|
95
|
+
current_finish_reason = data["choices"][i].get("finish_reason")
|
|
96
|
+
if current_finish_reason not in valid_finish_reasons:
|
|
97
|
+
data["choices"][i]["finish_reason"] = "stop"
|
|
95
98
|
|
|
96
99
|
super().__init__(**data)
|
|
97
100
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ai-pipeline-core
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.9
|
|
4
4
|
Summary: Core utilities for AI-powered processing pipelines using prefect
|
|
5
5
|
Project-URL: Homepage, https://github.com/bbarwik/ai-pipeline-core
|
|
6
6
|
Project-URL: Repository, https://github.com/bbarwik/ai-pipeline-core
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
ai_pipeline_core/__init__.py,sha256=
|
|
1
|
+
ai_pipeline_core/__init__.py,sha256=o0J4DdxbwUbZ6I07G0OVuCnc28NsywvNqEeiYuCmYI0,5720
|
|
2
2
|
ai_pipeline_core/exceptions.py,sha256=vx-XLTw2fJSPs-vwtXVYtqoQUcOc0JeI7UmHqRqQYWU,1569
|
|
3
3
|
ai_pipeline_core/pipeline.py,sha256=fWTVmrnOEIFge6o2NUYW2ndGef5UurpL8_fK5tkXbzI,28700
|
|
4
4
|
ai_pipeline_core/prefect.py,sha256=91ZgLJHsDsRUW77CpNmkKxYs3RCJuucPM3pjKmNBeDg,2199
|
|
@@ -19,9 +19,9 @@ ai_pipeline_core/flow/config.py,sha256=3PCDph2n8dj-txqAvd9Wflbi_6lmfXFR9rUhM-szG
|
|
|
19
19
|
ai_pipeline_core/flow/options.py,sha256=zn3N5DgYtlxLq0AvXfana3UOhym7A3XCheQSBIIarZE,2295
|
|
20
20
|
ai_pipeline_core/llm/__init__.py,sha256=3B_vtEzxrzidP1qOUNQ4RxlUmxZ2MBKQcUhQiTybM9g,661
|
|
21
21
|
ai_pipeline_core/llm/ai_messages.py,sha256=Onin3UPdbJQNl3WfY3-_jE5KRmF-ciXsa5K6UPOiy5s,14410
|
|
22
|
-
ai_pipeline_core/llm/client.py,sha256=
|
|
22
|
+
ai_pipeline_core/llm/client.py,sha256=VQOUxGT8bUoKiD3-XX0VY5OHUX80Xdz6esrN9j2KUZ4,25013
|
|
23
23
|
ai_pipeline_core/llm/model_options.py,sha256=uRNIHfVeh2sgt1mZBiOUx6hPQ6GKjB8b7TytZJ6afKg,11768
|
|
24
|
-
ai_pipeline_core/llm/model_response.py,sha256
|
|
24
|
+
ai_pipeline_core/llm/model_response.py,sha256=-fKJcblDP_Z6NV9CGp4bm_hitb0Z0jyy0ZndCQUpRkQ,13493
|
|
25
25
|
ai_pipeline_core/llm/model_types.py,sha256=2J4Qsb1x21I4eo_VPeaMMOW8shOGPqzJuoGjTLcBFPM,2791
|
|
26
26
|
ai_pipeline_core/logging/__init__.py,sha256=Nz6-ghAoENsgNmLD2ma9TW9M0U2_QfxuQ5DDW6Vt6M0,651
|
|
27
27
|
ai_pipeline_core/logging/logging.yml,sha256=YTW48keO_K5bkkb-KXGM7ZuaYKiquLsjsURei8Ql0V4,1353
|
|
@@ -35,7 +35,7 @@ ai_pipeline_core/storage/storage.py,sha256=ClMr419Y-eU2RuOjZYd51dC0stWQk28Vb56Pv
|
|
|
35
35
|
ai_pipeline_core/utils/__init__.py,sha256=TJSmEm1Quf-gKwXrxM96u2IGzVolUyeNNfLMPoLstXI,254
|
|
36
36
|
ai_pipeline_core/utils/deploy.py,sha256=rAtRuwkmGkc-fqvDMXpt08OzLrD7KTDMAmLDC9wYg7Y,13147
|
|
37
37
|
ai_pipeline_core/utils/remote_deployment.py,sha256=cPTgnS5InK08qiWnuPz3e8YKjoT3sPBloSaDfNTzghs,10137
|
|
38
|
-
ai_pipeline_core-0.2.
|
|
39
|
-
ai_pipeline_core-0.2.
|
|
40
|
-
ai_pipeline_core-0.2.
|
|
41
|
-
ai_pipeline_core-0.2.
|
|
38
|
+
ai_pipeline_core-0.2.9.dist-info/METADATA,sha256=8p4PXSJqP5j4XV4cxjuncSN3i8914ZMupaU3EKs6Qpk,15159
|
|
39
|
+
ai_pipeline_core-0.2.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
40
|
+
ai_pipeline_core-0.2.9.dist-info/licenses/LICENSE,sha256=kKj8mfbdWwkyG3U6n7ztB3bAZlEwShTkAsvaY657i3I,1074
|
|
41
|
+
ai_pipeline_core-0.2.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|