mw10013 / remix-cf-20240202

0 stars 0 forks source link

Add observation to chat history #11

Closed mw10013 closed 1 year ago

mw10013 commented 1 year ago
[chain/end] [1:chain:AgentExecutor] [2.92s] Exiting Chain run with output: {
  "output": "Keva Green's patient ID is \"kyHGADnvX3xbkU4V9ayaqh\".",
  "intermediateSteps": [
    {
      "action": {
        "tool": "getKevaGreenDetails",
        "toolInput": {},
        "log": "Invoking \"getKevaGreenDetails\" with {}\n",
        "messageLog": [
          {
            "lc": 1,
            "type": "constructor",
            "id": [
              "langchain",
              "schema",
              "AIMessage"
            ],
            "kwargs": {
              "content": "",
              "additional_kwargs": {
                "function_call": {
                  "name": "getKevaGreenDetails",
                  "arguments": "{}"
                }
              }
            }
          }
        ]
      },
      "observation": "{\"id\":\"19ad5913-4e34-4ac1-9781-46fd2a020f46\",\"resourceType\":\"Bundle\",\"type\":\"searchset\",\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"69efd2ea-1256-4ae7-b4ec-5d0160427185\",\"identifier\":[{\"value\":\"483749\",\"system\":\"urn:redox:redox-fhir-sandbox:MR\"}],\"active\":false,\"name\":[{\"use\":\"official\",\"given\":[\"Keva\"],\"family\":\"Green\"}],\"gender\":\"female\",\"birthDate\":\"1995-08-26\",\"deceasedDateTime\":null,\"address\":[{\"use\":\"home\",\"city\":\"Hillsboro\",\"line\":[\"932 Stehr Vista\"],\"state\":\"OR\",\"country\":\"US\",\"postalCode\":\"97123\"}],\"link\":[{\"type\":\"replaced-by\",\"other\":{\"reference\":\"Patient/81c2f5eb-f99f-40c4-b504-59483e6148d7\"}}],\"extension\":[{\"url\":\"http://hl7.org/fhir/us/core/StructureDefinition/us-core-race\",\"extension\":[{\"url\":\"text\",\"valueString\":\"White\"},{\"url\":\"ombCategory\",\"valueCoding\":{\"code\":\"2106-3\",\"system\":\"urn:oid:2.16.840.1.113883.6.238\",\"display\":\"White\"}}]}],\"meta\":{\"lastUpdated\":\"2022-10-05T16:03:06.633Z\"}},\"search\":{\"mode\":\"match\",\"score\":1}},{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"81c2f5eb-f99f-40c4-b504-59483e6148d7\",\"identifier\":[{\"value\":\"kyHGADnvX3xbkU4V9ayaqh\",\"system\":\"urn:redox:redox-fhir-sandbox:MR\"},{\"use\":\"secondary\",\"value\":\"483749\",\"system\":\"urn:redox:redox-fhir-sandbox:MR\"}],\"active\":true,\"name\":[{\"use\":\"official\",\"given\":[\"Keva\"],\"family\":\"Green\"}],\"telecom\":[{\"use\":\"home\",\"value\":\"+18088675302\",\"system\":\"phone\"},{\"value\":\"Keva.Green-95@test.net\",\"system\":\"email\"}],\"gender\":\"female\",\"birthDate\":\"1995-08-26\",\"deceasedDateTime\":null,\"address\":[{\"use\":\"home\",\"city\":\"Hillsboro\",\"line\":[\"932 Stehr Vista\"],\"state\":\"OR\",\"country\":\"US\",\"postalCode\":\"97123\"}],\"link\":[{\"type\":\"replaces\",\"other\":{\"reference\":\"Patient/69efd2ea-1256-4ae7-b4ec-5d0160427185\"}}],\"extension\":[{\"url\":\"http://hl7.org/fhir/us/core/StructureDefinition/us-core-race\",\"extension\":[{\"url\":\"text\",\"valueString\":\"White\"},{\"url\":\"ombCategory\",\"valueCoding\":{\"code\":\"2106-3\",\"system\":\"urn:oid:2.16.840.1.113883.6.238\",\"display\":\"White\"}}]}],\"meta\":{\"lastUpdated\":\"2022-12-01T21:57:23.879Z\"}},\"search\":{\"mode\":\"match\",\"score\":1}}],\"total\":2}"
    }
  ]
}
mw10013 commented 1 year ago
export interface BaseChatMemoryInput {
  chatHistory?: BaseChatMessageHistory;
  returnMessages?: boolean;
  inputKey?: string;
  outputKey?: string;
}

export interface BufferMemoryInput extends BaseChatMemoryInput {
  humanPrefix?: string;
  aiPrefix?: string;
  memoryKey?: string;
}

export abstract class BaseMemory;
export abstract class BaseChatMemory extends BaseMemory;

export class BufferMemory extends BaseChatMemory implements BufferMemoryInput {
  humanPrefix = "Human";

  aiPrefix = "AI";

  memoryKey = "history";

  constructor(fields?: BufferMemoryInput) {
    super({
      chatHistory: fields?.chatHistory,
      returnMessages: fields?.returnMessages ?? false,
      inputKey: fields?.inputKey,
      outputKey: fields?.outputKey,
    });
    this.humanPrefix = fields?.humanPrefix ?? this.humanPrefix;
    this.aiPrefix = fields?.aiPrefix ?? this.aiPrefix;
    this.memoryKey = fields?.memoryKey ?? this.memoryKey;
  }

  get memoryKeys() {
    return [this.memoryKey];
  }
}