Skip to content

Commit

Permalink
Extract method docs update (#192)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Signed-off-by: Pavlo Paliychuk <[email protected]>
Co-authored-by: Pavlo Paliychuk <[email protected]>

* Version Bump

Signed-off-by: Pavlo Paliychuk <[email protected]>

* 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 <[email protected]>

---------

Signed-off-by: Pavlo Paliychuk <[email protected]>
Co-authored-by: Pavlo Paliychuk <[email protected]>

* Version Bump

Signed-off-by: Pavlo Paliychuk <[email protected]>

* SDK regeneration

* SDK regeneration

* chore: Update memory example to use new search interface

---------

Signed-off-by: Pavlo Paliychuk <[email protected]>
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
Co-authored-by: paulpaliychuk <[email protected]>
Co-authored-by: Daniel Chalef <[email protected]>
Co-authored-by: Pavlo Paliychuk <[email protected]>

* 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 <[email protected]>

---------

Signed-off-by: Pavlo Paliychuk <[email protected]>
Signed-off-by: Daniel Chalef <[email protected]>
Co-authored-by: Travis Beauvais <[email protected]>
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
Co-authored-by: Daniel Chalef <[email protected]>
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

---------

Signed-off-by: Pavlo Paliychuk <[email protected]>
Signed-off-by: Daniel Chalef <[email protected]>
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
Co-authored-by: Daniel Chalef <[email protected]>
Co-authored-by: Travis Beauvais <[email protected]>
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
  • Loading branch information
5 people authored Jun 17, 2024
1 parent a26ec34 commit d6eb871
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/zep_cloud/external_clients/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d6eb871

Please sign in to comment.