Skip to content

Commit

Permalink
many string formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 15, 2024
1 parent ba92d4f commit 865e67c
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 54 deletions.
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/agents/cj/evaluators/__tests__/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 17 additions & 13 deletions src/lib/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand All @@ -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");
}

Expand Down
26 changes: 2 additions & 24 deletions src/lib/actions/continue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
2 changes: 1 addition & 1 deletion src/lib/actions/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/templates.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export const requestHandlerTemplate = `## Example Messages
export const requestHandlerTemplate = `{{flavor}}
## Example Messages
json\`\`\`
{{actionExamples}}
\`\`\`
{{flavor}}
# Scene Facts
{{recentSummarizations}}
{{relevantSummarizations}}
Expand Down
7 changes: 1 addition & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": "src",
"paths": {
"@/*": [
"*"
]
}
"baseUrl": "src"
},
"include": [
"src",
Expand Down

0 comments on commit 865e67c

Please sign in to comment.