Skip to content

Commit a1d44bf

Browse files
Merge pull request #67 from SmythOS/dev
hotFix : SDK Agent default model loading.
2 parents 6e4172f + c595eb0 commit a1d44bf

File tree

7 files changed

+79
-10
lines changed

7 files changed

+79
-10
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { SRE } from '@smythos/sre'; //Since we'ill
2+
import { Agent } from '@smythos/sdk';
3+
import path from 'path';
4+
import { fileURLToPath } from 'url';
5+
6+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
7+
const modelsPath = path.resolve(__dirname, '../agents-data/models.json');
8+
9+
//We initialize SRE with custom settings of the JSON ModelsProvider, in order to load our additional models
10+
SRE.init({
11+
ModelsProvider: {
12+
Connector: 'JSONModelsProvider',
13+
Settings: {
14+
models: modelsPath,
15+
mode: 'merge', //preserve smyth predefined models and add my custom models on top of them
16+
},
17+
},
18+
});
19+
20+
async function main() {
21+
const agent = new Agent({
22+
id: 'js-code-assistant',
23+
24+
name: 'JS Code Assistant',
25+
behavior: 'You are a JS code assistant. you answer any question by providing JS code output, you can use any library you want',
26+
model: 'gemma-3n-e4b',
27+
});
28+
29+
30+
const promptResult = await agent.prompt('Write a function that returns the sum of two numbers');
31+
32+
console.log(promptResult);
33+
34+
35+
}
36+
37+
main();

examples/agents-data/models.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"gemma-3n-e4b": {
3+
"provider": "OpenAI",
4+
"modelId": "google/gemma-3n-e4b",
5+
"baseURL": "http://localhost:1234/v1",
6+
7+
"tokens": 4096,
8+
"completionTokens": 1024,
9+
10+
"enabled": true,
11+
"features": ["text", "tools"],
12+
"credentials": "vault"
13+
}
14+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sre",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"description": "",
55
"author": "Alaa-eddine KADDOURI",
66
"license": "MIT",

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@smythos/sdk",
3-
"version": "1.0.32",
3+
"version": "1.0.33",
44
"description": "SRE SDK",
55
"keywords": [
66
"smythos",

packages/sdk/src/Agent/Agent.class.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import {
22
AccessCandidate,
33
AgentProcess,
44
BinaryInput,
5+
ConnectorService,
56
Conversation,
67
DEFAULT_TEAM_ID,
8+
SRE,
79
TLLMConnectorParams,
810
TLLMEvent,
911
TLLMModel,
@@ -344,11 +346,7 @@ export class Agent extends SDKObject {
344346

345347
const { model, ...rest } = this._settings;
346348

347-
if (typeof model === 'string') {
348-
this._data.defaultModel = findClosestModelInfo(model);
349-
} else {
350-
this._data.defaultModel = model as any;
351-
}
349+
this._data.defaultModel = model as any;
352350

353351
for (let key in rest) {
354352
this._data[key as keyof AgentData] = rest[key];
@@ -380,6 +378,26 @@ export class Agent extends SDKObject {
380378
DummyAccountHelper.addAgentToTeam(this._data.id, this._data.teamId);
381379
}
382380

381+
protected async init() {
382+
//if the SRE instance is not initializing, initialize it with default settings
383+
if (!SRE.initializing) SRE.init({});
384+
await SRE.ready();
385+
386+
const model = this._data.defaultModel;
387+
388+
const modelsProvider = ConnectorService.getModelsProviderConnector();
389+
const modelsProviderReq = modelsProvider.agent(this._data.id);
390+
391+
const models = await modelsProviderReq.getModels();
392+
393+
if (typeof model === 'string') {
394+
this._data.defaultModel = findClosestModelInfo(models, model);
395+
} else {
396+
this._data.defaultModel = model as any;
397+
}
398+
this._readyPromise.resolve(true);
399+
}
400+
383401
private _validateId(id: string) {
384402
//only accept alphanumeric, hyphens and underscores
385403
return id.length > 0 && id.length <= 64 && /^[a-zA-Z0-9_-]+$/.test(id);

packages/sdk/src/Core/SDKObject.class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { SRE } from '@smythos/sre';
1414
*/
1515
export class SDKObject {
1616
private _eventEmitter: EventEmitter;
17-
private _readyPromise: ControlledPromise<any>;
17+
protected _readyPromise: ControlledPromise<any>;
1818

1919
public get ready() {
2020
return this._readyPromise;

packages/sdk/src/LLM/Model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TCustomLLMModel, TLLMProvider, TLLMModel, models, SystemEvents } from '@smythos/sre';
1+
import { TCustomLLMModel, TLLMProvider, TLLMModel, SystemEvents } from '@smythos/sre';
22

33
import { adaptModelParams } from './utils';
44
import { TLLMInstanceParams } from './LLMInstance.class';
@@ -54,7 +54,7 @@ for (const provider of Object.keys(TLLMProvider)) {
5454
}) as TModelFactory;
5555
}
5656

57-
export function findClosestModelInfo(modelId: string) {
57+
export function findClosestModelInfo(models, modelId: string) {
5858
if (models[modelId]) {
5959
return models[modelId];
6060
}

0 commit comments

Comments
 (0)