Skip to content

Commit

Permalink
fix reflect test
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 14, 2024
1 parent 88ec459 commit 982b9b8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
25 changes: 12 additions & 13 deletions src/lib/evaluators/__tests__/reflect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,11 @@ describe("User Profile", () => {
const result = (await handler(runtime, message)) as string[];
const resultConcatenated = result.join("\n");

const state = await runtime.composeState(message);

console.log("************ state.recentMessages\n", state.recentMessages);
console.log("************ resultConcatenated\n", resultConcatenated);

console.log("Expecting the facts to contain programmer and Jim");
// const state = await runtime.composeState(message);
// console.log("************ state.recentMessages\n", state.recentMessages);
// console.log("************ resultConcatenated\n", resultConcatenated);

// console.log("Expecting the facts to contain programmer and Jim");
expect(resultConcatenated.toLowerCase()).toMatch(/programmer|startup/);
expect(resultConcatenated.toLowerCase()).toMatch(/jim/);

Expand All @@ -138,15 +136,16 @@ describe("User Profile", () => {
const result2 = (await handler(runtime, message)) as string[];
const resultConcatenated2 = result2.join("\n");

const state2 = await runtime.composeState(message);
// const state2 = await runtime.composeState(message);
// console.log("************ state.recentMessages\n", state2.recentMessages);
// console.log("************ resultConcatenated2\n", resultConcatenated2);
// console.log("Expecting the facts to contain francisco");

console.log("************ state.recentMessages\n", state2.recentMessages);
console.log("************ resultConcatenated2\n", resultConcatenated2);
console.log("Expecting the facts to contain francisco");
// expect result to ignore 'francisco' and '38' since they are already known
expect(resultConcatenated2.toLowerCase()).not.toMatch(/francisco/);
expect(resultConcatenated2.toLowerCase()).not.toMatch(/38/);

// expect result to not match 38
expect(resultConcatenated2.toLowerCase()).toMatch(/francisco/);
expect(resultConcatenated2.toLowerCase()).toMatch(/38/);
// expect result to contain 'married' since it is not already known
expect(resultConcatenated2.toLowerCase()).toMatch(/married/);
}, 60000);
});
17 changes: 14 additions & 3 deletions src/lib/evaluators/reflect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Extract any claims from the conversation in the ACTUAL scene that are not alread
- Status is pertinent to the current scene or character's immediate situation, also includes the character's thoughts, feelings, judgments or recommendations
- Response should be a JSON object array inside a JSON markdown block
- Ignore the examples when considering facts
- Include any factual detail, including where the user lives, works, or goes to school, what they do for a living, their hobbies, and any other relevant information
Correct response format:
\`\`\`json
Expand All @@ -112,7 +113,16 @@ Scene Dialog:
{{recentMessages}}
\`\`\`
INSTRUCTIONS: Extract any claims from the conversation in the scene that are not already present in the list of facts.`;
INSTRUCTIONS: Extract ALL claims from the conversation in the scene that are not already present in the list of facts.
Correct response format:
\`\`\`json
[
{claim: string, type: enum<fact|status>, in_bio: boolean, already_known: boolean },
{claim: string, type: enum<fact|status>, in_bio: boolean, already_known: boolean },
...
]
\`\`\``;

async function handler(runtime: BgentRuntime, message: Message) {
const state = (await runtime.composeState(message)) as State;
Expand Down Expand Up @@ -150,13 +160,13 @@ async function handler(runtime: BgentRuntime, message: Message) {
template,
});

if (runtime.debugMode) {
// if (runtime.debugMode) {
logger.log(context, {
title: "Reflection context",
frame: true,
color: "cyan",
});
}
// }

let reflections = null;

Expand All @@ -165,6 +175,7 @@ async function handler(runtime: BgentRuntime, message: Message) {
context,
stop: [],
});
console.log('reflectionText', reflectionText)
const parsedReflections = parseJsonArrayFromText(reflectionText);
if (parsedReflections) {
reflections = parsedReflections;
Expand Down
27 changes: 9 additions & 18 deletions src/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ const applyStyle = (self: { (...arguments_: any[]): any;[x: string]: any; "__@GE
Object.defineProperties(createChalk.prototype, styles2);

const chalk = createChalk({ level: 0 });
export const chalkStderr = createChalk({ level: stderrColor ? (stderrColor as { level?: number}).level : 0 });
export const chalkStderr = createChalk({ level: stderrColor ? (stderrColor as { level?: number }).level : 0 });

export {
stdoutColor as supportsColor,
Expand Down Expand Up @@ -700,25 +700,16 @@ class Logger {

frameMessage(message: string, title: string) {
const lines = message.split("\n");
const maxLength = Math.max(
...lines.map((line: string) => line.length),
title.length,
);
const topFrame = title
? this.frameChar.repeat(maxLength + 4) +
"\n" +
const frameHorizontalLength = 30;
const topFrame = this.frameChar.repeat(frameHorizontalLength + 4) +
" " +
this.frameChar +
" " +
title +
" ".repeat(maxLength - title.length + 1) +
this.frameChar
: this.frameChar.repeat(maxLength + 4);
const bottomFrame = this.frameChar.repeat(maxLength + 4);
const framedLines = lines.map(
(line: string) =>
`${this.frameChar} ${line} ${" ".repeat(maxLength - line.length)} ${this.frameChar}`,
);
return [topFrame, ...framedLines, bottomFrame].join("\n");
(title ?? 'log') +
" ".repeat(frameHorizontalLength - (title as string ?? 'log' as string).length + 1) +
this.frameChar.repeat(frameHorizontalLength + 4);
const bottomFrame = this.frameChar.repeat(frameHorizontalLength + 4);
return [topFrame, ...lines, bottomFrame].join("\n");
}
}

Expand Down

0 comments on commit 982b9b8

Please sign in to comment.