@sprucelabs/sprucebot-llm 14.2.0 → 14.2.2
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.
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { Log } from '@sprucelabs/spruce-skill-utils';
|
|
1
2
|
import { LlmAdapter } from '../../llm.types';
|
|
2
3
|
export default class LlmAdapterLoaderImpl implements LlmAdapterLoader {
|
|
3
4
|
static Class?: new (adapterName: ValidAdapterName) => LlmAdapterLoader;
|
|
4
5
|
static VALID_ADAPTERS: string[];
|
|
5
6
|
private adapterName;
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
private log?;
|
|
8
|
+
protected constructor(adapterName: ValidAdapterName, log?: Log);
|
|
9
|
+
static Loader(log?: Log): LlmAdapterLoader;
|
|
8
10
|
Adapter(): LlmAdapter;
|
|
9
11
|
private constructorsByName;
|
|
10
12
|
}
|
|
@@ -9,32 +9,40 @@ const AnthropicAdapter_1 = __importDefault(require("./AnthropicAdapter"));
|
|
|
9
9
|
const OllamaAdapter_1 = __importDefault(require("./OllamaAdapter"));
|
|
10
10
|
const OpenAiAdapter_1 = __importDefault(require("./OpenAiAdapter"));
|
|
11
11
|
class LlmAdapterLoaderImpl {
|
|
12
|
-
constructor(adapterName) {
|
|
12
|
+
constructor(adapterName, log) {
|
|
13
13
|
this.constructorsByName = {
|
|
14
14
|
openai: (key, options) => {
|
|
15
15
|
return OpenAiAdapter_1.default.Adapter(key, {
|
|
16
16
|
...options,
|
|
17
17
|
reasoningEffort: process.env
|
|
18
18
|
.SPRUCE_LLM_REASONING_EFFORT,
|
|
19
|
+
log: this.log?.buildLog('OpenAiAdapter'),
|
|
19
20
|
});
|
|
20
21
|
},
|
|
21
22
|
anthropic: (key, options) => {
|
|
22
|
-
|
|
23
|
+
const opts = {
|
|
23
24
|
...options,
|
|
24
25
|
thinking: process.env.SPRUCE_LLM_THINKING === 'true',
|
|
25
26
|
maxTokens: parseInt(process.env.SPRUCE_LLM_MAX_TOKENS, 10),
|
|
27
|
+
};
|
|
28
|
+
this.log?.info('Loading Anthropic adapter with options', JSON.stringify(opts, null, 2));
|
|
29
|
+
return AnthropicAdapter_1.default.Adapter(key, {
|
|
30
|
+
...opts,
|
|
31
|
+
log: this.log?.buildLog('AnthropicAdapter'),
|
|
26
32
|
});
|
|
27
33
|
},
|
|
28
34
|
ollama: (_key, options) => {
|
|
29
35
|
return OllamaAdapter_1.default.Adapter({
|
|
30
36
|
...options,
|
|
31
37
|
think: process.env.SPRUCE_LLM_THINKING === 'true',
|
|
38
|
+
log: this.log?.buildLog('OllamaAdapter'),
|
|
32
39
|
});
|
|
33
40
|
},
|
|
34
41
|
};
|
|
35
42
|
this.adapterName = adapterName;
|
|
43
|
+
this.log = log;
|
|
36
44
|
}
|
|
37
|
-
static Loader() {
|
|
45
|
+
static Loader(log) {
|
|
38
46
|
const { env: { SPRUCE_LLM_ADAPTER }, } = (0, schema_1.assertOptions)({
|
|
39
47
|
env: process.env,
|
|
40
48
|
}, ['env.SPRUCE_LLM_ADAPTER']);
|
|
@@ -50,7 +58,7 @@ class LlmAdapterLoaderImpl {
|
|
|
50
58
|
env: process.env,
|
|
51
59
|
}, ['env.SPRUCE_LLM_MAX_TOKENS']);
|
|
52
60
|
}
|
|
53
|
-
return new (this.Class ?? this)(name);
|
|
61
|
+
return new (this.Class ?? this)(name, log);
|
|
54
62
|
}
|
|
55
63
|
Adapter() {
|
|
56
64
|
const key = process.env.SPRUCE_LLM_API_KEY;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { Log } from '@sprucelabs/spruce-skill-utils';
|
|
1
2
|
import { LlmAdapter } from '../../llm.types';
|
|
2
3
|
export default class LlmAdapterLoaderImpl implements LlmAdapterLoader {
|
|
3
4
|
static Class?: new (adapterName: ValidAdapterName) => LlmAdapterLoader;
|
|
4
5
|
static VALID_ADAPTERS: string[];
|
|
5
6
|
private adapterName;
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
private log?;
|
|
8
|
+
protected constructor(adapterName: ValidAdapterName, log?: Log);
|
|
9
|
+
static Loader(log?: Log): LlmAdapterLoader;
|
|
8
10
|
Adapter(): LlmAdapter;
|
|
9
11
|
private constructorsByName;
|
|
10
12
|
}
|
|
@@ -4,22 +4,28 @@ import AnthropicAdapter from './AnthropicAdapter.js';
|
|
|
4
4
|
import OllamaAdapter from './OllamaAdapter.js';
|
|
5
5
|
import OpenAiAdapter from './OpenAiAdapter.js';
|
|
6
6
|
class LlmAdapterLoaderImpl {
|
|
7
|
-
constructor(adapterName) {
|
|
7
|
+
constructor(adapterName, log) {
|
|
8
8
|
this.constructorsByName = {
|
|
9
9
|
openai: (key, options) => {
|
|
10
|
+
var _a;
|
|
10
11
|
return OpenAiAdapter.Adapter(key, Object.assign(Object.assign({}, options), { reasoningEffort: process.env
|
|
11
|
-
.SPRUCE_LLM_REASONING_EFFORT }));
|
|
12
|
+
.SPRUCE_LLM_REASONING_EFFORT, log: (_a = this.log) === null || _a === void 0 ? void 0 : _a.buildLog('OpenAiAdapter') }));
|
|
12
13
|
},
|
|
13
14
|
anthropic: (key, options) => {
|
|
14
|
-
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const opts = Object.assign(Object.assign({}, options), { thinking: process.env.SPRUCE_LLM_THINKING === 'true', maxTokens: parseInt(process.env.SPRUCE_LLM_MAX_TOKENS, 10) });
|
|
17
|
+
(_a = this.log) === null || _a === void 0 ? void 0 : _a.info('Loading Anthropic adapter with options', JSON.stringify(opts, null, 2));
|
|
18
|
+
return AnthropicAdapter.Adapter(key, Object.assign(Object.assign({}, opts), { log: (_b = this.log) === null || _b === void 0 ? void 0 : _b.buildLog('AnthropicAdapter') }));
|
|
15
19
|
},
|
|
16
20
|
ollama: (_key, options) => {
|
|
17
|
-
|
|
21
|
+
var _a;
|
|
22
|
+
return OllamaAdapter.Adapter(Object.assign(Object.assign({}, options), { think: process.env.SPRUCE_LLM_THINKING === 'true', log: (_a = this.log) === null || _a === void 0 ? void 0 : _a.buildLog('OllamaAdapter') }));
|
|
18
23
|
},
|
|
19
24
|
};
|
|
20
25
|
this.adapterName = adapterName;
|
|
26
|
+
this.log = log;
|
|
21
27
|
}
|
|
22
|
-
static Loader() {
|
|
28
|
+
static Loader(log) {
|
|
23
29
|
var _a;
|
|
24
30
|
const { env: { SPRUCE_LLM_ADAPTER }, } = assertOptions({
|
|
25
31
|
env: process.env,
|
|
@@ -36,7 +42,7 @@ class LlmAdapterLoaderImpl {
|
|
|
36
42
|
env: process.env,
|
|
37
43
|
}, ['env.SPRUCE_LLM_MAX_TOKENS']);
|
|
38
44
|
}
|
|
39
|
-
return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(name);
|
|
45
|
+
return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(name, log);
|
|
40
46
|
}
|
|
41
47
|
Adapter() {
|
|
42
48
|
const key = process.env.SPRUCE_LLM_API_KEY;
|