Skip to content

Commit

Permalink
save context
Browse files Browse the repository at this point in the history
  • Loading branch information
gregreindel committed Jul 13, 2023
1 parent a790ae9 commit f5f6654
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion __tests__/unit/state/_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,17 @@ describe("llm-exe:state/BaseState", () => {
dialogue2.setUserMessage("This is the user message");
dialogue2.setAssistantMessage("Hello, this is the assistant");

state.createContextItem(createStateItem("mock-item", {test: "val"}))

expect(state.serialize()).toEqual({
attributes: {},
context: {},
context: {
"mock-item": {
class: "BaseStateItem",
name: "mock-item",
value: {"mock-item": { test: "val" }},
}
},
dialogues: {
chat: {
class: "Dialogue",
Expand Down
9 changes: 8 additions & 1 deletion src/state/_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export abstract class BaseState {

serialize() {
const dialogues: any = {};
const context: any = { ...this.context };
const context: any = {};
const attributes: any = { ...this.attributes };

const dialogueKeys = Object.keys(
Expand All @@ -73,6 +73,13 @@ export abstract class BaseState {
dialogues[dialogueKey] = this.dialogues[dialogueKey].serialize();
}

const contextKeys = Object.keys(
this.context
) as (keyof typeof this.context)[];
for (const contextKey of contextKeys) {
context[contextKey] = this.context[contextKey].serialize();
}

return {
dialogues,
context,
Expand Down

0 comments on commit f5f6654

Please sign in to comment.