openloops 0.4.3 → 0.4.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/CHANGELOG.md +7 -0
- package/dist/clients/llm/llm-client.js +8 -5
- package/dist/clients/llm/llm-client.mjs +8 -5
- package/dist/clients/llm/llm-error.js +1 -1
- package/dist/clients/llm/llm-error.mjs +1 -1
- package/dist/clients/llm/sampling-rules.d.ts +1 -0
- package/dist/clients/llm/sampling-rules.js +33 -0
- package/dist/clients/llm/sampling-rules.mjs +10 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `openloops` are written here, newest first. The format follows [Keep a Changelog](https://keepachangelog.com) and the versions follow [semantic versioning](https://semver.org), where a minor version can still break the API while the package is in beta. Changes before 0.4.0 are not recorded here, see the commits and the tags.
|
|
4
4
|
|
|
5
|
+
## 0.4.4
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Claude models on Amazon Bedrock failed with `temperature may only be set to 1 when thinking is enabled`. The temperature is no longer sent to them when thinking is on. The rules live in `src/clients/llm/sampling-rules.ts`, one entry per provider and model, so another model that rejects the temperature is one more line.
|
|
10
|
+
- A provider error saying the temperature "may only" take some value is now seen as a rejected sampling parameter, so the existing retry without temperature also covers it.
|
|
11
|
+
|
|
5
12
|
## 0.4.3
|
|
6
13
|
|
|
7
14
|
### Added
|
|
@@ -39,6 +39,7 @@ var import_llmcalls = require("../../services/llmcalls/index.js");
|
|
|
39
39
|
var import_pi_ai_adapter = require("./pi-ai-adapter");
|
|
40
40
|
var import_number_setting = require("../../common/utils/number-setting.js");
|
|
41
41
|
var import_model_resolution = require("./model-resolution");
|
|
42
|
+
var import_sampling_rules = require("./sampling-rules");
|
|
42
43
|
var import_llm_error = require("./llm-error");
|
|
43
44
|
const DEFAULT_TEMPERATURE = 0.7;
|
|
44
45
|
const MAX_RETRIES = 4;
|
|
@@ -99,15 +100,16 @@ class LLMClient {
|
|
|
99
100
|
const resolvedChoice = toolChoice === "required" ? REQUIRED_TOOL_CHOICE[model.api] : toolChoice;
|
|
100
101
|
if (toolChoice === "required" && !resolvedChoice) throw new Error(`[LLM Client] forced tool choice is not supported for api ${model.api}`);
|
|
101
102
|
const context = (0, import_pi_ai_adapter.toPiContext)({ messages, tools }, model);
|
|
103
|
+
const reasoning = thinking && thinking !== "off" ? thinking : void 0;
|
|
104
|
+
const ruleOmitsTemperature = (0, import_sampling_rules.omitsTemperature)(provider, modelName, Boolean(reasoning));
|
|
102
105
|
const send = (omitTemperature) => this.withDeadline(thinking === "high" ? this.callTimeoutMs * HIGH_THINKING_TIMEOUT_FACTOR : this.callTimeoutMs, (signal) => {
|
|
103
|
-
const options = { ...omitTemperature ? {} : { temperature }, maxRetries: MAX_RETRIES, signal, ...sessionId ? { sessionId } : {} };
|
|
104
|
-
const reasoning = thinking && thinking !== "off" ? thinking : void 0;
|
|
106
|
+
const options = { ...omitTemperature || ruleOmitsTemperature ? {} : { temperature }, maxRetries: MAX_RETRIES, signal, ...sessionId ? { sessionId } : {} };
|
|
105
107
|
return resolvedChoice || thinking ? models.completeSimple(model, context, { ...options, ...resolvedChoice ? { toolChoice: resolvedChoice } : {}, ...reasoning ? { reasoning } : {} }) : models.complete(model, context, options);
|
|
106
108
|
});
|
|
107
109
|
const raw = await this.traced(
|
|
108
110
|
{ origin, sessionId, answerId, currentUser, modelName, provider, temperature },
|
|
109
111
|
context,
|
|
110
|
-
() => this.withoutRejectedTemperature(
|
|
112
|
+
() => this.withoutRejectedTemperature({ provider, model: modelName, thinking: Boolean(reasoning) }, send)
|
|
111
113
|
);
|
|
112
114
|
if (raw.stopReason === "error" || raw.stopReason === "aborted") {
|
|
113
115
|
throw import_llm_error.LLMError.fromProvider(raw.errorMessage ?? `request ${raw.stopReason}`);
|
|
@@ -155,12 +157,13 @@ class LLMClient {
|
|
|
155
157
|
clearTimeout(timer);
|
|
156
158
|
}
|
|
157
159
|
}
|
|
158
|
-
async withoutRejectedTemperature(
|
|
160
|
+
async withoutRejectedTemperature(call, send) {
|
|
161
|
+
const key = `${call.provider}/${call.model}`;
|
|
159
162
|
const known = LLMClient.modelsWithoutTemperature.has(key);
|
|
160
163
|
const response = await this.waitingOnRateLimit(() => send(known));
|
|
161
164
|
if (known || response.stopReason !== "error" || !(0, import_llm_error.rejectsSamplingParameter)(response.errorMessage)) return response;
|
|
162
165
|
LLMClient.modelsWithoutTemperature.add(key);
|
|
163
|
-
this.logger.warn({
|
|
166
|
+
this.logger.warn({ ...call, error: response.errorMessage }, "[LLM Service] The model rejected the temperature setting, retrying without it. Add a rule in sampling-rules.ts to avoid this retry");
|
|
164
167
|
return this.waitingOnRateLimit(() => send(true));
|
|
165
168
|
}
|
|
166
169
|
async waitingOnRateLimit(run) {
|
|
@@ -7,6 +7,7 @@ import { createLLMCall } from "../../services/llmcalls/index.js";
|
|
|
7
7
|
import { toPiContext, fromPiMessage } from "./pi-ai-adapter";
|
|
8
8
|
import { numberSetting } from "../../common/utils/number-setting.js";
|
|
9
9
|
import { resolveModel, toModelRef } from "./model-resolution";
|
|
10
|
+
import { omitsTemperature } from "./sampling-rules";
|
|
10
11
|
import { LLMError, retryDelayMs, rejectsSamplingParameter } from "./llm-error";
|
|
11
12
|
const DEFAULT_TEMPERATURE = 0.7;
|
|
12
13
|
const MAX_RETRIES = 4;
|
|
@@ -67,15 +68,16 @@ class LLMClient {
|
|
|
67
68
|
const resolvedChoice = toolChoice === "required" ? REQUIRED_TOOL_CHOICE[model.api] : toolChoice;
|
|
68
69
|
if (toolChoice === "required" && !resolvedChoice) throw new Error(`[LLM Client] forced tool choice is not supported for api ${model.api}`);
|
|
69
70
|
const context = toPiContext({ messages, tools }, model);
|
|
71
|
+
const reasoning = thinking && thinking !== "off" ? thinking : void 0;
|
|
72
|
+
const ruleOmitsTemperature = omitsTemperature(provider, modelName, Boolean(reasoning));
|
|
70
73
|
const send = (omitTemperature) => this.withDeadline(thinking === "high" ? this.callTimeoutMs * HIGH_THINKING_TIMEOUT_FACTOR : this.callTimeoutMs, (signal) => {
|
|
71
|
-
const options = { ...omitTemperature ? {} : { temperature }, maxRetries: MAX_RETRIES, signal, ...sessionId ? { sessionId } : {} };
|
|
72
|
-
const reasoning = thinking && thinking !== "off" ? thinking : void 0;
|
|
74
|
+
const options = { ...omitTemperature || ruleOmitsTemperature ? {} : { temperature }, maxRetries: MAX_RETRIES, signal, ...sessionId ? { sessionId } : {} };
|
|
73
75
|
return resolvedChoice || thinking ? models.completeSimple(model, context, { ...options, ...resolvedChoice ? { toolChoice: resolvedChoice } : {}, ...reasoning ? { reasoning } : {} }) : models.complete(model, context, options);
|
|
74
76
|
});
|
|
75
77
|
const raw = await this.traced(
|
|
76
78
|
{ origin, sessionId, answerId, currentUser, modelName, provider, temperature },
|
|
77
79
|
context,
|
|
78
|
-
() => this.withoutRejectedTemperature(
|
|
80
|
+
() => this.withoutRejectedTemperature({ provider, model: modelName, thinking: Boolean(reasoning) }, send)
|
|
79
81
|
);
|
|
80
82
|
if (raw.stopReason === "error" || raw.stopReason === "aborted") {
|
|
81
83
|
throw LLMError.fromProvider(raw.errorMessage ?? `request ${raw.stopReason}`);
|
|
@@ -123,12 +125,13 @@ class LLMClient {
|
|
|
123
125
|
clearTimeout(timer);
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
|
-
async withoutRejectedTemperature(
|
|
128
|
+
async withoutRejectedTemperature(call, send) {
|
|
129
|
+
const key = `${call.provider}/${call.model}`;
|
|
127
130
|
const known = LLMClient.modelsWithoutTemperature.has(key);
|
|
128
131
|
const response = await this.waitingOnRateLimit(() => send(known));
|
|
129
132
|
if (known || response.stopReason !== "error" || !rejectsSamplingParameter(response.errorMessage)) return response;
|
|
130
133
|
LLMClient.modelsWithoutTemperature.add(key);
|
|
131
|
-
this.logger.warn({
|
|
134
|
+
this.logger.warn({ ...call, error: response.errorMessage }, "[LLM Service] The model rejected the temperature setting, retrying without it. Add a rule in sampling-rules.ts to avoid this retry");
|
|
132
135
|
return this.waitingOnRateLimit(() => send(true));
|
|
133
136
|
}
|
|
134
137
|
async waitingOnRateLimit(run) {
|
|
@@ -41,7 +41,7 @@ const RETRYABLE = {
|
|
|
41
41
|
};
|
|
42
42
|
const MAX_WAIT_MS = 6e4;
|
|
43
43
|
const SAMPLING_PARAMETER = /\b(?:temperature|top_p|top_k)\b/i;
|
|
44
|
-
const REJECTION = /unsupported|not supported|does not support|doesn't support|deprecated|not allowed|only the default|no longer|removed|cannot be|can't be|must be|invalid/i;
|
|
44
|
+
const REJECTION = /unsupported|not supported|does not support|doesn't support|deprecated|not allowed|only the default|may only|no longer|removed|cannot be|can't be|must be|invalid/i;
|
|
45
45
|
class LLMError extends Error {
|
|
46
46
|
code;
|
|
47
47
|
isRetryable;
|
|
@@ -17,7 +17,7 @@ const RETRYABLE = {
|
|
|
17
17
|
};
|
|
18
18
|
const MAX_WAIT_MS = 6e4;
|
|
19
19
|
const SAMPLING_PARAMETER = /\b(?:temperature|top_p|top_k)\b/i;
|
|
20
|
-
const REJECTION = /unsupported|not supported|does not support|doesn't support|deprecated|not allowed|only the default|no longer|removed|cannot be|can't be|must be|invalid/i;
|
|
20
|
+
const REJECTION = /unsupported|not supported|does not support|doesn't support|deprecated|not allowed|only the default|may only|no longer|removed|cannot be|can't be|must be|invalid/i;
|
|
21
21
|
class LLMError extends Error {
|
|
22
22
|
code;
|
|
23
23
|
isRetryable;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function omitsTemperature(provider: string, model: string, thinking: boolean): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var sampling_rules_exports = {};
|
|
20
|
+
__export(sampling_rules_exports, {
|
|
21
|
+
omitsTemperature: () => omitsTemperature
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(sampling_rules_exports);
|
|
24
|
+
const NO_TEMPERATURE = [
|
|
25
|
+
{ provider: "amazon-bedrock", model: /claude/, withThinking: true }
|
|
26
|
+
];
|
|
27
|
+
function omitsTemperature(provider, model, thinking) {
|
|
28
|
+
return NO_TEMPERATURE.some((rule) => rule.provider === provider && (!rule.model || rule.model.test(model)) && (!rule.withThinking || thinking));
|
|
29
|
+
}
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
omitsTemperature
|
|
33
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
const NO_TEMPERATURE = [
|
|
3
|
+
{ provider: "amazon-bedrock", model: /claude/, withThinking: true }
|
|
4
|
+
];
|
|
5
|
+
function omitsTemperature(provider, model, thinking) {
|
|
6
|
+
return NO_TEMPERATURE.some((rule) => rule.provider === provider && (!rule.model || rule.model.test(model)) && (!rule.withThinking || thinking));
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
omitsTemperature
|
|
10
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openloops",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "Open source harness for AI agents: a TypeScript runtime with persistence, tools, MCP trust, approvals and autonomous automations, where the loop is pluggable",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jose Barcos",
|