pi-service-tier 0.7.0 → 0.7.1
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.
- package/domain.ts +35 -1
- package/package.json +1 -1
package/domain.ts
CHANGED
|
@@ -163,12 +163,28 @@ function getTier(
|
|
|
163
163
|
);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
const VERTEX_SHARED_REQUEST_TYPE_HEADER = "X-Vertex-AI-LLM-Shared-Request-Type";
|
|
167
|
+
|
|
168
|
+
function setHeader(
|
|
169
|
+
headers: Record<string, unknown>,
|
|
170
|
+
name: string,
|
|
171
|
+
value: string,
|
|
172
|
+
): Record<string, unknown> {
|
|
173
|
+
const target = name.toLowerCase();
|
|
174
|
+
const next: Record<string, unknown> = {};
|
|
175
|
+
for (const [key, entryValue] of Object.entries(headers)) {
|
|
176
|
+
if (key.toLowerCase() !== target) next[key] = entryValue;
|
|
177
|
+
}
|
|
178
|
+
next[name] = value;
|
|
179
|
+
return next;
|
|
180
|
+
}
|
|
181
|
+
|
|
166
182
|
function applyPayloadServiceTier(
|
|
167
183
|
payload: Record<string, unknown>,
|
|
168
184
|
provider: ServiceTierProvider,
|
|
169
185
|
value: string,
|
|
170
186
|
): Record<string, unknown> {
|
|
171
|
-
if (provider === "google"
|
|
187
|
+
if (provider === "google") {
|
|
172
188
|
return {
|
|
173
189
|
...payload,
|
|
174
190
|
config: {
|
|
@@ -178,6 +194,24 @@ function applyPayloadServiceTier(
|
|
|
178
194
|
};
|
|
179
195
|
}
|
|
180
196
|
|
|
197
|
+
if (provider === "google-vertex") {
|
|
198
|
+
// Vertex AI rejects or ignores body `serviceTier`; it selects PayGo tiers via HTTP header.
|
|
199
|
+
const config = isRecord(payload.config) ? payload.config : {};
|
|
200
|
+
const { serviceTier: _removed, ...restConfig } = config;
|
|
201
|
+
const httpOptions = isRecord(config.httpOptions) ? config.httpOptions : {};
|
|
202
|
+
const headers = isRecord(httpOptions.headers) ? httpOptions.headers : {};
|
|
203
|
+
return {
|
|
204
|
+
...payload,
|
|
205
|
+
config: {
|
|
206
|
+
...restConfig,
|
|
207
|
+
httpOptions: {
|
|
208
|
+
...httpOptions,
|
|
209
|
+
headers: setHeader(headers, VERTEX_SHARED_REQUEST_TYPE_HEADER, value),
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
181
215
|
return { ...payload, service_tier: value };
|
|
182
216
|
}
|
|
183
217
|
|