Skip to content

Commit

Permalink
Update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
synw committed Mar 12, 2024
1 parent 0f482cc commit 854da65
Show file tree
Hide file tree
Showing 23 changed files with 479 additions and 35 deletions.
3 changes: 2 additions & 1 deletion packages/body/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@agent-smith/body",
"version": "0.0.4",
"version": "0.0.5",
"description": "An api to create human friendly agents",
"repository": "https://github.com/synw/agent-smith",
"scripts": {
Expand All @@ -13,6 +13,7 @@
},
"devDependencies": {
"@agent-smith/brain": "^0.0.3",
"@agent-smith/jobs": "^0.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/body/src/bodyinterfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MapStore } from "nanostores";
import { AgentBrain } from "@agent-smith/brain"
import { AgentJob } from "../../jobs/src/jobsinterfaces.js";
//import { AgentJob } from "../../jobs/src/jobsinterfaces.js";
import { AgentJob } from "@agent-smith/jobs";

/**
* Interface for the specification of an agent.
Expand Down
5 changes: 3 additions & 2 deletions packages/body/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { map } from 'nanostores'
import { AgentSmith, AgentState, type AgentSpec, type ConfirmFunction, type ConfirmOptions } from "./bodyinterfaces.js";
import { AgentBrain } from '@agent-smith/brain';
import { AgentJob } from "../../jobs/src/jobsinterfaces.js";
//import { AgentJob } from "../../jobs/src/jobsinterfaces.js";
import { AgentJob } from "@agent-smith/jobs";
import { AgentSmith, AgentState, type AgentSpec, type ConfirmFunction, type ConfirmOptions } from "./bodyinterfaces.js";

const useAgentSmith = (initParams: AgentSpec): AgentSmith => {
const name = initParams.name;
Expand Down
6 changes: 5 additions & 1 deletion packages/body/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useAgentSmith } from "./core.js";
import {
AgentSpec,
AgentSmith,
AgentSpec,
JsonData,
ConfirmFunction,
ConfirmOptions,
TalkFunction,
AgentState,
AgentInteractions,
} from "./bodyinterfaces.js";

export {
Expand All @@ -16,4 +18,6 @@ export {
ConfirmFunction,
ConfirmOptions,
TalkFunction,
AgentState,
AgentInteractions,
}
4 changes: 2 additions & 2 deletions packages/brain/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@agent-smith/brain",
"version": "0.0.3",
"description": "An api to ceate human friendly agents: the AI brain module",
"version": "0.0.5",
"description": "An api to create human friendly agents: the AI brain module",
"repository": "https://github.com/synw/agent-smith",
"scripts": {
"buildrl": "rm -rf dist/* && rollup -c",
Expand Down
21 changes: 15 additions & 6 deletions packages/brain/src/lm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ const useLmExpert = (spec: LmExpertSpec): LmExpert => {
delete completionParams.stop;
}
}
console.log("Params", inferenceParams);
console.log("Options", options);
if (options?.tsGrammar) {
completionParams.grammar = serializeGrammar(await compile(options.tsGrammar, "Grammar"));
}
Expand Down Expand Up @@ -103,7 +101,9 @@ const useLmExpert = (spec: LmExpertSpec): LmExpert => {
throw new Error(msg)
};
if (options?.verbose) {
console.log("Inference params", JSON.stringify(completionParams, null, " "));
console.log("Params", completionParams);
console.log("Options", options);
//console.log("Inference params", JSON.stringify(completionParams, null, " "));
}
const p = template.prompt(prompt);
state.setKey("isThinking", true);
Expand All @@ -112,9 +112,18 @@ const useLmExpert = (spec: LmExpertSpec): LmExpert => {
_parseJson = options.parseJson
}
let parseJsonFunc = (t: string) => JSON.parse(t);
// dirty patch
if (template.name == "chatml") {
parseJsonFunc = (t: string) => JSON.parse(t.replace("<|im_end|>", ""));
if (_parseJson) {
if (_lm.providerType == "koboldcpp") {
parseJsonFunc = (t: string) => {
//console.log("Start T", t);
let s = t.replace(/\\_/g, '_');
if (template.stop) {
s = s.replace(template.stop[0], "");
}
//console.log("End T", s, [t].includes('\\_'));
return JSON.parse(s)
};
}
}
const respData = await _lm.infer(p, completionParams, _parseJson, parseJsonFunc);
state.setKey("isStreaming", false);
Expand Down
7 changes: 5 additions & 2 deletions packages/jobs/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"name": "@agent-smith/jobs",
"version": "0.0.1",
"description": "An api to ceate human friendly agents: the jobs management module",
"version": "0.0.2",
"description": "An api to create human friendly agents: the jobs management module",
"repository": "https://github.com/synw/agent-smith",
"scripts": {
"buildrl": "rm -rf dist/* && rollup -c",
"build": "rm -rf dist/* && tsc",
"test": "jest --coverage",
"docs": "typedoc --entryPointStrategy expand"
},
"dependencies": {
"nanostores": "^0.10.0"
},
"devDependencies": {
"@agent-smith/tmem-jobs": "^0.0.2",
"@rollup/plugin-node-resolve": "^15.2.3",
Expand Down
12 changes: 6 additions & 6 deletions packages/jobs/src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const useAgentJob = (initParams: AgentJobSpec): AgentJob => {
});

const _runTask = async (t: AgentTask, params: any, autoComplete: boolean): Promise<Record<string, any>> => {
console.log("JOB RUN TASK", t.id, autoComplete, params);
//console.log("JOB RUN TASK", t.id, autoComplete, params);
//console.log("JOB running task:", t.name);
try {
let res: Record<string, any> = {};
Expand Down Expand Up @@ -61,7 +61,7 @@ const useAgentJob = (initParams: AgentJobSpec): AgentJob => {
}

const continueTask = async (params: any = {}): Promise<Record<string, any>> => {
console.log("JOB TASK CONTINUE -------- TASK PARAMS", params);
//console.log("JOB TASK CONTINUE -------- TASK PARAMS", params);
if (!state.get().isRunningTask) {
throw new Error('No task is running, can not continue');
}
Expand All @@ -70,7 +70,7 @@ const useAgentJob = (initParams: AgentJobSpec): AgentJob => {
}

const runTask = async (name: string, params: any = {}): Promise<Record<string, any>> => {
console.log("JOB TASK RUN -------- TASK PARAMS", params);
//console.log("JOB TASK RUN -------- TASK PARAMS", params);
if (state.get().isRunningTask) {
throw new Error('A task is already running');
}
Expand All @@ -80,23 +80,23 @@ const useAgentJob = (initParams: AgentJobSpec): AgentJob => {
}

const startTask = async (name: string, params: any = {}) => {
console.log("JOB TASK START -------- TASK PARAMS", params);
//console.log("JOB TASK START -------- TASK PARAMS", params);
if (state.get().isRunningTask) {
throw new Error('A task is already running');
}
await _startTask(name, params, false)
}

const reStartTask = async (name: string) => {
console.log("JOB TASK RERSTART", name);
//console.log("JOB TASK RERSTART", name);
if (state.get().isRunningTask) {
throw new Error('A task is already running');
}
await _startTask(name, {}, true)
}

const finishTask = async (completed: boolean, data?: any) => {
console.log("FINISH TASK", data);
//console.log("FINISH TASK", data);
const task = getTaskById(state.get().runningTask);
task.finish(completed, data);
state.setKey("isRunningTask", false);
Expand Down
7 changes: 3 additions & 4 deletions packages/jobs/src/task.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { map } from 'nanostores';
import { AgentTask, AgentTaskState, type AgentTaskSpec } from "./jobsinterfaces.js";


const useAgentTask = (spec: AgentTaskSpec): AgentTask => {
//console.log("Init task:", JSON.stringify(spec, null, " "));
//console.log("F", spec.run)
Expand All @@ -18,7 +17,7 @@ const useAgentTask = (spec: AgentTaskSpec): AgentTask => {
});

const _run = async (params: any, autoComplete: boolean): Promise<Record<string, any>> => {
console.log("TASK run task", id, autoComplete, params);
//console.log("TASK run task", id, autoComplete, params);
//console.log("RUN F", runFunc.name);
state.setKey("isRunning", true);
let data: Record<string, any> = {};
Expand All @@ -27,7 +26,7 @@ const useAgentTask = (spec: AgentTaskSpec): AgentTask => {
data = d;
}
if (autoComplete) {
console.log("AUTOCOMPLETE TASK", id);
//console.log("AUTOCOMPLETE TASK", id);
state.setKey("isRunning", false);
state.setKey("isCompleted", true);
}
Expand All @@ -43,7 +42,7 @@ const useAgentTask = (spec: AgentTaskSpec): AgentTask => {
}

const finish = (completed: boolean, data?: any): void => {
console.log("TASK finish task", id, completed, data);
//console.log("TASK finish task", id, completed, data);
state.setKey("isRunning", false);
state.setKey("isCompleted", completed);
if (data) {
Expand Down
46 changes: 46 additions & 0 deletions packages/smem/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@agent-smith/smem",
"version": "0.0.1",
"description": "An api to create human friendly agents: the semantic memory",
"repository": "https://github.com/synw/agent-smith",
"scripts": {
"buildrl": "rm -rf dist/* && rollup -c",
"build": "rm -rf dist/* && tsc",
"test": "jest --coverage",
"docs": "typedoc --entryPointStrategy expand"
},
"dependencies": {
"@xenova/transformers": "^2.15.1",
"apache-arrow": "^15.0.1",
"vectordb": "^0.4.12"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^20.11.20",
"markdown-it-replace-link": "^1.2.1",
"rollup": "^4.12.0",
"tslib": "^2.6.2",
"typedoc": "^0.25.8",
"typedoc-plugin-markdown": "^3.17.1",
"typedoc-plugin-rename-defaults": "^0.7.0",
"typescript": "^5.3.3"
},
"files": [
"dist"
],
"module": "./dist/main.js",
"types": "./dist/main.d.ts",
"type": "module",
"exports": {
".": {
"import": "./dist/main.js"
}
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"license": "MIT"
}
28 changes: 28 additions & 0 deletions packages/smem/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';

//const isProduction = !process.env.ROLLUP_WATCH;

export default {
input: 'src/main.ts',
output: [
{
file: 'dist/api.es.js',
format: 'esm'
},
{
file: 'dist/api.min.js',
format: 'iife',
name: '$agentbrain',
plugins: [terser()]
}],
plugins: [
typescript(),
resolve({
jsnext: true,
main: true,
browser: true,
}),
],
};
17 changes: 17 additions & 0 deletions packages/smem/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useSmem } from "./useSmem.js";
import { useSnode } from "./useSnode.js";
import {
SmemNodeFieldSchema,
SmemNodeSchema,
SmemNode,
Smem,
} from "./smeminterfaces.js"

export {
useSmem,
useSnode,
SmemNodeFieldSchema,
SmemNodeSchema,
SmemNode,
Smem,
}
40 changes: 40 additions & 0 deletions packages/smem/src/smeminterfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Connection, Table } from "vectordb";
import { Schema } from "apache-arrow";

interface SmemNodeFieldSchema {
name: string;
type: FieldDataType,
nullable?: boolean;
}

interface SmemNode {
table: Table;
vectorSourceCol: string;
open: () => Promise<Table>;
add: (data: Array<Record<string, unknown>>) => Promise<void>;
addRaw: (data: Array<Record<string, unknown>>) => Promise<void>;
upsert: (data: Array<Record<string, unknown>>, idCol?: string) => Promise<void>;
upsertRaw: (data: Array<Record<string, unknown>>, idCol?: string) => Promise<void>;
}

interface Smem {
nodes: Record<string, SmemNode>;
init: (dbpath: string) => Promise<Connection>;
node: (name: string, schema: SmemNodeSchema, vectorSourceCol: string) => Promise<SmemNode>;
nodeNames: () => Promise<string[]>;
nodeFromSchema: (name: string, schema: Schema, vectorSourceCol: string) => Promise<SmemNode>;
openTable: (name: string, sourceCol: string) => Promise<Table>;
vector: (text: string) => Promise<number[]>;
embed: (data: unknown[]) => Promise<number[][]>;
}

type SmemNodeSchema = Array<SmemNodeFieldSchema>;

type FieldDataType = "string" | "int" | "float" | "boolean";

export {
SmemNodeFieldSchema,
SmemNodeSchema,
SmemNode,
Smem,
}
Loading

0 comments on commit 854da65

Please sign in to comment.