From efe616cc023739b641862f89707e9393d61e119b Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Wed, 19 Jun 2024 18:38:04 +0000 Subject: [PATCH 01/10] SDK regeneration --- src/zep_cloud/__init__.py | 4 ++-- src/zep_cloud/memory/__init__.py | 3 --- src/zep_cloud/memory/client.py | 10 +++++----- src/zep_cloud/memory/types/__init__.py | 5 ----- .../memory/types/memory_get_request_memory_type.py | 7 ------- src/zep_cloud/types/__init__.py | 2 ++ src/zep_cloud/types/memory_type.py | 5 +++++ 7 files changed, 14 insertions(+), 22 deletions(-) delete mode 100644 src/zep_cloud/memory/types/__init__.py delete mode 100644 src/zep_cloud/memory/types/memory_get_request_memory_type.py create mode 100644 src/zep_cloud/types/memory_type.py diff --git a/src/zep_cloud/__init__.py b/src/zep_cloud/__init__.py index 55bc264e..3419b6cc 100644 --- a/src/zep_cloud/__init__.py +++ b/src/zep_cloud/__init__.py @@ -14,6 +14,7 @@ Fact, Memory, MemorySearchResult, + MemoryType, Message, MessageListResponse, Question, @@ -34,7 +35,6 @@ from .errors import BadRequestError, ConflictError, InternalServerError, NotFoundError, UnauthorizedError from . import document, memory, user from .environment import ZepEnvironment -from .memory import MemoryGetRequestMemoryType from .version import __version__ __all__ = [ @@ -53,8 +53,8 @@ "Fact", "InternalServerError", "Memory", - "MemoryGetRequestMemoryType", "MemorySearchResult", + "MemoryType", "Message", "MessageListResponse", "NotFoundError", diff --git a/src/zep_cloud/memory/__init__.py b/src/zep_cloud/memory/__init__.py index b590d250..f3ea2659 100644 --- a/src/zep_cloud/memory/__init__.py +++ b/src/zep_cloud/memory/__init__.py @@ -1,5 +1,2 @@ # This file was auto-generated by Fern from our API Definition. -from .types import MemoryGetRequestMemoryType - -__all__ = ["MemoryGetRequestMemoryType"] diff --git a/src/zep_cloud/memory/client.py b/src/zep_cloud/memory/client.py index fba052b7..16da8cb5 100644 --- a/src/zep_cloud/memory/client.py +++ b/src/zep_cloud/memory/client.py @@ -19,6 +19,7 @@ from ..types.end_sessions_response import EndSessionsResponse from ..types.memory import Memory from ..types.memory_search_result import MemorySearchResult +from ..types.memory_type import MemoryType from ..types.message import Message from ..types.message_list_response import MessageListResponse from ..types.question import Question @@ -29,7 +30,6 @@ from ..types.session_search_response import SessionSearchResponse from ..types.success_response import SuccessResponse from ..types.summary_list_response import SummaryListResponse -from .types.memory_get_request_memory_type import MemoryGetRequestMemoryType # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -638,7 +638,7 @@ def get( self, session_id: str, *, - memory_type: typing.Optional[MemoryGetRequestMemoryType] = None, + memory_type: typing.Optional[MemoryType] = None, lastn: typing.Optional[int] = None, request_options: typing.Optional[RequestOptions] = None, ) -> Memory: @@ -650,7 +650,7 @@ def get( session_id : str The ID of the session for which to retrieve memory. - memory_type : typing.Optional[MemoryGetRequestMemoryType] + memory_type : typing.Optional[MemoryType] The type of memory to retrieve: perpetual, summary_retriever, or message_window. Defaults to perpetual. lastn : typing.Optional[int] @@ -1781,7 +1781,7 @@ async def get( self, session_id: str, *, - memory_type: typing.Optional[MemoryGetRequestMemoryType] = None, + memory_type: typing.Optional[MemoryType] = None, lastn: typing.Optional[int] = None, request_options: typing.Optional[RequestOptions] = None, ) -> Memory: @@ -1793,7 +1793,7 @@ async def get( session_id : str The ID of the session for which to retrieve memory. - memory_type : typing.Optional[MemoryGetRequestMemoryType] + memory_type : typing.Optional[MemoryType] The type of memory to retrieve: perpetual, summary_retriever, or message_window. Defaults to perpetual. lastn : typing.Optional[int] diff --git a/src/zep_cloud/memory/types/__init__.py b/src/zep_cloud/memory/types/__init__.py deleted file mode 100644 index 90de6bca..00000000 --- a/src/zep_cloud/memory/types/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - -from .memory_get_request_memory_type import MemoryGetRequestMemoryType - -__all__ = ["MemoryGetRequestMemoryType"] diff --git a/src/zep_cloud/memory/types/memory_get_request_memory_type.py b/src/zep_cloud/memory/types/memory_get_request_memory_type.py deleted file mode 100644 index c830b454..00000000 --- a/src/zep_cloud/memory/types/memory_get_request_memory_type.py +++ /dev/null @@ -1,7 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - -import typing - -MemoryGetRequestMemoryType = typing.Union[ - typing.Literal["perpetual", "summary_retriever", "message_window"], typing.Any -] diff --git a/src/zep_cloud/types/__init__.py b/src/zep_cloud/types/__init__.py index 984db93f..6f3008df 100644 --- a/src/zep_cloud/types/__init__.py +++ b/src/zep_cloud/types/__init__.py @@ -13,6 +13,7 @@ from .fact import Fact from .memory import Memory from .memory_search_result import MemorySearchResult +from .memory_type import MemoryType from .message import Message from .message_list_response import MessageListResponse from .question import Question @@ -44,6 +45,7 @@ "Fact", "Memory", "MemorySearchResult", + "MemoryType", "Message", "MessageListResponse", "Question", diff --git a/src/zep_cloud/types/memory_type.py b/src/zep_cloud/types/memory_type.py new file mode 100644 index 00000000..42deafea --- /dev/null +++ b/src/zep_cloud/types/memory_type.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +MemoryType = typing.Union[typing.Literal["perpetual", "summary_retriever", "message_window"], typing.Any] From 92bcc24fff3593dd71415a0b9d4a498e87841ce9 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 20:32:44 +0000 Subject: [PATCH 02/10] SDK regeneration --- src/zep_cloud/core/client_wrapper.py | 2 +- src/zep_cloud/types/memory.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/zep_cloud/core/client_wrapper.py b/src/zep_cloud/core/client_wrapper.py index aa680cd6..f6d367b2 100644 --- a/src/zep_cloud/core/client_wrapper.py +++ b/src/zep_cloud/core/client_wrapper.py @@ -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.5", + "X-Fern-SDK-Version": "1.0.6", } headers["Authorization"] = f"Api-Key {self.api_key}" return headers diff --git a/src/zep_cloud/types/memory.py b/src/zep_cloud/types/memory.py index cb2e6429..4dfc249a 100644 --- a/src/zep_cloud/types/memory.py +++ b/src/zep_cloud/types/memory.py @@ -5,6 +5,7 @@ from ..core.datetime_utils import serialize_datetime from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +from .fact import Fact from .message import Message from .summary import Summary @@ -13,6 +14,7 @@ class Memory(pydantic_v1.BaseModel): facts: typing.Optional[typing.List[str]] = pydantic_v1.Field(default=None) """ Most recent list of facts derived from the session. Included only with perpetual memory type. + Deprecated: Facts will be deprecated in future releases and relevant_facts should be used instead. """ messages: typing.Optional[typing.List[Message]] = pydantic_v1.Field(default=None) @@ -25,6 +27,7 @@ class Memory(pydantic_v1.BaseModel): A dictionary containing metadata associated with the memory. """ + relevant_facts: typing.Optional[typing.List[Fact]] = None relevant_summaries: typing.Optional[typing.List[Summary]] = pydantic_v1.Field(default=None) """ Summary list result from Summary Retriever Memory Type. From 21a843db4513f1e320f5c00c0aa6a53397d873cb Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Tue, 2 Jul 2024 19:56:20 +0000 Subject: [PATCH 03/10] SDK regeneration From 2b4570f242c30aae992aac62e4f7f8a1ad510969 Mon Sep 17 00:00:00 2001 From: paulpaliychuk Date: Tue, 2 Jul 2024 15:59:38 -0400 Subject: [PATCH 04/10] chore: Bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 09b2015d..1e3f0a2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "zep-cloud" -version = "1.0.5" +version = "1.0.6" description = "" readme = "README.md" authors = [] From 46d49b356ef12217c84c24d96614c0af507b3b8c Mon Sep 17 00:00:00 2001 From: paulpaliychuk Date: Mon, 15 Jul 2024 13:10:50 -0400 Subject: [PATCH 05/10] chore: Bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 1e3f0a2d..a636626f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "zep-cloud" -version = "1.0.6" +version = "1.0.7" description = "" readme = "README.md" authors = [] From 2982f0f2b66c886ba6cd171e9236a06df65bcb76 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:12:30 +0000 Subject: [PATCH 06/10] SDK regeneration --- src/zep_cloud/__init__.py | 11 +- src/zep_cloud/base_client.py | 3 + src/zep_cloud/core/client_wrapper.py | 2 +- src/zep_cloud/fact/__init__.py | 2 + src/zep_cloud/fact/client.py | 117 ++++++++ src/zep_cloud/memory/client.py | 275 +++++++++++++++++- src/zep_cloud/types/__init__.py | 8 + src/zep_cloud/types/fact.py | 1 + src/zep_cloud/types/fact_rating_examples.py | 31 ++ .../types/fact_rating_instruction.py | 45 +++ src/zep_cloud/types/models_fact_response.py | 30 ++ src/zep_cloud/types/models_facts_response.py | 30 ++ src/zep_cloud/types/session.py | 2 + 13 files changed, 549 insertions(+), 8 deletions(-) create mode 100644 src/zep_cloud/fact/__init__.py create mode 100644 src/zep_cloud/fact/client.py create mode 100644 src/zep_cloud/types/fact_rating_examples.py create mode 100644 src/zep_cloud/types/fact_rating_instruction.py create mode 100644 src/zep_cloud/types/models_fact_response.py create mode 100644 src/zep_cloud/types/models_facts_response.py diff --git a/src/zep_cloud/__init__.py b/src/zep_cloud/__init__.py index 3419b6cc..c811a71b 100644 --- a/src/zep_cloud/__init__.py +++ b/src/zep_cloud/__init__.py @@ -12,11 +12,15 @@ EndSessionResponse, EndSessionsResponse, Fact, + FactRatingExamples, + FactRatingInstruction, Memory, MemorySearchResult, MemoryType, Message, MessageListResponse, + ModelsFactResponse, + ModelsFactsResponse, Question, RoleType, SearchScope, @@ -33,7 +37,7 @@ UserListResponse, ) from .errors import BadRequestError, ConflictError, InternalServerError, NotFoundError, UnauthorizedError -from . import document, memory, user +from . import document, fact, memory, user from .environment import ZepEnvironment from .version import __version__ @@ -51,12 +55,16 @@ "EndSessionResponse", "EndSessionsResponse", "Fact", + "FactRatingExamples", + "FactRatingInstruction", "InternalServerError", "Memory", "MemorySearchResult", "MemoryType", "Message", "MessageListResponse", + "ModelsFactResponse", + "ModelsFactsResponse", "NotFoundError", "Question", "RoleType", @@ -76,6 +84,7 @@ "ZepEnvironment", "__version__", "document", + "fact", "memory", "user", ] diff --git a/src/zep_cloud/base_client.py b/src/zep_cloud/base_client.py index 763c164a..6be81c69 100644 --- a/src/zep_cloud/base_client.py +++ b/src/zep_cloud/base_client.py @@ -9,6 +9,7 @@ from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from .document.client import AsyncDocumentClient, DocumentClient from .environment import ZepEnvironment +from .fact.client import AsyncFactClient, FactClient from .memory.client import AsyncMemoryClient, MemoryClient from .user.client import AsyncUserClient, UserClient @@ -75,6 +76,7 @@ def __init__( ) self.document = DocumentClient(client_wrapper=self._client_wrapper) self.memory = MemoryClient(client_wrapper=self._client_wrapper) + self.fact = FactClient(client_wrapper=self._client_wrapper) self.user = UserClient(client_wrapper=self._client_wrapper) @@ -140,6 +142,7 @@ def __init__( ) self.document = AsyncDocumentClient(client_wrapper=self._client_wrapper) self.memory = AsyncMemoryClient(client_wrapper=self._client_wrapper) + self.fact = AsyncFactClient(client_wrapper=self._client_wrapper) self.user = AsyncUserClient(client_wrapper=self._client_wrapper) diff --git a/src/zep_cloud/core/client_wrapper.py b/src/zep_cloud/core/client_wrapper.py index f6d367b2..9f6e3690 100644 --- a/src/zep_cloud/core/client_wrapper.py +++ b/src/zep_cloud/core/client_wrapper.py @@ -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.6", + "X-Fern-SDK-Version": "1.0.7", } headers["Authorization"] = f"Api-Key {self.api_key}" return headers diff --git a/src/zep_cloud/fact/__init__.py b/src/zep_cloud/fact/__init__.py new file mode 100644 index 00000000..f3ea2659 --- /dev/null +++ b/src/zep_cloud/fact/__init__.py @@ -0,0 +1,2 @@ +# This file was auto-generated by Fern from our API Definition. + diff --git a/src/zep_cloud/fact/client.py b/src/zep_cloud/fact/client.py new file mode 100644 index 00000000..69cc6584 --- /dev/null +++ b/src/zep_cloud/fact/client.py @@ -0,0 +1,117 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing +from json.decoder import JSONDecodeError + +from ..core.api_error import ApiError as core_api_error_ApiError +from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper +from ..core.jsonable_encoder import jsonable_encoder +from ..core.pydantic_utilities import pydantic_v1 +from ..core.request_options import RequestOptions +from ..errors.internal_server_error import InternalServerError +from ..errors.not_found_error import NotFoundError +from ..types.api_error import ApiError as types_api_error_ApiError + + +class FactClient: + def __init__(self, *, client_wrapper: SyncClientWrapper): + self._client_wrapper = client_wrapper + + def delete_a_fact_for_the_given_uuid( + self, fact_uuid: str, *, request_options: typing.Optional[RequestOptions] = None + ) -> str: + """ + delete a fact + + Parameters + ---------- + fact_uuid : str + Fact UUID + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + str + Deleted + + Examples + -------- + from zep_cloud.client import Zep + + client = Zep( + api_key="YOUR_API_KEY", + ) + client.fact.delete_a_fact_for_the_given_uuid( + fact_uuid="factUUID", + ) + """ + _response = self._client_wrapper.httpx_client.request( + f"facts/{jsonable_encoder(fact_uuid)}", method="DELETE", request_options=request_options + ) + if 200 <= _response.status_code < 300: + return pydantic_v1.parse_obj_as(str, _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) + + +class AsyncFactClient: + def __init__(self, *, client_wrapper: AsyncClientWrapper): + self._client_wrapper = client_wrapper + + async def delete_a_fact_for_the_given_uuid( + self, fact_uuid: str, *, request_options: typing.Optional[RequestOptions] = None + ) -> str: + """ + delete a fact + + Parameters + ---------- + fact_uuid : str + Fact UUID + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + str + Deleted + + Examples + -------- + from zep_cloud.client import AsyncZep + + client = AsyncZep( + api_key="YOUR_API_KEY", + ) + await client.fact.delete_a_fact_for_the_given_uuid( + fact_uuid="factUUID", + ) + """ + _response = await self._client_wrapper.httpx_client.request( + f"facts/{jsonable_encoder(fact_uuid)}", method="DELETE", request_options=request_options + ) + if 200 <= _response.status_code < 300: + return pydantic_v1.parse_obj_as(str, _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) diff --git a/src/zep_cloud/memory/client.py b/src/zep_cloud/memory/client.py index 16da8cb5..10ed7e16 100644 --- a/src/zep_cloud/memory/client.py +++ b/src/zep_cloud/memory/client.py @@ -17,11 +17,14 @@ from ..types.classify_session_response import ClassifySessionResponse from ..types.end_session_response import EndSessionResponse from ..types.end_sessions_response import EndSessionsResponse +from ..types.fact_rating_instruction import FactRatingInstruction from ..types.memory import Memory from ..types.memory_search_result import MemorySearchResult from ..types.memory_type import MemoryType from ..types.message import Message from ..types.message_list_response import MessageListResponse +from ..types.models_fact_response import ModelsFactResponse +from ..types.models_facts_response import ModelsFactsResponse from ..types.question import Question from ..types.search_scope import SearchScope from ..types.search_type import SearchType @@ -39,10 +42,58 @@ class MemoryClient: def __init__(self, *, client_wrapper: SyncClientWrapper): self._client_wrapper = client_wrapper + def get_fact( + self, fact_uuid: str, *, request_options: typing.Optional[RequestOptions] = None + ) -> ModelsFactResponse: + """ + get fact by uuid + + Parameters + ---------- + fact_uuid : str + Fact UUID + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + ModelsFactResponse + The fact with the specified UUID. + + Examples + -------- + from zep_cloud.client import Zep + + client = Zep( + api_key="YOUR_API_KEY", + ) + client.memory.get_fact( + fact_uuid="factUUID", + ) + """ + _response = self._client_wrapper.httpx_client.request( + f"facts/{jsonable_encoder(fact_uuid)}", method="GET", request_options=request_options + ) + if 200 <= _response.status_code < 300: + return pydantic_v1.parse_obj_as(ModelsFactResponse, _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 add_session( self, *, session_id: str, + fact_rating_instruction: typing.Optional[FactRatingInstruction] = OMIT, metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, user_id: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, @@ -55,6 +106,9 @@ def add_session( session_id : str The unique identifier of the session. + fact_rating_instruction : typing.Optional[FactRatingInstruction] + Optional instruction to use for fact rating. + metadata : typing.Optional[typing.Dict[str, typing.Any]] The metadata associated with the session. @@ -83,7 +137,12 @@ def add_session( _response = self._client_wrapper.httpx_client.request( "sessions", method="POST", - json={"metadata": metadata, "session_id": session_id, "user_id": user_id}, + json={ + "fact_rating_instruction": fact_rating_instruction, + "metadata": metadata, + "session_id": session_id, + "user_id": user_id, + }, request_options=request_options, omit=OMIT, ) @@ -226,6 +285,7 @@ def search_sessions( self, *, limit: typing.Optional[int] = None, + min_fact_rating: typing.Optional[float] = OMIT, min_score: typing.Optional[float] = OMIT, mmr_lambda: typing.Optional[float] = OMIT, record_filter: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, @@ -244,6 +304,8 @@ def search_sessions( limit : typing.Optional[int] The maximum number of search results to return. Defaults to None (no limit). + min_fact_rating : typing.Optional[float] + min_score : typing.Optional[float] mmr_lambda : typing.Optional[float] @@ -284,6 +346,7 @@ def search_sessions( method="POST", params={"limit": limit}, json={ + "min_fact_rating": min_fact_rating, "min_score": min_score, "mmr_lambda": mmr_lambda, "record_filter": record_filter, @@ -358,6 +421,7 @@ def update_session( session_id: str, *, metadata: typing.Dict[str, typing.Any], + fact_rating_instruction: typing.Optional[FactRatingInstruction] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> Session: """ @@ -371,6 +435,10 @@ def update_session( metadata : typing.Dict[str, typing.Any] The metadata to update + fact_rating_instruction : typing.Optional[FactRatingInstruction] + Optional instruction to use for fact rating. + Fact rating instructions can not be unset. + request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -394,7 +462,7 @@ def update_session( _response = self._client_wrapper.httpx_client.request( f"sessions/{jsonable_encoder(session_id)}", method="PATCH", - json={"metadata": metadata}, + json={"fact_rating_instruction": fact_rating_instruction, "metadata": metadata}, request_options=request_options, omit=OMIT, ) @@ -634,12 +702,70 @@ def extract_data( 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 get_session_facts( + self, + session_id: str, + *, + min_rating: typing.Optional[float] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> typing.List[typing.List[ModelsFactsResponse]]: + """ + get facts for a session + + Parameters + ---------- + session_id : str + Session ID + + min_rating : typing.Optional[float] + Minimum rating by which to filter facts + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + typing.List[typing.List[ModelsFactsResponse]] + The facts for the session. + + Examples + -------- + from zep_cloud.client import Zep + + client = Zep( + api_key="YOUR_API_KEY", + ) + client.memory.get_session_facts( + session_id="sessionId", + ) + """ + _response = self._client_wrapper.httpx_client.request( + f"sessions/{jsonable_encoder(session_id)}/facts", + method="GET", + params={"minRating": min_rating}, + request_options=request_options, + ) + if 200 <= _response.status_code < 300: + return pydantic_v1.parse_obj_as(typing.List[typing.List[ModelsFactsResponse]], _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 get( self, session_id: str, *, memory_type: typing.Optional[MemoryType] = None, lastn: typing.Optional[int] = None, + min_rating: typing.Optional[float] = None, request_options: typing.Optional[RequestOptions] = None, ) -> Memory: """ @@ -656,6 +782,9 @@ def get( lastn : typing.Optional[int] The number of most recent memory entries to retrieve. + min_rating : typing.Optional[float] + The minimum rating by which to filter facts + request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -678,7 +807,7 @@ def get( _response = self._client_wrapper.httpx_client.request( f"sessions/{jsonable_encoder(session_id)}/memory", method="GET", - params={"memoryType": memory_type, "lastn": lastn}, + params={"memoryType": memory_type, "lastn": lastn, "minRating": min_rating}, request_options=request_options, ) if 200 <= _response.status_code < 300: @@ -994,6 +1123,7 @@ def search( *, limit: typing.Optional[int] = None, metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, + min_fact_rating: typing.Optional[float] = OMIT, min_score: typing.Optional[float] = OMIT, mmr_lambda: typing.Optional[float] = OMIT, search_scope: typing.Optional[SearchScope] = OMIT, @@ -1015,6 +1145,8 @@ def search( metadata : typing.Optional[typing.Dict[str, typing.Any]] Metadata Filter + min_fact_rating : typing.Optional[float] + min_score : typing.Optional[float] mmr_lambda : typing.Optional[float] @@ -1050,6 +1182,7 @@ def search( params={"limit": limit}, json={ "metadata": metadata, + "min_fact_rating": min_fact_rating, "min_score": min_score, "mmr_lambda": mmr_lambda, "search_scope": search_scope, @@ -1182,10 +1315,58 @@ class AsyncMemoryClient: def __init__(self, *, client_wrapper: AsyncClientWrapper): self._client_wrapper = client_wrapper + async def get_fact( + self, fact_uuid: str, *, request_options: typing.Optional[RequestOptions] = None + ) -> ModelsFactResponse: + """ + get fact by uuid + + Parameters + ---------- + fact_uuid : str + Fact UUID + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + ModelsFactResponse + The fact with the specified UUID. + + Examples + -------- + from zep_cloud.client import AsyncZep + + client = AsyncZep( + api_key="YOUR_API_KEY", + ) + await client.memory.get_fact( + fact_uuid="factUUID", + ) + """ + _response = await self._client_wrapper.httpx_client.request( + f"facts/{jsonable_encoder(fact_uuid)}", method="GET", request_options=request_options + ) + if 200 <= _response.status_code < 300: + return pydantic_v1.parse_obj_as(ModelsFactResponse, _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 add_session( self, *, session_id: str, + fact_rating_instruction: typing.Optional[FactRatingInstruction] = OMIT, metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, user_id: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, @@ -1198,6 +1379,9 @@ async def add_session( session_id : str The unique identifier of the session. + fact_rating_instruction : typing.Optional[FactRatingInstruction] + Optional instruction to use for fact rating. + metadata : typing.Optional[typing.Dict[str, typing.Any]] The metadata associated with the session. @@ -1226,7 +1410,12 @@ async def add_session( _response = await self._client_wrapper.httpx_client.request( "sessions", method="POST", - json={"metadata": metadata, "session_id": session_id, "user_id": user_id}, + json={ + "fact_rating_instruction": fact_rating_instruction, + "metadata": metadata, + "session_id": session_id, + "user_id": user_id, + }, request_options=request_options, omit=OMIT, ) @@ -1369,6 +1558,7 @@ async def search_sessions( self, *, limit: typing.Optional[int] = None, + min_fact_rating: typing.Optional[float] = OMIT, min_score: typing.Optional[float] = OMIT, mmr_lambda: typing.Optional[float] = OMIT, record_filter: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, @@ -1387,6 +1577,8 @@ async def search_sessions( limit : typing.Optional[int] The maximum number of search results to return. Defaults to None (no limit). + min_fact_rating : typing.Optional[float] + min_score : typing.Optional[float] mmr_lambda : typing.Optional[float] @@ -1427,6 +1619,7 @@ async def search_sessions( method="POST", params={"limit": limit}, json={ + "min_fact_rating": min_fact_rating, "min_score": min_score, "mmr_lambda": mmr_lambda, "record_filter": record_filter, @@ -1501,6 +1694,7 @@ async def update_session( session_id: str, *, metadata: typing.Dict[str, typing.Any], + fact_rating_instruction: typing.Optional[FactRatingInstruction] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> Session: """ @@ -1514,6 +1708,10 @@ async def update_session( metadata : typing.Dict[str, typing.Any] The metadata to update + fact_rating_instruction : typing.Optional[FactRatingInstruction] + Optional instruction to use for fact rating. + Fact rating instructions can not be unset. + request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -1537,7 +1735,7 @@ async def update_session( _response = await self._client_wrapper.httpx_client.request( f"sessions/{jsonable_encoder(session_id)}", method="PATCH", - json={"metadata": metadata}, + json={"fact_rating_instruction": fact_rating_instruction, "metadata": metadata}, request_options=request_options, omit=OMIT, ) @@ -1777,12 +1975,70 @@ async def extract_data( 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 get_session_facts( + self, + session_id: str, + *, + min_rating: typing.Optional[float] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> typing.List[typing.List[ModelsFactsResponse]]: + """ + get facts for a session + + Parameters + ---------- + session_id : str + Session ID + + min_rating : typing.Optional[float] + Minimum rating by which to filter facts + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + typing.List[typing.List[ModelsFactsResponse]] + The facts for the session. + + Examples + -------- + from zep_cloud.client import AsyncZep + + client = AsyncZep( + api_key="YOUR_API_KEY", + ) + await client.memory.get_session_facts( + session_id="sessionId", + ) + """ + _response = await self._client_wrapper.httpx_client.request( + f"sessions/{jsonable_encoder(session_id)}/facts", + method="GET", + params={"minRating": min_rating}, + request_options=request_options, + ) + if 200 <= _response.status_code < 300: + return pydantic_v1.parse_obj_as(typing.List[typing.List[ModelsFactsResponse]], _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 get( self, session_id: str, *, memory_type: typing.Optional[MemoryType] = None, lastn: typing.Optional[int] = None, + min_rating: typing.Optional[float] = None, request_options: typing.Optional[RequestOptions] = None, ) -> Memory: """ @@ -1799,6 +2055,9 @@ async def get( lastn : typing.Optional[int] The number of most recent memory entries to retrieve. + min_rating : typing.Optional[float] + The minimum rating by which to filter facts + request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -1821,7 +2080,7 @@ async def get( _response = await self._client_wrapper.httpx_client.request( f"sessions/{jsonable_encoder(session_id)}/memory", method="GET", - params={"memoryType": memory_type, "lastn": lastn}, + params={"memoryType": memory_type, "lastn": lastn, "minRating": min_rating}, request_options=request_options, ) if 200 <= _response.status_code < 300: @@ -2139,6 +2398,7 @@ async def search( *, limit: typing.Optional[int] = None, metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, + min_fact_rating: typing.Optional[float] = OMIT, min_score: typing.Optional[float] = OMIT, mmr_lambda: typing.Optional[float] = OMIT, search_scope: typing.Optional[SearchScope] = OMIT, @@ -2160,6 +2420,8 @@ async def search( metadata : typing.Optional[typing.Dict[str, typing.Any]] Metadata Filter + min_fact_rating : typing.Optional[float] + min_score : typing.Optional[float] mmr_lambda : typing.Optional[float] @@ -2195,6 +2457,7 @@ async def search( params={"limit": limit}, json={ "metadata": metadata, + "min_fact_rating": min_fact_rating, "min_score": min_score, "mmr_lambda": mmr_lambda, "search_scope": search_scope, diff --git a/src/zep_cloud/types/__init__.py b/src/zep_cloud/types/__init__.py index 6f3008df..087d4968 100644 --- a/src/zep_cloud/types/__init__.py +++ b/src/zep_cloud/types/__init__.py @@ -11,11 +11,15 @@ from .end_session_response import EndSessionResponse from .end_sessions_response import EndSessionsResponse from .fact import Fact +from .fact_rating_examples import FactRatingExamples +from .fact_rating_instruction import FactRatingInstruction from .memory import Memory from .memory_search_result import MemorySearchResult from .memory_type import MemoryType from .message import Message from .message_list_response import MessageListResponse +from .models_fact_response import ModelsFactResponse +from .models_facts_response import ModelsFactsResponse from .question import Question from .role_type import RoleType from .search_scope import SearchScope @@ -43,11 +47,15 @@ "EndSessionResponse", "EndSessionsResponse", "Fact", + "FactRatingExamples", + "FactRatingInstruction", "Memory", "MemorySearchResult", "MemoryType", "Message", "MessageListResponse", + "ModelsFactResponse", + "ModelsFactsResponse", "Question", "RoleType", "SearchScope", diff --git a/src/zep_cloud/types/fact.py b/src/zep_cloud/types/fact.py index 2d70e9fb..3664eb06 100644 --- a/src/zep_cloud/types/fact.py +++ b/src/zep_cloud/types/fact.py @@ -10,6 +10,7 @@ class Fact(pydantic_v1.BaseModel): created_at: typing.Optional[str] = None fact: typing.Optional[str] = None + rating: typing.Optional[float] = None uuid_: typing.Optional[str] = pydantic_v1.Field(alias="uuid", default=None) def json(self, **kwargs: typing.Any) -> str: diff --git a/src/zep_cloud/types/fact_rating_examples.py b/src/zep_cloud/types/fact_rating_examples.py new file mode 100644 index 00000000..7e7679cb --- /dev/null +++ b/src/zep_cloud/types/fact_rating_examples.py @@ -0,0 +1,31 @@ +# This file was auto-generated by Fern from our API Definition. + +import datetime as dt +import typing + +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 + + +class FactRatingExamples(pydantic_v1.BaseModel): + high: typing.Optional[str] = None + low: typing.Optional[str] = None + medium: typing.Optional[str] = None + + def json(self, **kwargs: typing.Any) -> str: + kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + return super().json(**kwargs_with_defaults) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/zep_cloud/types/fact_rating_instruction.py b/src/zep_cloud/types/fact_rating_instruction.py new file mode 100644 index 00000000..85d70a46 --- /dev/null +++ b/src/zep_cloud/types/fact_rating_instruction.py @@ -0,0 +1,45 @@ +# This file was auto-generated by Fern from our API Definition. + +import datetime as dt +import typing + +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +from .fact_rating_examples import FactRatingExamples + + +class FactRatingInstruction(pydantic_v1.BaseModel): + examples: typing.Optional[FactRatingExamples] = pydantic_v1.Field(default=None) + """ + Examples is a list of examples that demonstrate how facts might be rated based on your instruction. You should provide + an example of a highly rated example, a low rated example, and a medium (or in between example). For example, if you are rating + based on relevance to a trip planning application, your examples might be: + High: "Joe's dream vacation is Bali" + Medium: "Joe has a fear of flying", + Low: "Joe's favorite food is Japanese", + """ + + instruction: typing.Optional[str] = pydantic_v1.Field(default=None) + """ + A string describing how to rate facts as they apply to your application. A trip planning application may + use something like "relevancy to planning a trip, the user's preferences when traveling, + or the user's travel history." + """ + + def json(self, **kwargs: typing.Any) -> str: + kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + return super().json(**kwargs_with_defaults) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/zep_cloud/types/models_fact_response.py b/src/zep_cloud/types/models_fact_response.py new file mode 100644 index 00000000..7f60e609 --- /dev/null +++ b/src/zep_cloud/types/models_fact_response.py @@ -0,0 +1,30 @@ +# This file was auto-generated by Fern from our API Definition. + +import datetime as dt +import typing + +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +from .fact import Fact + + +class ModelsFactResponse(pydantic_v1.BaseModel): + fact: typing.Optional[Fact] = None + + def json(self, **kwargs: typing.Any) -> str: + kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + return super().json(**kwargs_with_defaults) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/zep_cloud/types/models_facts_response.py b/src/zep_cloud/types/models_facts_response.py new file mode 100644 index 00000000..156cf46a --- /dev/null +++ b/src/zep_cloud/types/models_facts_response.py @@ -0,0 +1,30 @@ +# This file was auto-generated by Fern from our API Definition. + +import datetime as dt +import typing + +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +from .fact import Fact + + +class ModelsFactsResponse(pydantic_v1.BaseModel): + facts: typing.Optional[typing.List[Fact]] = None + + def json(self, **kwargs: typing.Any) -> str: + kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + return super().json(**kwargs_with_defaults) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/zep_cloud/types/session.py b/src/zep_cloud/types/session.py index 6ae67985..34b442fa 100644 --- a/src/zep_cloud/types/session.py +++ b/src/zep_cloud/types/session.py @@ -5,6 +5,7 @@ from ..core.datetime_utils import serialize_datetime from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +from .fact_rating_instruction import FactRatingInstruction class Session(pydantic_v1.BaseModel): @@ -12,6 +13,7 @@ class Session(pydantic_v1.BaseModel): created_at: typing.Optional[str] = None deleted_at: typing.Optional[str] = None ended_at: typing.Optional[str] = None + fact_rating_instruction: typing.Optional[FactRatingInstruction] = None fact_version_uuid: typing.Optional[str] = None facts: typing.Optional[typing.List[str]] = None id: typing.Optional[int] = None From 20ae792ba8667210056369acfa360e1b9a24b330 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:16:49 +0000 Subject: [PATCH 07/10] SDK regeneration --- src/zep_cloud/__init__.py | 11 +- src/zep_cloud/base_client.py | 3 - src/zep_cloud/fact/__init__.py | 2 - src/zep_cloud/fact/client.py | 117 ----------------- src/zep_cloud/memory/client.py | 120 +++++++++++++++--- src/zep_cloud/types/__init__.py | 8 +- ...dels_fact_response.py => fact_response.py} | 2 +- ...ls_facts_response.py => facts_response.py} | 2 +- 8 files changed, 115 insertions(+), 150 deletions(-) delete mode 100644 src/zep_cloud/fact/__init__.py delete mode 100644 src/zep_cloud/fact/client.py rename src/zep_cloud/types/{models_fact_response.py => fact_response.py} (95%) rename src/zep_cloud/types/{models_facts_response.py => facts_response.py} (95%) diff --git a/src/zep_cloud/__init__.py b/src/zep_cloud/__init__.py index c811a71b..17b5e3c0 100644 --- a/src/zep_cloud/__init__.py +++ b/src/zep_cloud/__init__.py @@ -14,13 +14,13 @@ Fact, FactRatingExamples, FactRatingInstruction, + FactResponse, + FactsResponse, Memory, MemorySearchResult, MemoryType, Message, MessageListResponse, - ModelsFactResponse, - ModelsFactsResponse, Question, RoleType, SearchScope, @@ -37,7 +37,7 @@ UserListResponse, ) from .errors import BadRequestError, ConflictError, InternalServerError, NotFoundError, UnauthorizedError -from . import document, fact, memory, user +from . import document, memory, user from .environment import ZepEnvironment from .version import __version__ @@ -57,14 +57,14 @@ "Fact", "FactRatingExamples", "FactRatingInstruction", + "FactResponse", + "FactsResponse", "InternalServerError", "Memory", "MemorySearchResult", "MemoryType", "Message", "MessageListResponse", - "ModelsFactResponse", - "ModelsFactsResponse", "NotFoundError", "Question", "RoleType", @@ -84,7 +84,6 @@ "ZepEnvironment", "__version__", "document", - "fact", "memory", "user", ] diff --git a/src/zep_cloud/base_client.py b/src/zep_cloud/base_client.py index 6be81c69..763c164a 100644 --- a/src/zep_cloud/base_client.py +++ b/src/zep_cloud/base_client.py @@ -9,7 +9,6 @@ from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from .document.client import AsyncDocumentClient, DocumentClient from .environment import ZepEnvironment -from .fact.client import AsyncFactClient, FactClient from .memory.client import AsyncMemoryClient, MemoryClient from .user.client import AsyncUserClient, UserClient @@ -76,7 +75,6 @@ def __init__( ) self.document = DocumentClient(client_wrapper=self._client_wrapper) self.memory = MemoryClient(client_wrapper=self._client_wrapper) - self.fact = FactClient(client_wrapper=self._client_wrapper) self.user = UserClient(client_wrapper=self._client_wrapper) @@ -142,7 +140,6 @@ def __init__( ) self.document = AsyncDocumentClient(client_wrapper=self._client_wrapper) self.memory = AsyncMemoryClient(client_wrapper=self._client_wrapper) - self.fact = AsyncFactClient(client_wrapper=self._client_wrapper) self.user = AsyncUserClient(client_wrapper=self._client_wrapper) diff --git a/src/zep_cloud/fact/__init__.py b/src/zep_cloud/fact/__init__.py deleted file mode 100644 index f3ea2659..00000000 --- a/src/zep_cloud/fact/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - diff --git a/src/zep_cloud/fact/client.py b/src/zep_cloud/fact/client.py deleted file mode 100644 index 69cc6584..00000000 --- a/src/zep_cloud/fact/client.py +++ /dev/null @@ -1,117 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - -import typing -from json.decoder import JSONDecodeError - -from ..core.api_error import ApiError as core_api_error_ApiError -from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.pydantic_utilities import pydantic_v1 -from ..core.request_options import RequestOptions -from ..errors.internal_server_error import InternalServerError -from ..errors.not_found_error import NotFoundError -from ..types.api_error import ApiError as types_api_error_ApiError - - -class FactClient: - def __init__(self, *, client_wrapper: SyncClientWrapper): - self._client_wrapper = client_wrapper - - def delete_a_fact_for_the_given_uuid( - self, fact_uuid: str, *, request_options: typing.Optional[RequestOptions] = None - ) -> str: - """ - delete a fact - - Parameters - ---------- - fact_uuid : str - Fact UUID - - request_options : typing.Optional[RequestOptions] - Request-specific configuration. - - Returns - ------- - str - Deleted - - Examples - -------- - from zep_cloud.client import Zep - - client = Zep( - api_key="YOUR_API_KEY", - ) - client.fact.delete_a_fact_for_the_given_uuid( - fact_uuid="factUUID", - ) - """ - _response = self._client_wrapper.httpx_client.request( - f"facts/{jsonable_encoder(fact_uuid)}", method="DELETE", request_options=request_options - ) - if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(str, _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) - - -class AsyncFactClient: - def __init__(self, *, client_wrapper: AsyncClientWrapper): - self._client_wrapper = client_wrapper - - async def delete_a_fact_for_the_given_uuid( - self, fact_uuid: str, *, request_options: typing.Optional[RequestOptions] = None - ) -> str: - """ - delete a fact - - Parameters - ---------- - fact_uuid : str - Fact UUID - - request_options : typing.Optional[RequestOptions] - Request-specific configuration. - - Returns - ------- - str - Deleted - - Examples - -------- - from zep_cloud.client import AsyncZep - - client = AsyncZep( - api_key="YOUR_API_KEY", - ) - await client.fact.delete_a_fact_for_the_given_uuid( - fact_uuid="factUUID", - ) - """ - _response = await self._client_wrapper.httpx_client.request( - f"facts/{jsonable_encoder(fact_uuid)}", method="DELETE", request_options=request_options - ) - if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(str, _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) diff --git a/src/zep_cloud/memory/client.py b/src/zep_cloud/memory/client.py index 10ed7e16..dbc477b9 100644 --- a/src/zep_cloud/memory/client.py +++ b/src/zep_cloud/memory/client.py @@ -18,13 +18,13 @@ from ..types.end_session_response import EndSessionResponse from ..types.end_sessions_response import EndSessionsResponse from ..types.fact_rating_instruction import FactRatingInstruction +from ..types.fact_response import FactResponse +from ..types.facts_response import FactsResponse from ..types.memory import Memory from ..types.memory_search_result import MemorySearchResult from ..types.memory_type import MemoryType from ..types.message import Message from ..types.message_list_response import MessageListResponse -from ..types.models_fact_response import ModelsFactResponse -from ..types.models_facts_response import ModelsFactsResponse from ..types.question import Question from ..types.search_scope import SearchScope from ..types.search_type import SearchType @@ -42,9 +42,7 @@ class MemoryClient: def __init__(self, *, client_wrapper: SyncClientWrapper): self._client_wrapper = client_wrapper - def get_fact( - self, fact_uuid: str, *, request_options: typing.Optional[RequestOptions] = None - ) -> ModelsFactResponse: + def get_fact(self, fact_uuid: str, *, request_options: typing.Optional[RequestOptions] = None) -> FactResponse: """ get fact by uuid @@ -58,7 +56,7 @@ def get_fact( Returns ------- - ModelsFactResponse + FactResponse The fact with the specified UUID. Examples @@ -76,7 +74,52 @@ def get_fact( f"facts/{jsonable_encoder(fact_uuid)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ModelsFactResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(FactResponse, _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 delete_fact(self, fact_uuid: str, *, request_options: typing.Optional[RequestOptions] = None) -> str: + """ + delete a fact + + Parameters + ---------- + fact_uuid : str + Fact UUID + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + str + Deleted + + Examples + -------- + from zep_cloud.client import Zep + + client = Zep( + api_key="YOUR_API_KEY", + ) + client.memory.delete_fact( + fact_uuid="factUUID", + ) + """ + _response = self._client_wrapper.httpx_client.request( + f"facts/{jsonable_encoder(fact_uuid)}", method="DELETE", request_options=request_options + ) + if 200 <= _response.status_code < 300: + return pydantic_v1.parse_obj_as(str, _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: @@ -708,7 +751,7 @@ def get_session_facts( *, min_rating: typing.Optional[float] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> typing.List[typing.List[ModelsFactsResponse]]: + ) -> typing.List[typing.List[FactsResponse]]: """ get facts for a session @@ -725,7 +768,7 @@ def get_session_facts( Returns ------- - typing.List[typing.List[ModelsFactsResponse]] + typing.List[typing.List[FactsResponse]] The facts for the session. Examples @@ -746,7 +789,7 @@ def get_session_facts( request_options=request_options, ) if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(typing.List[typing.List[ModelsFactsResponse]], _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(typing.List[typing.List[FactsResponse]], _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: @@ -1317,7 +1360,7 @@ def __init__(self, *, client_wrapper: AsyncClientWrapper): async def get_fact( self, fact_uuid: str, *, request_options: typing.Optional[RequestOptions] = None - ) -> ModelsFactResponse: + ) -> FactResponse: """ get fact by uuid @@ -1331,7 +1374,7 @@ async def get_fact( Returns ------- - ModelsFactResponse + FactResponse The fact with the specified UUID. Examples @@ -1349,7 +1392,52 @@ async def get_fact( f"facts/{jsonable_encoder(fact_uuid)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ModelsFactResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(FactResponse, _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 delete_fact(self, fact_uuid: str, *, request_options: typing.Optional[RequestOptions] = None) -> str: + """ + delete a fact + + Parameters + ---------- + fact_uuid : str + Fact UUID + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + str + Deleted + + Examples + -------- + from zep_cloud.client import AsyncZep + + client = AsyncZep( + api_key="YOUR_API_KEY", + ) + await client.memory.delete_fact( + fact_uuid="factUUID", + ) + """ + _response = await self._client_wrapper.httpx_client.request( + f"facts/{jsonable_encoder(fact_uuid)}", method="DELETE", request_options=request_options + ) + if 200 <= _response.status_code < 300: + return pydantic_v1.parse_obj_as(str, _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: @@ -1981,7 +2069,7 @@ async def get_session_facts( *, min_rating: typing.Optional[float] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> typing.List[typing.List[ModelsFactsResponse]]: + ) -> typing.List[typing.List[FactsResponse]]: """ get facts for a session @@ -1998,7 +2086,7 @@ async def get_session_facts( Returns ------- - typing.List[typing.List[ModelsFactsResponse]] + typing.List[typing.List[FactsResponse]] The facts for the session. Examples @@ -2019,7 +2107,7 @@ async def get_session_facts( request_options=request_options, ) if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(typing.List[typing.List[ModelsFactsResponse]], _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(typing.List[typing.List[FactsResponse]], _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: diff --git a/src/zep_cloud/types/__init__.py b/src/zep_cloud/types/__init__.py index 087d4968..a9af3111 100644 --- a/src/zep_cloud/types/__init__.py +++ b/src/zep_cloud/types/__init__.py @@ -13,13 +13,13 @@ from .fact import Fact from .fact_rating_examples import FactRatingExamples from .fact_rating_instruction import FactRatingInstruction +from .fact_response import FactResponse +from .facts_response import FactsResponse from .memory import Memory from .memory_search_result import MemorySearchResult from .memory_type import MemoryType from .message import Message from .message_list_response import MessageListResponse -from .models_fact_response import ModelsFactResponse -from .models_facts_response import ModelsFactsResponse from .question import Question from .role_type import RoleType from .search_scope import SearchScope @@ -49,13 +49,13 @@ "Fact", "FactRatingExamples", "FactRatingInstruction", + "FactResponse", + "FactsResponse", "Memory", "MemorySearchResult", "MemoryType", "Message", "MessageListResponse", - "ModelsFactResponse", - "ModelsFactsResponse", "Question", "RoleType", "SearchScope", diff --git a/src/zep_cloud/types/models_fact_response.py b/src/zep_cloud/types/fact_response.py similarity index 95% rename from src/zep_cloud/types/models_fact_response.py rename to src/zep_cloud/types/fact_response.py index 7f60e609..cfc5419f 100644 --- a/src/zep_cloud/types/models_fact_response.py +++ b/src/zep_cloud/types/fact_response.py @@ -8,7 +8,7 @@ from .fact import Fact -class ModelsFactResponse(pydantic_v1.BaseModel): +class FactResponse(pydantic_v1.BaseModel): fact: typing.Optional[Fact] = None def json(self, **kwargs: typing.Any) -> str: diff --git a/src/zep_cloud/types/models_facts_response.py b/src/zep_cloud/types/facts_response.py similarity index 95% rename from src/zep_cloud/types/models_facts_response.py rename to src/zep_cloud/types/facts_response.py index 156cf46a..c9f54e86 100644 --- a/src/zep_cloud/types/models_facts_response.py +++ b/src/zep_cloud/types/facts_response.py @@ -8,7 +8,7 @@ from .fact import Fact -class ModelsFactsResponse(pydantic_v1.BaseModel): +class FactsResponse(pydantic_v1.BaseModel): facts: typing.Optional[typing.List[Fact]] = None def json(self, **kwargs: typing.Any) -> str: From a1b05c68a7967f5e835d450013258f5dc0b5c3d2 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:31:23 +0000 Subject: [PATCH 08/10] SDK regeneration --- src/zep_cloud/memory/client.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/zep_cloud/memory/client.py b/src/zep_cloud/memory/client.py index dbc477b9..d96c87d1 100644 --- a/src/zep_cloud/memory/client.py +++ b/src/zep_cloud/memory/client.py @@ -751,7 +751,7 @@ def get_session_facts( *, min_rating: typing.Optional[float] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> typing.List[typing.List[FactsResponse]]: + ) -> FactsResponse: """ get facts for a session @@ -768,7 +768,7 @@ def get_session_facts( Returns ------- - typing.List[typing.List[FactsResponse]] + FactsResponse The facts for the session. Examples @@ -789,7 +789,7 @@ def get_session_facts( request_options=request_options, ) if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(typing.List[typing.List[FactsResponse]], _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(FactsResponse, _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: @@ -2069,7 +2069,7 @@ async def get_session_facts( *, min_rating: typing.Optional[float] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> typing.List[typing.List[FactsResponse]]: + ) -> FactsResponse: """ get facts for a session @@ -2086,7 +2086,7 @@ async def get_session_facts( Returns ------- - typing.List[typing.List[FactsResponse]] + FactsResponse The facts for the session. Examples @@ -2107,7 +2107,7 @@ async def get_session_facts( request_options=request_options, ) if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(typing.List[typing.List[FactsResponse]], _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(FactsResponse, _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: From b7ac9924c9790da85462f5afaf058abafc348b5a Mon Sep 17 00:00:00 2001 From: paulpaliychuk Date: Thu, 18 Jul 2024 12:57:05 -0400 Subject: [PATCH 09/10] feat: Update memory example to include latest api --- examples/chat_history/memory.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/chat_history/memory.py b/examples/chat_history/memory.py index 4e742fae..900ae84b 100644 --- a/examples/chat_history/memory.py +++ b/examples/chat_history/memory.py @@ -51,7 +51,9 @@ async def main() -> None: print(f"\n---Creating session: {session_id}") await client.memory.add_session( - session_id=session_id, user_id=user_id, metadata={"foo": "bar"} + session_id=session_id, + user_id=user_id, + metadata={"foo": "bar"}, ) # Update session metadata @@ -70,7 +72,7 @@ async def main() -> None: await client.memory.add(session_id=session_id, messages=[Message(**m)]) # Wait for the messages to be processed - await asyncio.sleep(5) + await asyncio.sleep(65) # Synthesize a question from most recent messages. # Useful for RAG apps. This is faster than using an LLM chain. @@ -92,6 +94,10 @@ async def main() -> None: ) print(f"Classification: {classification}") + all_session_facts = await client.memory.get_session_facts(session_id) + for f in all_session_facts.facts: + print(f"{f.fact}\n") + # Get Memory for session print(f"\n---Get Perpetual Memory for Session: {session_id}") memory = await client.memory.get(session_id, memory_type="perpetual") @@ -106,6 +112,13 @@ async def main() -> None: ) print("summaryResult: ", summary_result) + query = "What are Jane's favorite shoe brands?" + print(f"\n---Searching over facts for: '{query}'") + facts_result = await client.memory.search_sessions( + session_ids=[session_id], text=query, search_scope="facts" + ) + print("facts_result: ", facts_result) + print("\n---Searching over summaries with MMR Reranking") summary_mmr_result = await client.memory.search_sessions( session_ids=[session_id], text=query, search_scope="summary", search_type="mmr" From b157c7037908de336eff563837440fbcd0efbe24 Mon Sep 17 00:00:00 2001 From: paulpaliychuk Date: Thu, 18 Jul 2024 12:59:14 -0400 Subject: [PATCH 10/10] fix: Decrease sleep in example --- examples/chat_history/memory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/chat_history/memory.py b/examples/chat_history/memory.py index 900ae84b..d2a0459d 100644 --- a/examples/chat_history/memory.py +++ b/examples/chat_history/memory.py @@ -72,7 +72,7 @@ async def main() -> None: await client.memory.add(session_id=session_id, messages=[Message(**m)]) # Wait for the messages to be processed - await asyncio.sleep(65) + await asyncio.sleep(5) # Synthesize a question from most recent messages. # Useful for RAG apps. This is faster than using an LLM chain.