Skip to content

Commit

Permalink
Add end session method (#177)
Browse files Browse the repository at this point in the history
* SDK regeneration

* chore: Remove duplicate collection name argument

* SDK regeneration

* SDK regeneration

* SDK regeneration

* SDK regeneration

* chore: Add example

* chore: Update fernignore

* chore: Update fernignore

* SDK regeneration

* SDK regeneration

* chore: Add client and memory

* chore: Ignore memory and client

* SDK regeneration

* chore: Add memory example, split up clients based on existing deployed sdk

* SDK regeneration

* fix: Attempt to fix imports

* fix: Attempt to fix imports take 2

* fix: Attempt to fix imports take 3

* fix: Attempt to fix imports take 4

* fix: Attempt to fix imports take 4

* fix: Attempt to fix imports take 5

* chore: Imports reorg

* chore: Imports reorg

* SDK regeneration

* chore: Update external clients

* chore: Update fernignore

* Update README.md

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

* SDK regeneration

* SDK regeneration

* SDK regeneration

* SDK regeneration

* SDK regeneration

* SDK regeneration

* feat: Set up langchain examples and classes

* SDK regeneration

* chore: Update examples

* SDK regeneration

* chore: Fix vector store example

* fix: Vector store

* fix: Langserve examples

* chore: Get langchain and memory examples to work, as well as chainlit

* SDK regeneration

* wip

* SDK regeneration

* SDK regeneration

* chore: Fix role types

* SDK regeneration

* chore: Add get summaries example

* SDK regeneration

* SDK regeneration

* SDK regeneration

* SDK regeneration

* chore: Fix examples

* SDK regeneration

* SDK regeneration

* SDK regeneration

* chore: Change package name, consolidate memory examples

* chore: set rc version

* chore: readme update

* chore: Fix langchain classes and linter

* chore: Remove test action dep

* chore: Add pyproject to fernignore

* chore: Lock poetry

* chore: remove api url from examples

* chore: Version downgrade (tmp)

* chore: Version downgrade (tmp)

* SDK regeneration

* SDK regeneration

* SDK regeneration

* chore: Update package name

* chore: Update v2 against cloud branch

* Rename package to zep_cloud (#172)

* chore: Add get summaries example

* SDK regeneration

* SDK regeneration

* SDK regeneration

* chore: Update package name

* chore: Update v2 against cloud branch

---------

Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>

* SDK regeneration

* chore: Update fernignore and bring back custom classes

* chore: Version bump

* SDK regeneration

* chore: Reintroduce gitignore update

* SDK regeneration

* chore: Version bump

* chore: Add end session example

---------

Signed-off-by: Pavlo Paliychuk <[email protected]>
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
  • Loading branch information
paul-paliychuk and fern-api[bot] authored May 14, 2024
1 parent 5db0854 commit 3d307c2
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 6 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ dist/
.mypy_cache/
__pycache__/
poetry.toml
examples/.env
.idea
.venv
6 changes: 5 additions & 1 deletion examples/chat_history/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,13 @@ async def main() -> None:
)
print("messages_result: ", messages_result)

# End session - this will trigger summarization and other background tasks on the completed session
print(f"\n5---end_session for Session: {session_id}")
await client.memory.end_session(session_id)

# Delete Memory for session
# Uncomment to run
print(f"\n5---deleteMemory for Session: {session_id}")
print(f"\n6---deleteMemory for Session: {session_id}")
# await client.memory.delete(session_id)


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "zep-cloud"
version = "1.0.1"
version = "1.0.2"
description = ""
readme = "README.md"
authors = []
Expand Down
2 changes: 1 addition & 1 deletion src/zep_cloud/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get_headers(self) -> typing.Dict[str, str]:
headers: typing.Dict[str, str] = {
"X-Fern-Language": "Python",
"X-Fern-SDK-Name": "zep-cloud",
"X-Fern-SDK-Version": "1.0.1",
"X-Fern-SDK-Version": "1.0.2",
}
headers["Authorization"] = f"Api-Key {self.api_key}"
return headers
Expand Down
162 changes: 162 additions & 0 deletions src/zep_cloud/memory/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,87 @@ def classify_session(
raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

def end_session(
self,
session_id: str,
*,
instruction: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> Session:
"""
End a session by ID
Parameters
----------
session_id : str
Session ID
instruction : typing.Optional[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
Session
OK
Examples
--------
from zep_cloud.client import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.memory.end_session(
session_id="sessionId",
)
"""
_request: typing.Dict[str, typing.Any] = {}
if instruction is not OMIT:
_request["instruction"] = instruction
_response = self._client_wrapper.httpx_client.request(
method="POST",
url=urllib.parse.urljoin(
f"{self._client_wrapper.get_base_url()}/", f"sessions/{jsonable_encoder(session_id)}/end"
),
params=jsonable_encoder(
request_options.get("additional_query_parameters") if request_options is not None else None
),
json=jsonable_encoder(_request)
if request_options is None or request_options.get("additional_body_parameters") is None
else {
**jsonable_encoder(_request),
**(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
},
headers=jsonable_encoder(
remove_none_from_dict(
{
**self._client_wrapper.get_headers(),
**(request_options.get("additional_headers", {}) if request_options is not None else {}),
}
)
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
if 200 <= _response.status_code < 300:
return pydantic_v1.parse_obj_as(Session, _response.json()) # type: ignore
if _response.status_code == 404:
raise NotFoundError(pydantic_v1.parse_obj_as(types_api_error_ApiError, _response.json())) # type: ignore
if _response.status_code == 500:
raise InternalServerError(
pydantic_v1.parse_obj_as(types_api_error_ApiError, _response.json()) # type: ignore
)
try:
_response_json = _response.json()
except JSONDecodeError:
raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

def extract_session_data(
self,
session_id: str,
Expand Down Expand Up @@ -1734,6 +1815,87 @@ async def classify_session(
raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

async def end_session(
self,
session_id: str,
*,
instruction: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> Session:
"""
End a session by ID
Parameters
----------
session_id : str
Session ID
instruction : typing.Optional[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
Session
OK
Examples
--------
from zep_cloud.client import AsyncZep
client = AsyncZep(
api_key="YOUR_API_KEY",
)
await client.memory.end_session(
session_id="sessionId",
)
"""
_request: typing.Dict[str, typing.Any] = {}
if instruction is not OMIT:
_request["instruction"] = instruction
_response = await self._client_wrapper.httpx_client.request(
method="POST",
url=urllib.parse.urljoin(
f"{self._client_wrapper.get_base_url()}/", f"sessions/{jsonable_encoder(session_id)}/end"
),
params=jsonable_encoder(
request_options.get("additional_query_parameters") if request_options is not None else None
),
json=jsonable_encoder(_request)
if request_options is None or request_options.get("additional_body_parameters") is None
else {
**jsonable_encoder(_request),
**(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
},
headers=jsonable_encoder(
remove_none_from_dict(
{
**self._client_wrapper.get_headers(),
**(request_options.get("additional_headers", {}) if request_options is not None else {}),
}
)
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
if 200 <= _response.status_code < 300:
return pydantic_v1.parse_obj_as(Session, _response.json()) # type: ignore
if _response.status_code == 404:
raise NotFoundError(pydantic_v1.parse_obj_as(types_api_error_ApiError, _response.json())) # type: ignore
if _response.status_code == 500:
raise InternalServerError(
pydantic_v1.parse_obj_as(types_api_error_ApiError, _response.json()) # type: ignore
)
try:
_response_json = _response.json()
except JSONDecodeError:
raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

async def extract_session_data(
self,
session_id: str,
Expand Down
1 change: 1 addition & 0 deletions src/zep_cloud/types/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Session(pydantic_v1.BaseModel):
classifications: typing.Optional[typing.Dict[str, str]] = None
created_at: typing.Optional[str] = None
deleted_at: typing.Optional[str] = None
ended_at: typing.Optional[str] = None
facts: typing.Optional[typing.List[str]] = None
id: typing.Optional[int] = None
metadata: typing.Optional[typing.Dict[str, typing.Any]] = None
Expand Down

0 comments on commit 3d307c2

Please sign in to comment.