Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ export class ModelInfo {
}

export interface ModelFactory {
getModel<T extends Model<object, object>>(modelName: string): T;
getModel<T extends Model>(modelName: string): T;
}

export abstract class Model<TInput extends object, TOutput extends object> {
protected constructor(
public readonly info: ModelInfo,
protected invoker: ModelInvoker,
) {}
export abstract class Model<TInput = unknown, TOutput = unknown> {
static invoker: ModelInvoker | null = null;
protected constructor(public info: ModelInfo) {}

debug: boolean = false;

Expand All @@ -27,13 +25,17 @@ export abstract class Model<TInput extends object, TOutput extends object> {
* @returns The output object from the model.
*/
invoke(input: TInput): TOutput {
if (!Model.invoker) {
throw new Error("Model invoker is not set.");
}

const modelName = this.info.name;
const inputJson = JSON.stringify(input);
if (this.debug) {
console.debug(`Invoking ${modelName} model with input: ${inputJson}`);
}

const outputJson = this.invoker(modelName, inputJson);
const outputJson = Model.invoker(modelName, inputJson);
if (!outputJson) {
throw new Error(`Failed to invoke ${modelName} model.`);
}
Expand Down
12 changes: 6 additions & 6 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hypermode/models-as",
"version": "0.1.2",
"version": "0.1.5",
"description": "Hypermode Model Interface Library for AssemblyScript",
"author": "Hypermode, Inc.",
"license": "MIT",
Expand All @@ -17,7 +17,7 @@
"json-as": "^0.9.6"
},
"devDependencies": {
"@types/node": "^20.14.4",
"@types/node": "^20.14.5",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"assemblyscript": "^0.27.27",
Expand Down