@jambonz/llm 0.6.3 → 0.6.5
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 +16 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -3
- package/dist/index.js.map +1 -1
- package/dist/test-kit/index.cjs +16 -3
- package/dist/test-kit/index.cjs.map +1 -1
- package/dist/test-kit/index.js +16 -3
- package/dist/test-kit/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -131,6 +131,9 @@ async function* streamFromOpenAI(client, req, options) {
|
|
|
131
131
|
if (req.cacheKey && options.includeCacheKey !== false) {
|
|
132
132
|
body.prompt_cache_key = req.cacheKey;
|
|
133
133
|
}
|
|
134
|
+
if (req.cacheKey && options.openRouterAutoCache && /^~?anthropic\//.test(req.model)) {
|
|
135
|
+
body.cache_control = { type: "ephemeral" };
|
|
136
|
+
}
|
|
134
137
|
const effectiveMaxTokens = req.maxTokens ?? options.defaultMaxTokens;
|
|
135
138
|
if (effectiveMaxTokens !== void 0) {
|
|
136
139
|
const param = options.tokensParam ?? (needsMaxCompletionTokens(req.model) ? "max_completion_tokens" : "max_tokens");
|
|
@@ -555,10 +558,13 @@ var OpenAIAdapter = class {
|
|
|
555
558
|
vendor = openAIManifest.vendor;
|
|
556
559
|
acceptedAuth = ["apiKey"];
|
|
557
560
|
client;
|
|
561
|
+
/** baseURL is OpenRouter: enables its automatic prompt caching for Anthropic models. */
|
|
562
|
+
isOpenRouter = false;
|
|
558
563
|
init(auth, client) {
|
|
559
564
|
if (!auth.apiKey) {
|
|
560
565
|
throw new Error("OpenAIAdapter: apiKey is required");
|
|
561
566
|
}
|
|
567
|
+
this.isOpenRouter = /(^|\/\/|\.)openrouter\.ai(\/|:|$)/i.test(auth.baseURL ?? "");
|
|
562
568
|
this.client = new import_openai.default({
|
|
563
569
|
apiKey: auth.apiKey,
|
|
564
570
|
...auth.baseURL ? { baseURL: auth.baseURL } : {},
|
|
@@ -570,7 +576,8 @@ var OpenAIAdapter = class {
|
|
|
570
576
|
return streamFromOpenAI(this.ensureClient(), req, {
|
|
571
577
|
knownModels: this.knownModels(),
|
|
572
578
|
vendorMetadataExtractor: OPENAI_METADATA_EXTRACTOR,
|
|
573
|
-
includeCacheKey: this.forwardCacheKey()
|
|
579
|
+
includeCacheKey: this.forwardCacheKey(),
|
|
580
|
+
openRouterAutoCache: this.isOpenRouter
|
|
574
581
|
});
|
|
575
582
|
}
|
|
576
583
|
appendAssistantToolCall(history, toolCalls, assistantText) {
|
|
@@ -2838,11 +2845,12 @@ var BedrockAdapter = class {
|
|
|
2838
2845
|
if (Object.keys(inferenceConfig).length > 0) {
|
|
2839
2846
|
commandInput.inferenceConfig = inferenceConfig;
|
|
2840
2847
|
}
|
|
2841
|
-
|
|
2848
|
+
const caching = req.cacheKey ? cachePointSupport(req.model) : void 0;
|
|
2849
|
+
if (caching) {
|
|
2842
2850
|
if (commandInput.system) {
|
|
2843
2851
|
commandInput.system.push({ cachePoint: { type: "default" } });
|
|
2844
2852
|
}
|
|
2845
|
-
if (tools) {
|
|
2853
|
+
if (tools && caching.tools) {
|
|
2846
2854
|
tools.tools.push({ cachePoint: { type: "default" } });
|
|
2847
2855
|
}
|
|
2848
2856
|
markLastMessageForCaching2(messages);
|
|
@@ -3066,6 +3074,11 @@ function buildWireMessages3(req) {
|
|
|
3066
3074
|
}
|
|
3067
3075
|
return out;
|
|
3068
3076
|
}
|
|
3077
|
+
function cachePointSupport(model) {
|
|
3078
|
+
if (model.includes("anthropic.claude")) return { tools: true };
|
|
3079
|
+
if (model.includes("amazon.nova")) return { tools: false };
|
|
3080
|
+
return void 0;
|
|
3081
|
+
}
|
|
3069
3082
|
function markLastMessageForCaching2(messages) {
|
|
3070
3083
|
if (messages.length === 0) return;
|
|
3071
3084
|
const last = messages[messages.length - 1];
|