From d6eb87141f1ed8530af34069728bb9c608b093f6 Mon Sep 17 00:00:00 2001 From: Pavlo Paliychuk Date: Mon, 17 Jun 2024 18:16:04 -0400 Subject: [PATCH] Extract method docs update (#192) * SDK regeneration * SDK regeneration * chore: Add search multiple sessions example * SDK regeneration * chore: Update search sessions example signature * SDK regeneration * SDK regeneration * implement sde; update ci to use python3.9 (#187) * wip * wip * ruff it * update ci * chore: Update Makefile with test coverage and linting commands * chore: Update Makefile with linting command and fix ruff check path * chore: Refactor memory client to use keyword arguments for optional parameters * chore: Add Makefile to .fernignore * Add extractor folder to fernignore Signed-off-by: Pavlo Paliychuk --------- Signed-off-by: Pavlo Paliychuk Co-authored-by: Pavlo Paliychuk * Version Bump Signed-off-by: Pavlo Paliychuk * SDK regeneration * SDK regeneration * chore: Update memory example to use new search interface * Document extract method (#191) * Facts search (#189) * SDK regeneration * SDK regeneration * chore: Add search multiple sessions example * SDK regeneration * chore: Update search sessions example signature * SDK regeneration * SDK regeneration * implement sde; update ci to use python3.9 (#187) * wip * wip * ruff it * update ci * chore: Update Makefile with test coverage and linting commands * chore: Update Makefile with linting command and fix ruff check path * chore: Refactor memory client to use keyword arguments for optional parameters * chore: Add Makefile to .fernignore * Add extractor folder to fernignore Signed-off-by: Pavlo Paliychuk --------- Signed-off-by: Pavlo Paliychuk Co-authored-by: Pavlo Paliychuk * Version Bump Signed-off-by: Pavlo Paliychuk * SDK regeneration * SDK regeneration * chore: Update memory example to use new search interface --------- Signed-off-by: Pavlo Paliychuk Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Co-authored-by: paulpaliychuk Co-authored-by: Daniel Chalef <131175+danielchalef@users.noreply.github.com> Co-authored-by: Pavlo Paliychuk * chore: Add code comments to extract methods * Update src/zep_cloud/external_clients/memory.py Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> Signed-off-by: Daniel Chalef <131175+danielchalef@users.noreply.github.com> --------- Signed-off-by: Pavlo Paliychuk Signed-off-by: Daniel Chalef <131175+danielchalef@users.noreply.github.com> Co-authored-by: Travis Beauvais Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Co-authored-by: Daniel Chalef <131175+danielchalef@users.noreply.github.com> Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --------- Signed-off-by: Pavlo Paliychuk Signed-off-by: Daniel Chalef <131175+danielchalef@users.noreply.github.com> Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Co-authored-by: Daniel Chalef <131175+danielchalef@users.noreply.github.com> Co-authored-by: Travis Beauvais Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --- src/zep_cloud/external_clients/memory.py | 82 ++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/zep_cloud/external_clients/memory.py b/src/zep_cloud/external_clients/memory.py index f394117..167fcda 100644 --- a/src/zep_cloud/external_clients/memory.py +++ b/src/zep_cloud/external_clients/memory.py @@ -24,6 +24,47 @@ def extract( last_n: int = 4, validate: bool = False, ): + """Extracts structured data from a session based on a ZepModel schema. + This method retrieves data based on a given model and session details. + It then returns the extracted and validated data as an instance of the given ZepModel. + + Parameters + ---------- + session_id: str + Session ID. + model: ZepModel + An instance of a ZepModel subclass defining the expected data structure and field types. + current_date_time: typing.Optional[datetime.datetime] + Your current date and time in ISO 8601 format including timezone. + This is used for determining relative dates. + last_n: typing.Optional[int] + The number of messages in the chat history from which to extract data. + validate: typing.Optional[bool] + Validate that the extracted data is present in the dialog and correct per the field description. + Mitigates hallucination, but is slower and may result in false negatives. + + Returns + ------- + ZepModel: An instance of the provided ZepModel subclass populated with the + extracted and validated data. + + Examples + -------- + class CustomerInfo(ZepModel): + name: Optional[ZepText] = Field(description="Customer name", default=None) + email: Optional[ZepEmail] = Field(description="Customer email", default=None) + signup_date: Optional[ZepDate] = Field(description="Customer Sign up date", default=None) + + client = AsyncMemoryClient(...) + + customer_data = await client.memory.extract( + session_id="session123", + model=CustomerInfo(), + current_date_time=datetime.datetime.now(), # Filter data up to now + ) + + print(customer_data.name) # Access extracted and validated customer name + """ model_schema = json.dumps(model.model_json_schema()) result = self.extract_data( @@ -51,6 +92,47 @@ async def extract( last_n: int = 4, validate: bool = False, ): + """Extracts structured data from a session based on a ZepModel schema. + This method retrieves data based on a given model and session details. + It then returns the extracted and validated data as an instance of the given ZepModel. + + Parameters + ---------- + session_id: str + Session ID. + model: ZepModel + An instance of a ZepModel subclass defining the expected data structure and field types. + current_date_time: typing.Optional[datetime.datetime] + Your current date and time in ISO 8601 format including timezone. + This is used for determining relative dates. + last_n: typing.Optional[int] + The number of messages in the chat history from which to extract data. + validate: typing.Optional[bool] + Validate that the extracted data is present in the dialog and correct per the field description. + Mitigates hallucination, but is slower and may result in false negatives. + + Returns + ------- + ZepModel: An instance of the provided ZepModel subclass populated with the + extracted and validated data. + + Examples + -------- + class CustomerInfo(ZepModel): + name: Optional[ZepText] = Field(description="Customer name", default=None) + name: Optional[ZepEmail] = Field(description="Customer email", default=None) + signup_date: Optional[ZepDate] = Field(description="Customer Sign up date", default=None) + + client = AsyncMemoryClient(...) + + customer_data = await client.memory.extract( + session_id="session123", + model=CustomerInfo(), + current_date_time=datetime.datetime.now(), # Filter data up to now + ) + + print(customer_data.name) # Access extracted and validated customer name + """ model_schema = json.dumps(model.model_json_schema()) result = await self.extract_data(