Skip to content

Commit

Permalink
0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 14, 2024
1 parent de3b24e commit 3efe64f
Show file tree
Hide file tree
Showing 29 changed files with 668 additions and 160 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bgent",
"version": "0.0.2",
"version": "0.0.3",
"private": false,
"description": "bgent. because agent was taken.",
"type": "module",
Expand Down Expand Up @@ -60,7 +60,6 @@
"@rollup/plugin-json": "^6.1.0",
"@supabase/supabase-js": "^2.39.3",
"@tsndr/cloudflare-worker-jwt": "^2.2.1",
"chalk": "^5.3.0",
"dotenv": "^16.4.4",
"inquirer": "^9.2.14",
"ts-node": "^10.9.2"
Expand Down
11 changes: 4 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ export default defineConfig([
],
plugins: [
json(),
resolve(), // so Rollup can resolve packages
commonjs(), // so Rollup can convert commonjs to an ES module
typescript(), // so Rollup can convert TypeScript to JavaScript
resolve(),
commonjs(),
typescript(),
replace({
// see: https://github.com/rollup/plugins/tree/master/packages/replace#preventassignment
preventAssignment: true,
})
].filter(Boolean),
Expand All @@ -55,11 +54,9 @@ export default defineConfig([
],
plugins: [
json(),
typescript(), // so Rollup can convert TypeScript to JavaScript
typescript(),
replace({
// preserve to be handled by bundlers
__DEV__: `(process.env.NODE_ENV !== 'production')`,
// see: https://github.com/rollup/plugins/tree/master/packages/replace#preventassignment
preventAssignment: true,
})
].filter(Boolean),
Expand Down
15 changes: 3 additions & 12 deletions src/agents/cj/actions/__tests__/introduce.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// test creating an agent runtime
import dotenv from "dotenv";

import { type UUID } from "crypto";
Expand All @@ -20,7 +19,6 @@ import {
} from "../../../../test/cache";
dotenv.config();

// create a UUID of 0s
const zeroUuid = "00000000-0000-0000-0000-000000000000";

describe("Introduce Action", () => {
Expand Down Expand Up @@ -55,7 +53,6 @@ describe("Introduce Action", () => {
}

async function _testCreateProfile() {
// first, add all the memories for conversation
let conversation = GetTellMeAboutYourselfConversation1(user?.id as UUID);
for (let i = 0; i < conversation.length; i++) {
const c = conversation[i];
Expand All @@ -79,8 +76,7 @@ describe("Introduce Action", () => {

const handler = evaluator.handler!;

// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
let result = (await handler(runtime, message)) as unknown as string;
let result = (await handler(runtime, message)) as string;

expect(result.includes("programmer")).toBe(true);

Expand Down Expand Up @@ -113,7 +109,6 @@ describe("Introduce Action", () => {

const previousDescriptions = [jimProfileExample1, jimProfileExample2];

// for each description in previousDescriptions, add it to the memory
for (let i = 0; i < previousDescriptions.length; i++) {
const c = previousDescriptions[i];
const bakedMemory =
Expand All @@ -124,13 +119,11 @@ describe("Introduce Action", () => {
room_id,
});
await runtime.descriptionManager.createMemory(bakedMemory);
// wait for .2 seconds

await new Promise((resolve) => setTimeout(resolve, 250));
}

// TODO: fix this
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
result = (await handler(runtime, message)) as unknown as string;
result = (await handler(runtime, message)) as string;

expect(result.includes("38")).toBe(true);

Expand All @@ -141,12 +134,10 @@ describe("Introduce Action", () => {
expect(result.toLowerCase().includes("startup")).toBe(true);
}

// first, destroy all memories where the user_id is TestUser
await _cleanup();

await _testCreateProfile();

// then destroy all memories again
await _cleanup();
}, 60000);
});
4 changes: 1 addition & 3 deletions src/agents/cj/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { type Action } from "../../../lib/types";
import introduce from "./introduce";
/**
* A list of tools/actions available to the agent
*/

export default [introduce] as Action[];
3 changes: 0 additions & 3 deletions src/agents/cj/actions/introduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ const handler = async (runtime: BgentRuntime, message: Message) => {

let responseData = null;
for (let triesLeft = 3; triesLeft > 0; triesLeft--) {
// generate the response
const response = await runtime.completion({
context,
stop: [],
});

// parse the response, which is a json object block
const parsedResponse = parseJSONObjectFromText(response);

if (parsedResponse) {
Expand Down Expand Up @@ -109,7 +107,6 @@ export default {
_runtime: BgentRuntime,
_message: Message,
): Promise<boolean> => {
// immediatel resolve true
return await Promise.resolve(true);
},
description:
Expand Down
6 changes: 0 additions & 6 deletions src/agents/cj/evaluators/__tests__/details.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// test creating an agent runtime
import dotenv from "dotenv";

import { type UUID } from "crypto";
Expand All @@ -18,7 +17,6 @@ import {
} from "../../../../test/cache";
dotenv.config();

// create a UUID of 0s
const zeroUuid = "00000000-0000-0000-0000-000000000000";

describe("User Details", () => {
Expand Down Expand Up @@ -54,7 +52,6 @@ describe("User Details", () => {
}

async function _testGetDetails() {
// first, add all the memories for conversation
let conversation = GetTellMeAboutYourselfConversation1(user?.id as UUID);
for (let i = 0; i < conversation.length; i++) {
const c = conversation[i];
Expand All @@ -69,7 +66,6 @@ describe("User Details", () => {
embedding,
});
await runtime.messageManager.createMemory(bakedMemory);
// wait for .2 seconds
if (!embedding) {
writeCachedEmbedding(c.content, bakedMemory.embedding as number[]);
await new Promise((resolve) => setTimeout(resolve, 250));
Expand Down Expand Up @@ -125,12 +121,10 @@ describe("User Details", () => {
expect(locationIncludesSanFrancisco).toBe(true);
}

// first, destroy all memories where the user_id is TestUser
await _cleanup();

await _testGetDetails();

// then destroy all memories again
await _cleanup();
}, 60000);
});
4 changes: 1 addition & 3 deletions src/agents/cj/evaluators/__tests__/profile.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// test creating an agent runtime
import dotenv from "dotenv";

import { type UUID } from "crypto";
Expand All @@ -23,7 +22,6 @@ import evaluator from "../profile";

dotenv.config();

// create a UUID of 0s
const zeroUuid: UUID = "00000000-0000-0000-0000-000000000000";
let runtime: BgentRuntime;
let user: User;
Expand Down Expand Up @@ -164,7 +162,7 @@ describe("User Profile", () => {

expect(result.toLowerCase().includes("francisco")).toBe(true);

expect(result.toLowerCase().includes("startup")).toBe(true);
expect(result.toLowerCase().includes("startup") || result.toLowerCase().includes("programmer")).toBe(true);

const descriptions = await runtime.descriptionManager.getMemoriesByIds({
userIds: [message.senderId, message.agentId] as UUID[],
Expand Down
9 changes: 1 addition & 8 deletions src/agents/cj/evaluators/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Using the most recent conversation, get the details for the user's name, age, lo
Only include the values that can be extracted from the conversation.
Then respond with a JSON object containing a field for description in a JSON block formatted for markdown with this structure:
\`\`\`json
{ user: {{senderName}}, name?: string, age?: number, location?: string, gender?: string}
{ name?: string, age?: number, location?: string, gender?: string}
\`\`\`
Your response must include the JSON block.`;
Expand All @@ -30,13 +30,11 @@ const handler = async (runtime: BgentRuntime, message: Message) => {
let responseData = null;

for (let triesLeft = 3; triesLeft > 0; triesLeft--) {
// generate the response
const response = await runtime.completion({
context,
stop: [],
});

// parse the response, which is a json object block
const parsedResponse = parseJSONObjectFromText(response);

if (parsedResponse) {
Expand All @@ -61,7 +59,6 @@ const handler = async (runtime: BgentRuntime, message: Message) => {

const { user, name, age, location, gender } = responseData;

// find the user
const response = await runtime.supabase
.from("accounts")
.select("*")
Expand All @@ -74,7 +71,6 @@ const handler = async (runtime: BgentRuntime, message: Message) => {

const currentDetails = userRecord.details || {};

// for name, age, location, gender -- if the value exists and doesn't exist in currentDetails, add it
if (name && !currentDetails.name) {
currentDetails.name = name;
}
Expand All @@ -91,7 +87,6 @@ const handler = async (runtime: BgentRuntime, message: Message) => {
currentDetails.gender = gender;
}

// update the user with the new details
const { error: updateError } = await runtime.supabase
.from("accounts")
.update({ details: currentDetails })
Expand All @@ -100,7 +95,6 @@ const handler = async (runtime: BgentRuntime, message: Message) => {
console.error("error updating user", updateError);
}

// respond with the details
return {
name,
age,
Expand All @@ -115,7 +109,6 @@ export default {
_runtime: BgentRuntime,
_message: Message,
): Promise<boolean> => {
// immediatel resolve true
return await Promise.resolve(true);
},
description:
Expand Down
16 changes: 0 additions & 16 deletions src/agents/cj/evaluators/profile.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
// - Gather general information about the user

// - Info we want:

// Basics / Logistics
// - Name
// - Gender
// - Age
// - Location

// Deeper
// - What is important to you in a connection?
// - Describe the best aspects of your best connection.
// - Describe what went well and what went poorly.
// - How much do they value interests and hobbies vs other things

import { type UUID } from "crypto";
import { getRelationship, type BgentRuntime } from "../../../lib";
import { composeContext } from "../../../lib/context";
Expand Down
10 changes: 1 addition & 9 deletions src/agents/cj/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import actions from "./actions";
import evaluators from "./evaluators";
import flavor from "./flavor";

// main entry point for the agent
const onMessage = async (
message: Message,
runtime: BgentRuntime,
state?: State,
) => {
const { content: senderContent, senderId, agentId } = message;

// if userIds is not defined, set it to [senderId, agentId]
if (!message.userIds) {
message.userIds = [senderId!, agentId!];
}
Expand Down Expand Up @@ -47,7 +45,6 @@ class Route {
path;
handler;

// handler is an async function which takes HandlerArgs and returns Promise<Response>
constructor({
path = /^/,
handler,
Expand All @@ -68,7 +65,6 @@ const routes: Route[] = [
return;
}

// parse the body from the request
const message = await req.json();

const runtime = new BgentRuntime({
Expand Down Expand Up @@ -113,7 +109,6 @@ const routes: Route[] = [
return;
}

// parse the body from the request
const message = (await req.json()) as Message;

const runtime = new BgentRuntime({
Expand Down Expand Up @@ -219,7 +214,6 @@ async function handleRequest(
}
}

// Default handler if no other routes are called
return _setHeaders(
new Response(
JSON.stringify({ content: "No handler found for this path" }),
Expand All @@ -241,9 +235,8 @@ export const fetch = async (
) => {
try {
const res = (await handleRequest(request, env)) as Response;
return _setHeaders(res); // Ensure _setHeaders modifies the response and returns it
return _setHeaders(res);
} catch (error) {
// Catch any errors that occur during handling and return a Response object
return new Response(JSON.stringify({ error: (error as Error).message }), {
status: 500,
headers: { "Content-Type": "application/json" },
Expand Down Expand Up @@ -288,7 +281,6 @@ function _setHeaders(res: Response) {
];

for (const { key, value } of defaultHeaders) {
// if res.headers doesnt contain, add
if (!res.headers.has(key)) res.headers.append(key, value);
}
return res;
Expand Down
3 changes: 0 additions & 3 deletions src/agents/simple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import logger from "../../lib/logger";
import { BgentRuntime } from "../../lib/runtime";
import { type Content, type Message, type State } from "../../lib/types";

// main entry point for the agent
const onMessage = async (
message: Message,
runtime: BgentRuntime,
state?: State,
) => {
const { content: senderContent, senderId, agentId } = message;

// if userIds is not defined, set it to [senderId, agentId]
if (!message.userIds) {
message.userIds = [senderId!, agentId!];
}
Expand Down Expand Up @@ -43,7 +41,6 @@ class Route {
path;
handler;

// handler is an async function which takes HandlerArgs and returns Promise<Response>
constructor({
path = /^/,
handler,
Expand Down
1 change: 0 additions & 1 deletion src/lib/__tests__/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { getCachedEmbedding, writeCachedEmbedding } from "../../test/cache";
import { createRuntime } from "../../test/createRuntime";
import { getRelationship } from "../relationships";
import { type BgentRuntime } from "../runtime";
// import { type Message } from '../types'

dotenv.config();

Expand Down
2 changes: 0 additions & 2 deletions src/lib/__tests__/memory.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// memory.test.ts

import { type User } from "@supabase/supabase-js";
import { type UUID } from "crypto";
import dotenv from "dotenv";
Expand Down
Loading

0 comments on commit 3efe64f

Please sign in to comment.