@jaypie/llm 1.2.25 → 1.2.26
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/cjs/index.cjs
CHANGED
|
@@ -1065,6 +1065,24 @@ const NOT_RETRYABLE_ERROR_NAMES = [
|
|
|
1065
1065
|
"NotFoundError",
|
|
1066
1066
|
"PermissionDeniedError",
|
|
1067
1067
|
];
|
|
1068
|
+
// Models known not to accept `temperature`.
|
|
1069
|
+
// Patterns (not exact names) so dated variants and future releases are covered
|
|
1070
|
+
// without code changes — Anthropic is trending toward removing temperature on
|
|
1071
|
+
// newer Claude models.
|
|
1072
|
+
const MODELS_WITHOUT_TEMPERATURE = [
|
|
1073
|
+
/^claude-opus-4-[789]/,
|
|
1074
|
+
/^claude-opus-[5-9]/,
|
|
1075
|
+
];
|
|
1076
|
+
function isTemperatureDeprecationError(error) {
|
|
1077
|
+
if (!error || typeof error !== "object")
|
|
1078
|
+
return false;
|
|
1079
|
+
const err = error;
|
|
1080
|
+
const name = error?.constructor?.name;
|
|
1081
|
+
if (name !== "BadRequestError" && err.status !== 400)
|
|
1082
|
+
return false;
|
|
1083
|
+
const messages = [err.message, err.error?.message].filter((m) => typeof m === "string");
|
|
1084
|
+
return messages.some((m) => m.toLowerCase().includes("temperature"));
|
|
1085
|
+
}
|
|
1068
1086
|
//
|
|
1069
1087
|
//
|
|
1070
1088
|
// Main
|
|
@@ -1079,6 +1097,20 @@ class AnthropicAdapter extends BaseProviderAdapter {
|
|
|
1079
1097
|
super(...arguments);
|
|
1080
1098
|
this.name = PROVIDER.ANTHROPIC.NAME;
|
|
1081
1099
|
this.defaultModel = PROVIDER.ANTHROPIC.MODEL.DEFAULT;
|
|
1100
|
+
// Session-level cache of models observed to reject `temperature` at runtime.
|
|
1101
|
+
// Populated by executeRequest on 400 errors so repeat calls skip the param.
|
|
1102
|
+
this.runtimeNoTemperatureModels = new Set();
|
|
1103
|
+
}
|
|
1104
|
+
rememberModelRejectsTemperature(model) {
|
|
1105
|
+
this.runtimeNoTemperatureModels.add(model);
|
|
1106
|
+
}
|
|
1107
|
+
clearRuntimeNoTemperatureModels() {
|
|
1108
|
+
this.runtimeNoTemperatureModels.clear();
|
|
1109
|
+
}
|
|
1110
|
+
supportsTemperature(model) {
|
|
1111
|
+
if (this.runtimeNoTemperatureModels.has(model))
|
|
1112
|
+
return false;
|
|
1113
|
+
return !MODELS_WITHOUT_TEMPERATURE.some((pattern) => pattern.test(model));
|
|
1082
1114
|
}
|
|
1083
1115
|
//
|
|
1084
1116
|
// Request Building
|
|
@@ -1170,6 +1202,11 @@ class AnthropicAdapter extends BaseProviderAdapter {
|
|
|
1170
1202
|
if (request.temperature !== undefined) {
|
|
1171
1203
|
anthropicRequest.temperature = request.temperature;
|
|
1172
1204
|
}
|
|
1205
|
+
// Strip temperature for models that don't support it (denylist + runtime cache)
|
|
1206
|
+
if (anthropicRequest.temperature !== undefined &&
|
|
1207
|
+
!this.supportsTemperature(anthropicRequest.model)) {
|
|
1208
|
+
delete anthropicRequest.temperature;
|
|
1209
|
+
}
|
|
1173
1210
|
return anthropicRequest;
|
|
1174
1211
|
}
|
|
1175
1212
|
formatTools(toolkit, outputSchema) {
|
|
@@ -1220,22 +1257,48 @@ class AnthropicAdapter extends BaseProviderAdapter {
|
|
|
1220
1257
|
//
|
|
1221
1258
|
async executeRequest(client, request, signal) {
|
|
1222
1259
|
const anthropic = client;
|
|
1260
|
+
const anthropicRequest = request;
|
|
1223
1261
|
try {
|
|
1224
|
-
return (await anthropic.messages.create(
|
|
1262
|
+
return (await anthropic.messages.create(anthropicRequest, signal ? { signal } : undefined));
|
|
1225
1263
|
}
|
|
1226
1264
|
catch (error) {
|
|
1227
1265
|
if (signal?.aborted)
|
|
1228
1266
|
return undefined;
|
|
1267
|
+
// If the model rejected `temperature`, cache it and retry without the param
|
|
1268
|
+
if (anthropicRequest.temperature !== undefined &&
|
|
1269
|
+
isTemperatureDeprecationError(error)) {
|
|
1270
|
+
this.rememberModelRejectsTemperature(anthropicRequest.model);
|
|
1271
|
+
const retryRequest = { ...anthropicRequest };
|
|
1272
|
+
delete retryRequest.temperature;
|
|
1273
|
+
return (await anthropic.messages.create(retryRequest, signal ? { signal } : undefined));
|
|
1274
|
+
}
|
|
1229
1275
|
throw error;
|
|
1230
1276
|
}
|
|
1231
1277
|
}
|
|
1232
1278
|
async *executeStreamRequest(client, request, signal) {
|
|
1233
1279
|
const anthropic = client;
|
|
1234
|
-
|
|
1280
|
+
let streamRequest = {
|
|
1235
1281
|
...request,
|
|
1236
1282
|
stream: true,
|
|
1237
1283
|
};
|
|
1238
|
-
|
|
1284
|
+
let stream;
|
|
1285
|
+
try {
|
|
1286
|
+
stream = await anthropic.messages.create(streamRequest, signal ? { signal } : undefined);
|
|
1287
|
+
}
|
|
1288
|
+
catch (error) {
|
|
1289
|
+
if (streamRequest.temperature !== undefined &&
|
|
1290
|
+
isTemperatureDeprecationError(error)) {
|
|
1291
|
+
this.rememberModelRejectsTemperature(streamRequest.model);
|
|
1292
|
+
streamRequest = {
|
|
1293
|
+
...streamRequest,
|
|
1294
|
+
};
|
|
1295
|
+
delete streamRequest.temperature;
|
|
1296
|
+
stream = await anthropic.messages.create(streamRequest, signal ? { signal } : undefined);
|
|
1297
|
+
}
|
|
1298
|
+
else {
|
|
1299
|
+
throw error;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1239
1302
|
// Track current tool call being built
|
|
1240
1303
|
let currentToolCall = null;
|
|
1241
1304
|
// Track usage for final chunk
|