diff --git a/pyproject.toml b/pyproject.toml index 48c4f60..1e9a7f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ name = "zep-cloud" [tool.poetry] name = "zep-cloud" -version = "3.14.0" +version = "3.15.0" description = "" readme = "README.md" authors = [] diff --git a/reference.md b/reference.md index 566d51b..3fcbf5d 100644 --- a/reference.md +++ b/reference.md @@ -359,6 +359,260 @@ client.context.delete_context_template( ## Graph +
client.graph.list_custom_instructions(...) +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Lists all custom instructions for a project, user, or graph. +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```python +from zep_cloud import Zep + +client = Zep( + api_key="YOUR_API_KEY", +) +client.graph.list_custom_instructions( + user_id="user_id", + graph_id="graph_id", +) + +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**user_id:** `typing.Optional[str]` — User ID to get user-specific instructions + +
+
+ +
+
+ +**graph_id:** `typing.Optional[str]` — Graph ID to get graph-specific instructions + +
+
+ +
+
+ +**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration. + +
+
+
+
+ + +
+
+
+ +
client.graph.add_custom_instructions(...) +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Adds new custom instructions for graphs without removing existing ones. If user_ids or graph_ids is empty, adds to project-wide default instructions. +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```python +from zep_cloud import CustomInstruction, Zep + +client = Zep( + api_key="YOUR_API_KEY", +) +client.graph.add_custom_instructions( + instructions=[ + CustomInstruction( + name="name", + text="text", + ) + ], +) + +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**instructions:** `typing.Sequence[CustomInstruction]` — Instructions to add to the graph. + +
+
+ +
+
+ +**graph_ids:** `typing.Optional[typing.Sequence[str]]` — Graph IDs to add the instructions to. If empty, the instructions are added to the project-wide default. + +
+
+ +
+
+ +**user_ids:** `typing.Optional[typing.Sequence[str]]` — User IDs to add the instructions to. If empty, the instructions are added to the project-wide default. + +
+
+ +
+
+ +**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration. + +
+
+
+
+ + +
+
+
+ +
client.graph.delete_custom_instructions(...) +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Deletes custom instructions for graphs or project wide defaults. +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```python +from zep_cloud import Zep + +client = Zep( + api_key="YOUR_API_KEY", +) +client.graph.delete_custom_instructions() + +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**graph_ids:** `typing.Optional[typing.Sequence[str]]` — Determines which group graphs will have their custom instructions deleted. If no graphs are provided, the project-wide custom instructions will be affected. + +
+
+ +
+
+ +**instruction_names:** `typing.Optional[typing.Sequence[str]]` — Unique identifier for the instructions to be deleted. If empty deletes all instructions. + +
+
+ +
+
+ +**user_ids:** `typing.Optional[typing.Sequence[str]]` — Determines which user graphs will have their custom instructions deleted. If no users are provided, the project-wide custom instructions will be affected. + +
+
+ +
+
+ +**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration. + +
+
+
+
+ + +
+
+
+
client.graph.list_entity_types(...)
diff --git a/src/zep_cloud/__init__.py b/src/zep_cloud/__init__.py index 9cad36c..ae9a38f 100644 --- a/src/zep_cloud/__init__.py +++ b/src/zep_cloud/__init__.py @@ -10,6 +10,7 @@ CloneGraphResponse, ComparisonOperator, ContextTemplateResponse, + CustomInstruction, DateFilter, EdgeType, EntityEdge, @@ -34,6 +35,7 @@ GraphSearchResults, GraphSearchScope, ListContextTemplatesResponse, + ListCustomInstructionsResponse, ListUserInstructionsResponse, Message, MessageListResponse, @@ -73,6 +75,7 @@ "CloneGraphResponse", "ComparisonOperator", "ContextTemplateResponse", + "CustomInstruction", "DateFilter", "EdgeType", "EntityEdge", @@ -98,6 +101,7 @@ "GraphSearchScope", "InternalServerError", "ListContextTemplatesResponse", + "ListCustomInstructionsResponse", "ListUserInstructionsResponse", "Message", "MessageListResponse", diff --git a/src/zep_cloud/core/client_wrapper.py b/src/zep_cloud/core/client_wrapper.py index 81b1aeb..bc2827a 100644 --- a/src/zep_cloud/core/client_wrapper.py +++ b/src/zep_cloud/core/client_wrapper.py @@ -22,10 +22,10 @@ def __init__( def get_headers(self) -> typing.Dict[str, str]: headers: typing.Dict[str, str] = { - "User-Agent": "zep-cloud/3.14.0", + "User-Agent": "zep-cloud/3.15.0", "X-Fern-Language": "Python", "X-Fern-SDK-Name": "zep-cloud", - "X-Fern-SDK-Version": "3.14.0", + "X-Fern-SDK-Version": "3.15.0", **(self.get_custom_headers() or {}), } headers["Authorization"] = f"Api-Key {self.api_key}" diff --git a/src/zep_cloud/graph/client.py b/src/zep_cloud/graph/client.py index f386a6b..2e52096 100644 --- a/src/zep_cloud/graph/client.py +++ b/src/zep_cloud/graph/client.py @@ -6,6 +6,7 @@ from ..core.request_options import RequestOptions from ..types.add_triple_response import AddTripleResponse from ..types.clone_graph_response import CloneGraphResponse +from ..types.custom_instruction import CustomInstruction from ..types.edge_type import EdgeType from ..types.entity_type import EntityType from ..types.entity_type_response import EntityTypeResponse @@ -17,6 +18,7 @@ from ..types.graph_list_response import GraphListResponse from ..types.graph_search_results import GraphSearchResults from ..types.graph_search_scope import GraphSearchScope +from ..types.list_custom_instructions_response import ListCustomInstructionsResponse from ..types.reranker import Reranker from ..types.search_filters import SearchFilters from ..types.success_response import SuccessResponse @@ -49,6 +51,144 @@ def with_raw_response(self) -> RawGraphClient: """ return self._raw_client + def list_custom_instructions( + self, + *, + user_id: typing.Optional[str] = None, + graph_id: typing.Optional[str] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> ListCustomInstructionsResponse: + """ + Lists all custom instructions for a project, user, or graph. + + Parameters + ---------- + user_id : typing.Optional[str] + User ID to get user-specific instructions + + graph_id : typing.Optional[str] + Graph ID to get graph-specific instructions + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + ListCustomInstructionsResponse + The list of instructions. + + Examples + -------- + from zep_cloud import Zep + + client = Zep( + api_key="YOUR_API_KEY", + ) + client.graph.list_custom_instructions( + user_id="user_id", + graph_id="graph_id", + ) + """ + _response = self._raw_client.list_custom_instructions( + user_id=user_id, graph_id=graph_id, request_options=request_options + ) + return _response.data + + def add_custom_instructions( + self, + *, + instructions: typing.Sequence[CustomInstruction], + graph_ids: typing.Optional[typing.Sequence[str]] = OMIT, + user_ids: typing.Optional[typing.Sequence[str]] = OMIT, + request_options: typing.Optional[RequestOptions] = None, + ) -> SuccessResponse: + """ + Adds new custom instructions for graphs without removing existing ones. If user_ids or graph_ids is empty, adds to project-wide default instructions. + + Parameters + ---------- + instructions : typing.Sequence[CustomInstruction] + Instructions to add to the graph. + + graph_ids : typing.Optional[typing.Sequence[str]] + Graph IDs to add the instructions to. If empty, the instructions are added to the project-wide default. + + user_ids : typing.Optional[typing.Sequence[str]] + User IDs to add the instructions to. If empty, the instructions are added to the project-wide default. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + SuccessResponse + Instructions added successfully + + Examples + -------- + from zep_cloud import CustomInstruction, Zep + + client = Zep( + api_key="YOUR_API_KEY", + ) + client.graph.add_custom_instructions( + instructions=[ + CustomInstruction( + name="name", + text="text", + ) + ], + ) + """ + _response = self._raw_client.add_custom_instructions( + instructions=instructions, graph_ids=graph_ids, user_ids=user_ids, request_options=request_options + ) + return _response.data + + def delete_custom_instructions( + self, + *, + graph_ids: typing.Optional[typing.Sequence[str]] = OMIT, + instruction_names: typing.Optional[typing.Sequence[str]] = OMIT, + user_ids: typing.Optional[typing.Sequence[str]] = OMIT, + request_options: typing.Optional[RequestOptions] = None, + ) -> SuccessResponse: + """ + Deletes custom instructions for graphs or project wide defaults. + + Parameters + ---------- + graph_ids : typing.Optional[typing.Sequence[str]] + Determines which group graphs will have their custom instructions deleted. If no graphs are provided, the project-wide custom instructions will be affected. + + instruction_names : typing.Optional[typing.Sequence[str]] + Unique identifier for the instructions to be deleted. If empty deletes all instructions. + + user_ids : typing.Optional[typing.Sequence[str]] + Determines which user graphs will have their custom instructions deleted. If no users are provided, the project-wide custom instructions will be affected. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + SuccessResponse + Instructions deleted successfully + + Examples + -------- + from zep_cloud import Zep + + client = Zep( + api_key="YOUR_API_KEY", + ) + client.graph.delete_custom_instructions() + """ + _response = self._raw_client.delete_custom_instructions( + graph_ids=graph_ids, instruction_names=instruction_names, user_ids=user_ids, request_options=request_options + ) + return _response.data + def list_entity_types( self, *, @@ -750,6 +890,168 @@ def with_raw_response(self) -> AsyncRawGraphClient: """ return self._raw_client + async def list_custom_instructions( + self, + *, + user_id: typing.Optional[str] = None, + graph_id: typing.Optional[str] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> ListCustomInstructionsResponse: + """ + Lists all custom instructions for a project, user, or graph. + + Parameters + ---------- + user_id : typing.Optional[str] + User ID to get user-specific instructions + + graph_id : typing.Optional[str] + Graph ID to get graph-specific instructions + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + ListCustomInstructionsResponse + The list of instructions. + + Examples + -------- + import asyncio + + from zep_cloud import AsyncZep + + client = AsyncZep( + api_key="YOUR_API_KEY", + ) + + + async def main() -> None: + await client.graph.list_custom_instructions( + user_id="user_id", + graph_id="graph_id", + ) + + + asyncio.run(main()) + """ + _response = await self._raw_client.list_custom_instructions( + user_id=user_id, graph_id=graph_id, request_options=request_options + ) + return _response.data + + async def add_custom_instructions( + self, + *, + instructions: typing.Sequence[CustomInstruction], + graph_ids: typing.Optional[typing.Sequence[str]] = OMIT, + user_ids: typing.Optional[typing.Sequence[str]] = OMIT, + request_options: typing.Optional[RequestOptions] = None, + ) -> SuccessResponse: + """ + Adds new custom instructions for graphs without removing existing ones. If user_ids or graph_ids is empty, adds to project-wide default instructions. + + Parameters + ---------- + instructions : typing.Sequence[CustomInstruction] + Instructions to add to the graph. + + graph_ids : typing.Optional[typing.Sequence[str]] + Graph IDs to add the instructions to. If empty, the instructions are added to the project-wide default. + + user_ids : typing.Optional[typing.Sequence[str]] + User IDs to add the instructions to. If empty, the instructions are added to the project-wide default. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + SuccessResponse + Instructions added successfully + + Examples + -------- + import asyncio + + from zep_cloud import AsyncZep, CustomInstruction + + client = AsyncZep( + api_key="YOUR_API_KEY", + ) + + + async def main() -> None: + await client.graph.add_custom_instructions( + instructions=[ + CustomInstruction( + name="name", + text="text", + ) + ], + ) + + + asyncio.run(main()) + """ + _response = await self._raw_client.add_custom_instructions( + instructions=instructions, graph_ids=graph_ids, user_ids=user_ids, request_options=request_options + ) + return _response.data + + async def delete_custom_instructions( + self, + *, + graph_ids: typing.Optional[typing.Sequence[str]] = OMIT, + instruction_names: typing.Optional[typing.Sequence[str]] = OMIT, + user_ids: typing.Optional[typing.Sequence[str]] = OMIT, + request_options: typing.Optional[RequestOptions] = None, + ) -> SuccessResponse: + """ + Deletes custom instructions for graphs or project wide defaults. + + Parameters + ---------- + graph_ids : typing.Optional[typing.Sequence[str]] + Determines which group graphs will have their custom instructions deleted. If no graphs are provided, the project-wide custom instructions will be affected. + + instruction_names : typing.Optional[typing.Sequence[str]] + Unique identifier for the instructions to be deleted. If empty deletes all instructions. + + user_ids : typing.Optional[typing.Sequence[str]] + Determines which user graphs will have their custom instructions deleted. If no users are provided, the project-wide custom instructions will be affected. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + SuccessResponse + Instructions deleted successfully + + Examples + -------- + import asyncio + + from zep_cloud import AsyncZep + + client = AsyncZep( + api_key="YOUR_API_KEY", + ) + + + async def main() -> None: + await client.graph.delete_custom_instructions() + + + asyncio.run(main()) + """ + _response = await self._raw_client.delete_custom_instructions( + graph_ids=graph_ids, instruction_names=instruction_names, user_ids=user_ids, request_options=request_options + ) + return _response.data + async def list_entity_types( self, *, diff --git a/src/zep_cloud/graph/raw_client.py b/src/zep_cloud/graph/raw_client.py index 73291f2..934d1a6 100644 --- a/src/zep_cloud/graph/raw_client.py +++ b/src/zep_cloud/graph/raw_client.py @@ -16,6 +16,7 @@ from ..types.add_triple_response import AddTripleResponse from ..types.api_error import ApiError as types_api_error_ApiError from ..types.clone_graph_response import CloneGraphResponse +from ..types.custom_instruction import CustomInstruction from ..types.edge_type import EdgeType from ..types.entity_type import EntityType from ..types.entity_type_response import EntityTypeResponse @@ -27,6 +28,7 @@ from ..types.graph_list_response import GraphListResponse from ..types.graph_search_results import GraphSearchResults from ..types.graph_search_scope import GraphSearchScope +from ..types.list_custom_instructions_response import ListCustomInstructionsResponse from ..types.reranker import Reranker from ..types.search_filters import SearchFilters from ..types.success_response import SuccessResponse @@ -39,6 +41,254 @@ class RawGraphClient: def __init__(self, *, client_wrapper: SyncClientWrapper): self._client_wrapper = client_wrapper + def list_custom_instructions( + self, + *, + user_id: typing.Optional[str] = None, + graph_id: typing.Optional[str] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> HttpResponse[ListCustomInstructionsResponse]: + """ + Lists all custom instructions for a project, user, or graph. + + Parameters + ---------- + user_id : typing.Optional[str] + User ID to get user-specific instructions + + graph_id : typing.Optional[str] + Graph ID to get graph-specific instructions + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + HttpResponse[ListCustomInstructionsResponse] + The list of instructions. + """ + _response = self._client_wrapper.httpx_client.request( + "custom-instructions", + method="GET", + params={ + "user_id": user_id, + "graph_id": graph_id, + }, + request_options=request_options, + ) + try: + if 200 <= _response.status_code < 300: + _data = typing.cast( + ListCustomInstructionsResponse, + parse_obj_as( + type_=ListCustomInstructionsResponse, # type: ignore + object_=_response.json(), + ), + ) + return HttpResponse(response=_response, data=_data) + if _response.status_code == 400: + raise BadRequestError( + headers=dict(_response.headers), + body=typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 500: + raise InternalServerError( + headers=dict(_response.headers), + body=typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise core_api_error_ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise core_api_error_ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response_json + ) + + def add_custom_instructions( + self, + *, + instructions: typing.Sequence[CustomInstruction], + graph_ids: typing.Optional[typing.Sequence[str]] = OMIT, + user_ids: typing.Optional[typing.Sequence[str]] = OMIT, + request_options: typing.Optional[RequestOptions] = None, + ) -> HttpResponse[SuccessResponse]: + """ + Adds new custom instructions for graphs without removing existing ones. If user_ids or graph_ids is empty, adds to project-wide default instructions. + + Parameters + ---------- + instructions : typing.Sequence[CustomInstruction] + Instructions to add to the graph. + + graph_ids : typing.Optional[typing.Sequence[str]] + Graph IDs to add the instructions to. If empty, the instructions are added to the project-wide default. + + user_ids : typing.Optional[typing.Sequence[str]] + User IDs to add the instructions to. If empty, the instructions are added to the project-wide default. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + HttpResponse[SuccessResponse] + Instructions added successfully + """ + _response = self._client_wrapper.httpx_client.request( + "custom-instructions", + method="POST", + json={ + "graph_ids": graph_ids, + "instructions": convert_and_respect_annotation_metadata( + object_=instructions, annotation=typing.Sequence[CustomInstruction], direction="write" + ), + "user_ids": user_ids, + }, + headers={ + "content-type": "application/json", + }, + request_options=request_options, + omit=OMIT, + ) + try: + if 200 <= _response.status_code < 300: + _data = typing.cast( + SuccessResponse, + parse_obj_as( + type_=SuccessResponse, # type: ignore + object_=_response.json(), + ), + ) + return HttpResponse(response=_response, data=_data) + if _response.status_code == 400: + raise BadRequestError( + headers=dict(_response.headers), + body=typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 500: + raise InternalServerError( + headers=dict(_response.headers), + body=typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise core_api_error_ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise core_api_error_ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response_json + ) + + def delete_custom_instructions( + self, + *, + graph_ids: typing.Optional[typing.Sequence[str]] = OMIT, + instruction_names: typing.Optional[typing.Sequence[str]] = OMIT, + user_ids: typing.Optional[typing.Sequence[str]] = OMIT, + request_options: typing.Optional[RequestOptions] = None, + ) -> HttpResponse[SuccessResponse]: + """ + Deletes custom instructions for graphs or project wide defaults. + + Parameters + ---------- + graph_ids : typing.Optional[typing.Sequence[str]] + Determines which group graphs will have their custom instructions deleted. If no graphs are provided, the project-wide custom instructions will be affected. + + instruction_names : typing.Optional[typing.Sequence[str]] + Unique identifier for the instructions to be deleted. If empty deletes all instructions. + + user_ids : typing.Optional[typing.Sequence[str]] + Determines which user graphs will have their custom instructions deleted. If no users are provided, the project-wide custom instructions will be affected. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + HttpResponse[SuccessResponse] + Instructions deleted successfully + """ + _response = self._client_wrapper.httpx_client.request( + "custom-instructions", + method="DELETE", + json={ + "graph_ids": graph_ids, + "instruction_names": instruction_names, + "user_ids": user_ids, + }, + headers={ + "content-type": "application/json", + }, + request_options=request_options, + omit=OMIT, + ) + try: + if 200 <= _response.status_code < 300: + _data = typing.cast( + SuccessResponse, + parse_obj_as( + type_=SuccessResponse, # type: ignore + object_=_response.json(), + ), + ) + return HttpResponse(response=_response, data=_data) + if _response.status_code == 400: + raise BadRequestError( + headers=dict(_response.headers), + body=typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 500: + raise InternalServerError( + headers=dict(_response.headers), + body=typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise core_api_error_ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise core_api_error_ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response_json + ) + def list_entity_types( self, *, @@ -1188,6 +1438,254 @@ class AsyncRawGraphClient: def __init__(self, *, client_wrapper: AsyncClientWrapper): self._client_wrapper = client_wrapper + async def list_custom_instructions( + self, + *, + user_id: typing.Optional[str] = None, + graph_id: typing.Optional[str] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> AsyncHttpResponse[ListCustomInstructionsResponse]: + """ + Lists all custom instructions for a project, user, or graph. + + Parameters + ---------- + user_id : typing.Optional[str] + User ID to get user-specific instructions + + graph_id : typing.Optional[str] + Graph ID to get graph-specific instructions + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + AsyncHttpResponse[ListCustomInstructionsResponse] + The list of instructions. + """ + _response = await self._client_wrapper.httpx_client.request( + "custom-instructions", + method="GET", + params={ + "user_id": user_id, + "graph_id": graph_id, + }, + request_options=request_options, + ) + try: + if 200 <= _response.status_code < 300: + _data = typing.cast( + ListCustomInstructionsResponse, + parse_obj_as( + type_=ListCustomInstructionsResponse, # type: ignore + object_=_response.json(), + ), + ) + return AsyncHttpResponse(response=_response, data=_data) + if _response.status_code == 400: + raise BadRequestError( + headers=dict(_response.headers), + body=typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 500: + raise InternalServerError( + headers=dict(_response.headers), + body=typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise core_api_error_ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise core_api_error_ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response_json + ) + + async def add_custom_instructions( + self, + *, + instructions: typing.Sequence[CustomInstruction], + graph_ids: typing.Optional[typing.Sequence[str]] = OMIT, + user_ids: typing.Optional[typing.Sequence[str]] = OMIT, + request_options: typing.Optional[RequestOptions] = None, + ) -> AsyncHttpResponse[SuccessResponse]: + """ + Adds new custom instructions for graphs without removing existing ones. If user_ids or graph_ids is empty, adds to project-wide default instructions. + + Parameters + ---------- + instructions : typing.Sequence[CustomInstruction] + Instructions to add to the graph. + + graph_ids : typing.Optional[typing.Sequence[str]] + Graph IDs to add the instructions to. If empty, the instructions are added to the project-wide default. + + user_ids : typing.Optional[typing.Sequence[str]] + User IDs to add the instructions to. If empty, the instructions are added to the project-wide default. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + AsyncHttpResponse[SuccessResponse] + Instructions added successfully + """ + _response = await self._client_wrapper.httpx_client.request( + "custom-instructions", + method="POST", + json={ + "graph_ids": graph_ids, + "instructions": convert_and_respect_annotation_metadata( + object_=instructions, annotation=typing.Sequence[CustomInstruction], direction="write" + ), + "user_ids": user_ids, + }, + headers={ + "content-type": "application/json", + }, + request_options=request_options, + omit=OMIT, + ) + try: + if 200 <= _response.status_code < 300: + _data = typing.cast( + SuccessResponse, + parse_obj_as( + type_=SuccessResponse, # type: ignore + object_=_response.json(), + ), + ) + return AsyncHttpResponse(response=_response, data=_data) + if _response.status_code == 400: + raise BadRequestError( + headers=dict(_response.headers), + body=typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 500: + raise InternalServerError( + headers=dict(_response.headers), + body=typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise core_api_error_ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise core_api_error_ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response_json + ) + + async def delete_custom_instructions( + self, + *, + graph_ids: typing.Optional[typing.Sequence[str]] = OMIT, + instruction_names: typing.Optional[typing.Sequence[str]] = OMIT, + user_ids: typing.Optional[typing.Sequence[str]] = OMIT, + request_options: typing.Optional[RequestOptions] = None, + ) -> AsyncHttpResponse[SuccessResponse]: + """ + Deletes custom instructions for graphs or project wide defaults. + + Parameters + ---------- + graph_ids : typing.Optional[typing.Sequence[str]] + Determines which group graphs will have their custom instructions deleted. If no graphs are provided, the project-wide custom instructions will be affected. + + instruction_names : typing.Optional[typing.Sequence[str]] + Unique identifier for the instructions to be deleted. If empty deletes all instructions. + + user_ids : typing.Optional[typing.Sequence[str]] + Determines which user graphs will have their custom instructions deleted. If no users are provided, the project-wide custom instructions will be affected. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + AsyncHttpResponse[SuccessResponse] + Instructions deleted successfully + """ + _response = await self._client_wrapper.httpx_client.request( + "custom-instructions", + method="DELETE", + json={ + "graph_ids": graph_ids, + "instruction_names": instruction_names, + "user_ids": user_ids, + }, + headers={ + "content-type": "application/json", + }, + request_options=request_options, + omit=OMIT, + ) + try: + if 200 <= _response.status_code < 300: + _data = typing.cast( + SuccessResponse, + parse_obj_as( + type_=SuccessResponse, # type: ignore + object_=_response.json(), + ), + ) + return AsyncHttpResponse(response=_response, data=_data) + if _response.status_code == 400: + raise BadRequestError( + headers=dict(_response.headers), + body=typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 500: + raise InternalServerError( + headers=dict(_response.headers), + body=typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise core_api_error_ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise core_api_error_ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response_json + ) + async def list_entity_types( self, *, diff --git a/src/zep_cloud/types/__init__.py b/src/zep_cloud/types/__init__.py index 39ec436..5cbf96a 100644 --- a/src/zep_cloud/types/__init__.py +++ b/src/zep_cloud/types/__init__.py @@ -9,6 +9,7 @@ from .clone_graph_response import CloneGraphResponse from .comparison_operator import ComparisonOperator from .context_template_response import ContextTemplateResponse +from .custom_instruction import CustomInstruction from .date_filter import DateFilter from .edge_type import EdgeType from .entity_edge import EntityEdge @@ -33,6 +34,7 @@ from .graph_search_results import GraphSearchResults from .graph_search_scope import GraphSearchScope from .list_context_templates_response import ListContextTemplatesResponse +from .list_custom_instructions_response import ListCustomInstructionsResponse from .list_user_instructions_response import ListUserInstructionsResponse from .message import Message from .message_list_response import MessageListResponse @@ -63,6 +65,7 @@ "CloneGraphResponse", "ComparisonOperator", "ContextTemplateResponse", + "CustomInstruction", "DateFilter", "EdgeType", "EntityEdge", @@ -87,6 +90,7 @@ "GraphSearchResults", "GraphSearchScope", "ListContextTemplatesResponse", + "ListCustomInstructionsResponse", "ListUserInstructionsResponse", "Message", "MessageListResponse", diff --git a/src/zep_cloud/types/custom_instruction.py b/src/zep_cloud/types/custom_instruction.py new file mode 100644 index 0000000..38b6d15 --- /dev/null +++ b/src/zep_cloud/types/custom_instruction.py @@ -0,0 +1,20 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +import pydantic +from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel + + +class CustomInstruction(UniversalBaseModel): + name: str + text: str + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 + else: + + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/src/zep_cloud/types/list_custom_instructions_response.py b/src/zep_cloud/types/list_custom_instructions_response.py new file mode 100644 index 0000000..e7ac97a --- /dev/null +++ b/src/zep_cloud/types/list_custom_instructions_response.py @@ -0,0 +1,20 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +import pydantic +from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel +from .custom_instruction import CustomInstruction + + +class ListCustomInstructionsResponse(UniversalBaseModel): + instructions: typing.Optional[typing.List[CustomInstruction]] = None + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 + else: + + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow