@jambonz/llm 0.6.4 → 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 +8 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/test-kit/index.cjs +8 -1
- package/dist/test-kit/index.cjs.map +1 -1
- package/dist/test-kit/index.js +8 -1
- 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) {
|