@llmops/app 0.3.3 → 0.3.4-beta.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/dist/index.cjs +36 -16
- package/dist/index.mjs +36 -16
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -16432,7 +16432,8 @@ async function handleDirectProviderRequest(c, next, originalBody, providerSlug,
|
|
|
16432
16432
|
...originalBody,
|
|
16433
16433
|
model: modelName
|
|
16434
16434
|
};
|
|
16435
|
-
|
|
16435
|
+
const path$1 = c.req.path;
|
|
16436
|
+
if (path$1.endsWith("/chat/completions") || path$1.endsWith("/completions")) delete updatedBody.input;
|
|
16436
16437
|
const newHeaders = new Headers(c.req.raw.headers);
|
|
16437
16438
|
newHeaders.set("x-llmops-config", JSON.stringify(portkeyConfig));
|
|
16438
16439
|
if (portkeyConfig.default_input_guardrails) newHeaders.set("x-portkey-default-input-guardrails", JSON.stringify(portkeyConfig.default_input_guardrails));
|
|
@@ -16474,7 +16475,7 @@ const createGatewayAdapterMiddleware = () => {
|
|
|
16474
16475
|
const method = c.req.method;
|
|
16475
16476
|
const contentType = c.req.header("content-type")?.split(";")[0];
|
|
16476
16477
|
const isChatRequest = method === "POST" && contentType === "application/json" && (path$1.endsWith("/chat/completions") || path$1.endsWith("/completions"));
|
|
16477
|
-
if (!configId &&
|
|
16478
|
+
if (!configId && method === "POST" && contentType === "application/json") {
|
|
16478
16479
|
try {
|
|
16479
16480
|
const body = await c.req.json();
|
|
16480
16481
|
const model = body.model;
|
|
@@ -16643,13 +16644,17 @@ function createStreamingCostExtractor() {
|
|
|
16643
16644
|
};
|
|
16644
16645
|
}
|
|
16645
16646
|
const usageData = parsed;
|
|
16646
|
-
if (usageData.usage)
|
|
16647
|
-
promptTokens
|
|
16648
|
-
completionTokens
|
|
16649
|
-
|
|
16650
|
-
|
|
16651
|
-
|
|
16652
|
-
|
|
16647
|
+
if (usageData.usage) {
|
|
16648
|
+
const promptTokens = usageData.usage.prompt_tokens ?? usageData.usage.input_tokens ?? 0;
|
|
16649
|
+
const completionTokens = usageData.usage.completion_tokens ?? usageData.usage.output_tokens ?? 0;
|
|
16650
|
+
extractedUsage = {
|
|
16651
|
+
promptTokens,
|
|
16652
|
+
completionTokens,
|
|
16653
|
+
totalTokens: usageData.usage.total_tokens ?? promptTokens + completionTokens,
|
|
16654
|
+
cachedTokens: usageData.usage.prompt_tokens_details?.cached_tokens ?? usageData.usage.input_tokens_details?.cached_tokens,
|
|
16655
|
+
hookResults: extractedHookResults
|
|
16656
|
+
};
|
|
16657
|
+
}
|
|
16653
16658
|
} catch {}
|
|
16654
16659
|
}
|
|
16655
16660
|
return {
|
|
@@ -16965,7 +16970,18 @@ function createCostTrackingMiddleware(config$1 = {}) {
|
|
|
16965
16970
|
return async (c, next) => {
|
|
16966
16971
|
if (!enabled) return next();
|
|
16967
16972
|
const path$1 = c.req.path;
|
|
16968
|
-
if (!
|
|
16973
|
+
if (![
|
|
16974
|
+
"/chat/completions",
|
|
16975
|
+
"/completions",
|
|
16976
|
+
"/responses",
|
|
16977
|
+
"/embeddings",
|
|
16978
|
+
"/images/generations",
|
|
16979
|
+
"/images/edits",
|
|
16980
|
+
"/audio/speech",
|
|
16981
|
+
"/audio/transcriptions",
|
|
16982
|
+
"/audio/translations",
|
|
16983
|
+
"/messages"
|
|
16984
|
+
].some((endpoint) => path$1.endsWith(endpoint) || endpoint === "/responses" && path$1.match(/\/responses\/[^/]+$/))) return next();
|
|
16969
16985
|
const requestId = (0, node_crypto.randomUUID)();
|
|
16970
16986
|
const startTime = Date.now();
|
|
16971
16987
|
c.header("x-llmops-request-id", requestId);
|
|
@@ -17061,12 +17077,16 @@ function createCostTrackingMiddleware(config$1 = {}) {
|
|
|
17061
17077
|
let guardrailResults = null;
|
|
17062
17078
|
try {
|
|
17063
17079
|
const responseBody = await response.clone().json();
|
|
17064
|
-
if (responseBody.usage)
|
|
17065
|
-
promptTokens
|
|
17066
|
-
completionTokens
|
|
17067
|
-
|
|
17068
|
-
|
|
17069
|
-
|
|
17080
|
+
if (responseBody.usage) {
|
|
17081
|
+
const promptTokens = responseBody.usage.prompt_tokens ?? responseBody.usage.input_tokens ?? 0;
|
|
17082
|
+
const completionTokens = responseBody.usage.completion_tokens ?? responseBody.usage.output_tokens ?? 0;
|
|
17083
|
+
usage = {
|
|
17084
|
+
promptTokens,
|
|
17085
|
+
completionTokens,
|
|
17086
|
+
totalTokens: responseBody.usage.total_tokens || promptTokens + completionTokens,
|
|
17087
|
+
cachedTokens: responseBody.usage.prompt_tokens_details?.cached_tokens ?? responseBody.usage.input_tokens_details?.cached_tokens
|
|
17088
|
+
};
|
|
17089
|
+
}
|
|
17070
17090
|
if (responseBody.hook_results) {
|
|
17071
17091
|
const wasBlocked = statusCode === 446;
|
|
17072
17092
|
guardrailResults = transformHookResultsToGuardrailResults(responseBody.hook_results, wasBlocked);
|
package/dist/index.mjs
CHANGED
|
@@ -16404,7 +16404,8 @@ async function handleDirectProviderRequest(c, next, originalBody, providerSlug,
|
|
|
16404
16404
|
...originalBody,
|
|
16405
16405
|
model: modelName
|
|
16406
16406
|
};
|
|
16407
|
-
|
|
16407
|
+
const path = c.req.path;
|
|
16408
|
+
if (path.endsWith("/chat/completions") || path.endsWith("/completions")) delete updatedBody.input;
|
|
16408
16409
|
const newHeaders = new Headers(c.req.raw.headers);
|
|
16409
16410
|
newHeaders.set("x-llmops-config", JSON.stringify(portkeyConfig));
|
|
16410
16411
|
if (portkeyConfig.default_input_guardrails) newHeaders.set("x-portkey-default-input-guardrails", JSON.stringify(portkeyConfig.default_input_guardrails));
|
|
@@ -16446,7 +16447,7 @@ const createGatewayAdapterMiddleware = () => {
|
|
|
16446
16447
|
const method = c.req.method;
|
|
16447
16448
|
const contentType = c.req.header("content-type")?.split(";")[0];
|
|
16448
16449
|
const isChatRequest = method === "POST" && contentType === "application/json" && (path.endsWith("/chat/completions") || path.endsWith("/completions"));
|
|
16449
|
-
if (!configId &&
|
|
16450
|
+
if (!configId && method === "POST" && contentType === "application/json") {
|
|
16450
16451
|
try {
|
|
16451
16452
|
const body = await c.req.json();
|
|
16452
16453
|
const model = body.model;
|
|
@@ -16615,13 +16616,17 @@ function createStreamingCostExtractor() {
|
|
|
16615
16616
|
};
|
|
16616
16617
|
}
|
|
16617
16618
|
const usageData = parsed;
|
|
16618
|
-
if (usageData.usage)
|
|
16619
|
-
promptTokens
|
|
16620
|
-
completionTokens
|
|
16621
|
-
|
|
16622
|
-
|
|
16623
|
-
|
|
16624
|
-
|
|
16619
|
+
if (usageData.usage) {
|
|
16620
|
+
const promptTokens = usageData.usage.prompt_tokens ?? usageData.usage.input_tokens ?? 0;
|
|
16621
|
+
const completionTokens = usageData.usage.completion_tokens ?? usageData.usage.output_tokens ?? 0;
|
|
16622
|
+
extractedUsage = {
|
|
16623
|
+
promptTokens,
|
|
16624
|
+
completionTokens,
|
|
16625
|
+
totalTokens: usageData.usage.total_tokens ?? promptTokens + completionTokens,
|
|
16626
|
+
cachedTokens: usageData.usage.prompt_tokens_details?.cached_tokens ?? usageData.usage.input_tokens_details?.cached_tokens,
|
|
16627
|
+
hookResults: extractedHookResults
|
|
16628
|
+
};
|
|
16629
|
+
}
|
|
16625
16630
|
} catch {}
|
|
16626
16631
|
}
|
|
16627
16632
|
return {
|
|
@@ -16937,7 +16942,18 @@ function createCostTrackingMiddleware(config$1 = {}) {
|
|
|
16937
16942
|
return async (c, next) => {
|
|
16938
16943
|
if (!enabled) return next();
|
|
16939
16944
|
const path = c.req.path;
|
|
16940
|
-
if (!
|
|
16945
|
+
if (![
|
|
16946
|
+
"/chat/completions",
|
|
16947
|
+
"/completions",
|
|
16948
|
+
"/responses",
|
|
16949
|
+
"/embeddings",
|
|
16950
|
+
"/images/generations",
|
|
16951
|
+
"/images/edits",
|
|
16952
|
+
"/audio/speech",
|
|
16953
|
+
"/audio/transcriptions",
|
|
16954
|
+
"/audio/translations",
|
|
16955
|
+
"/messages"
|
|
16956
|
+
].some((endpoint) => path.endsWith(endpoint) || endpoint === "/responses" && path.match(/\/responses\/[^/]+$/))) return next();
|
|
16941
16957
|
const requestId = randomUUID();
|
|
16942
16958
|
const startTime = Date.now();
|
|
16943
16959
|
c.header("x-llmops-request-id", requestId);
|
|
@@ -17033,12 +17049,16 @@ function createCostTrackingMiddleware(config$1 = {}) {
|
|
|
17033
17049
|
let guardrailResults = null;
|
|
17034
17050
|
try {
|
|
17035
17051
|
const responseBody = await response.clone().json();
|
|
17036
|
-
if (responseBody.usage)
|
|
17037
|
-
promptTokens
|
|
17038
|
-
completionTokens
|
|
17039
|
-
|
|
17040
|
-
|
|
17041
|
-
|
|
17052
|
+
if (responseBody.usage) {
|
|
17053
|
+
const promptTokens = responseBody.usage.prompt_tokens ?? responseBody.usage.input_tokens ?? 0;
|
|
17054
|
+
const completionTokens = responseBody.usage.completion_tokens ?? responseBody.usage.output_tokens ?? 0;
|
|
17055
|
+
usage = {
|
|
17056
|
+
promptTokens,
|
|
17057
|
+
completionTokens,
|
|
17058
|
+
totalTokens: responseBody.usage.total_tokens || promptTokens + completionTokens,
|
|
17059
|
+
cachedTokens: responseBody.usage.prompt_tokens_details?.cached_tokens ?? responseBody.usage.input_tokens_details?.cached_tokens
|
|
17060
|
+
};
|
|
17061
|
+
}
|
|
17042
17062
|
if (responseBody.hook_results) {
|
|
17043
17063
|
const wasBlocked = statusCode === 446;
|
|
17044
17064
|
guardrailResults = transformHookResultsToGuardrailResults(responseBody.hook_results, wasBlocked);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llmops/app",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4-beta.1",
|
|
4
4
|
"description": "LLMOps application with server and client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"react-aria-components": "^1.13.0",
|
|
68
68
|
"react-hook-form": "^7.68.0",
|
|
69
69
|
"recharts": "^3.6.0",
|
|
70
|
-
"@llmops/core": "^0.3.
|
|
71
|
-
"@llmops/gateway": "^0.3.
|
|
70
|
+
"@llmops/core": "^0.3.4-beta.1",
|
|
71
|
+
"@llmops/gateway": "^0.3.4-beta.1"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"react": "^19.2.1",
|