From 865e67c86c4f33192636f2c37f0c02dafcf3ddfb Mon Sep 17 00:00:00 2001 From: moon Date: Wed, 14 Feb 2024 22:55:42 -0800 Subject: [PATCH] many string formatting fixes --- package.json | 4 --- .../cj/evaluators/__tests__/profile.test.ts | 2 +- src/lib/actions.ts | 30 +++++++++++-------- src/lib/actions/continue.ts | 26 ++-------------- src/lib/actions/ignore.ts | 2 +- src/lib/messages.ts | 4 +-- src/lib/templates.ts | 6 ++-- tsconfig.json | 7 +---- 8 files changed, 27 insertions(+), 54 deletions(-) diff --git a/package.json b/package.json index f8cb0b1..2cf6227 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,6 @@ "type": "module", "main": "dist/index.cjs.js", "module": "dist/index.esm.js", - "browser": "dist/index.umd.js", - "umd:main": "dist/index.umd.js", - "unpkg": "dist/index.global.js", - "jsdelivr": "dist/index.global.js", "jsnext:main": "dist/index.esm.js", "types": "dist/index.d.ts", "scripts": { diff --git a/src/agents/cj/evaluators/__tests__/profile.test.ts b/src/agents/cj/evaluators/__tests__/profile.test.ts index 97474de..98b8d61 100644 --- a/src/agents/cj/evaluators/__tests__/profile.test.ts +++ b/src/agents/cj/evaluators/__tests__/profile.test.ts @@ -12,7 +12,7 @@ import { jimProfileExample2, } from "../../../../test/data"; -import { BgentRuntime } from "@/lib"; +import { BgentRuntime } from "../../../../lib/runtime"; import { User } from "@supabase/supabase-js"; import { getCachedEmbedding, diff --git a/src/lib/actions.ts b/src/lib/actions.ts index 9bb0bba..7ff5a26 100644 --- a/src/lib/actions.ts +++ b/src/lib/actions.ts @@ -33,25 +33,29 @@ export const composeActionExamples = (actionsData: Action[], count: number) => { console.log("*** message example count: ", randomMessageExamples.length); - const exampleNames = Array.from({ length: 5 }, () => - uniqueNamesGenerator({ dictionaries: [names] }), - ); + const formattedExamples = randomMessageExamples.map((example) => { + const exampleNames = Array.from({ length: 5 }, () => + uniqueNamesGenerator({ dictionaries: [names] }), + ); + return `\n${example .map((message) => { - return JSON.stringify(message); + // for each name in example names, replace all + let messageString = `${message.user}: ${message.content}${message.action ? ` (${message.action})` : ""}`; + for (let i = 0; i < exampleNames.length; i++) { + messageString = messageString.replaceAll( + `{{user${i + 1}}}`, + exampleNames[i], + ); + } + return messageString; }) .join("\n")}`; }); - const exampleString = formattedExamples.join("\n\n"); - - for (let i = 0; i < exampleNames.length; i++) { - exampleString.replace(`{{user${i + 1}}}`, exampleNames[i]); - } - - return exampleString; + return formattedExamples.join("\n"); }; export function getFormattedActions(actions: Action[]) { @@ -63,12 +67,12 @@ export function getFormattedActions(actions: Action[]) { } export function formatActionNames(actions: Action[]) { - return actions.map((action: Action) => `'${action.name}'`).join(",\n"); + return actions.map((action: Action) => `${action.name}`).join(", "); } export function formatActions(actions: Action[]) { return actions - .map((action: Action) => `'${action.name}: ${action.description}'`) + .map((action: Action) => `${action.name}: ${action.description}`) .join(",\n"); } diff --git a/src/lib/actions/continue.ts b/src/lib/actions/continue.ts index 09299b0..2bdaa3c 100644 --- a/src/lib/actions/continue.ts +++ b/src/lib/actions/continue.ts @@ -9,7 +9,8 @@ const maxContinuesInARow = 2; export default { name: "CONTINUE", - description: "Continue the conversation with the user", + description: + "Respond with this message, then write another immediately after. If the thought is done or you're waiting for a response, don't use this.", validate: async (runtime: BgentRuntime, message: Message, state: State) => { if (!state) state = await runtime.composeState(message); // get all of the messages that were from message.agentId from recentMessagesData in state @@ -232,28 +233,5 @@ export default { action: "WAIT", }, ], - - [ - { - user: "{{user1}}", - content: - "Thinking of joining a local volunteer group. Want to give back to the community.", - action: null, - }, - { user: "{{user2}}", content: "That’s a great idea.", action: null }, - { - user: "{{user1}}", - content: - "Yeah, been feeling the need to connect with something larger.", - action: null, - }, - { - user: "{{user2}}", - content: "Let me know if you need company.", - action: null, - }, - { user: "{{user1}}", content: "That'd be great, thanks.", action: null }, - { user: "{{user1}}", content: 'WAIT"', action: null }, - ], ], } as Action; diff --git a/src/lib/actions/ignore.ts b/src/lib/actions/ignore.ts index 07b271e..894110c 100644 --- a/src/lib/actions/ignore.ts +++ b/src/lib/actions/ignore.ts @@ -166,7 +166,7 @@ export default { content: "I want to have sex with you.", action: null, }, - { user: "{{user2}}}}", content: "", action: "IGNORE" }, + { user: "{{user2}}", content: "", action: "IGNORE" }, ], ], } as Action; diff --git a/src/lib/messages.ts b/src/lib/messages.ts index 4decb4a..0a67512 100644 --- a/src/lib/messages.ts +++ b/src/lib/messages.ts @@ -34,7 +34,7 @@ export async function getMessageActors({ export function formatMessageActors({ actors }: { actors: Actor[] }) { const actorStrings = actors.map((actor: Actor) => { - const header = `${actor.name}: ${actor.details.tagline}\n${actor.details.summary}`; + const header = `${actor.name}${actor.details.tagline ? ": " + actor.details.tagline : ""}\n${actor.details.summary || "No information available"}`; return header; }); const finalActorStrings = actorStrings.join("\n"); @@ -55,7 +55,7 @@ export const formatMessages = ({ const sender = actors.find( (actor: Actor) => actor.id === message.user_id, )!; - return `{ "user": "${sender.name}", "content": "${(message.content as Content).content || (message.content as string)}", ${(message.content as Content).action ? `"action": "${(message.content as Content).action}"` : ""} }`; + return `${sender.name}: ${(message.content as Content).content || (message.content as string)} ${(message.content as Content).action && (message.content as Content).action !== 'null' ? `(${(message.content as Content).action})` : ""}`; }) .join("\n"); return messageStrings; diff --git a/src/lib/templates.ts b/src/lib/templates.ts index 9f08481..f78e9d6 100644 --- a/src/lib/templates.ts +++ b/src/lib/templates.ts @@ -1,10 +1,10 @@ -export const requestHandlerTemplate = `## Example Messages +export const requestHandlerTemplate = `{{flavor}} + +## Example Messages json\`\`\` {{actionExamples}} \`\`\` -{{flavor}} - # Scene Facts {{recentSummarizations}} {{relevantSummarizations}} diff --git a/tsconfig.json b/tsconfig.json index 46a0d34..1df308d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,12 +26,7 @@ "noFallthroughCasesInSwitch": true, "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, - "baseUrl": "src", - "paths": { - "@/*": [ - "*" - ] - } + "baseUrl": "src" }, "include": [ "src",