|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -from typing import TYPE_CHECKING |
| 3 | +from collections.abc import Mapping |
| 4 | +from typing import TYPE_CHECKING, Literal |
4 | 5 |
|
5 | 6 | from pangea.asyncio.services.base import ServiceBaseAsync |
6 | 7 | from pangea.config import PangeaConfig |
7 | | -from pangea.services.prompt_guard import GuardResult, Message |
| 8 | +from pangea.response import PangeaResponseResult |
| 9 | +from pangea.services.prompt_guard import ( |
| 10 | + AuditDataActivityConfig, |
| 11 | + GuardResult, |
| 12 | + Message, |
| 13 | + ServiceConfigFilter, |
| 14 | + ServiceConfigsPage, |
| 15 | +) |
8 | 16 |
|
9 | 17 | if TYPE_CHECKING: |
10 | 18 | from collections.abc import Iterable |
@@ -82,3 +90,105 @@ async def guard( |
82 | 90 | GuardResult, |
83 | 91 | data={"messages": messages, "analyzers": analyzers, "classify": classify}, |
84 | 92 | ) |
| 93 | + |
| 94 | + async def get_service_config( |
| 95 | + self, |
| 96 | + *, |
| 97 | + id: str | None = None, |
| 98 | + version: str | None = None, |
| 99 | + analyzers: Mapping[str, bool] | None = None, |
| 100 | + malicious_detection_threshold: float | None = None, |
| 101 | + benign_detection_threshold: float | None = None, |
| 102 | + audit_data_activity: AuditDataActivityConfig | None = None, |
| 103 | + ) -> PangeaResponse[PangeaResponseResult]: |
| 104 | + """ |
| 105 | + OperationId: prompt_guard_post_v1beta_config |
| 106 | + """ |
| 107 | + return await self.request.post( |
| 108 | + "v1beta/config", |
| 109 | + data={ |
| 110 | + "id": id, |
| 111 | + "version": version, |
| 112 | + "analyzers": analyzers, |
| 113 | + "malicious_detection_threshold": malicious_detection_threshold, |
| 114 | + "benign_detection_threshold": benign_detection_threshold, |
| 115 | + "audit_data_activity": audit_data_activity, |
| 116 | + }, |
| 117 | + result_class=PangeaResponseResult, |
| 118 | + ) |
| 119 | + |
| 120 | + async def create_service_config( |
| 121 | + self, |
| 122 | + *, |
| 123 | + id: str | None = None, |
| 124 | + version: str | None = None, |
| 125 | + analyzers: Mapping[str, bool] | None = None, |
| 126 | + malicious_detection_threshold: float | None = None, |
| 127 | + benign_detection_threshold: float | None = None, |
| 128 | + audit_data_activity: AuditDataActivityConfig | None = None, |
| 129 | + ) -> PangeaResponse[PangeaResponseResult]: |
| 130 | + """ |
| 131 | + OperationId: prompt_guard_post_v1beta_config_create |
| 132 | + """ |
| 133 | + return await self.request.post( |
| 134 | + "v1beta/config/create", |
| 135 | + data={ |
| 136 | + "id": id, |
| 137 | + "version": version, |
| 138 | + "analyzers": analyzers, |
| 139 | + "malicious_detection_threshold": malicious_detection_threshold, |
| 140 | + "benign_detection_threshold": benign_detection_threshold, |
| 141 | + "audit_data_activity": audit_data_activity, |
| 142 | + }, |
| 143 | + result_class=PangeaResponseResult, |
| 144 | + ) |
| 145 | + |
| 146 | + async def update_service_config( |
| 147 | + self, |
| 148 | + *, |
| 149 | + id: str | None = None, |
| 150 | + version: str | None = None, |
| 151 | + analyzers: Mapping[str, bool] | None = None, |
| 152 | + malicious_detection_threshold: float | None = None, |
| 153 | + benign_detection_threshold: float | None = None, |
| 154 | + audit_data_activity: AuditDataActivityConfig | None = None, |
| 155 | + ) -> PangeaResponse[PangeaResponseResult]: |
| 156 | + """ |
| 157 | + OperationId: prompt_guard_post_v1beta_config_update |
| 158 | + """ |
| 159 | + return await self.request.post( |
| 160 | + "v1beta/config/update", |
| 161 | + data={ |
| 162 | + "id": id, |
| 163 | + "version": version, |
| 164 | + "analyzers": analyzers, |
| 165 | + "malicious_detection_threshold": malicious_detection_threshold, |
| 166 | + "benign_detection_threshold": benign_detection_threshold, |
| 167 | + "audit_data_activity": audit_data_activity, |
| 168 | + }, |
| 169 | + result_class=PangeaResponseResult, |
| 170 | + ) |
| 171 | + |
| 172 | + async def delete_service_config(self, id: str) -> PangeaResponse[PangeaResponseResult]: |
| 173 | + """ |
| 174 | + OperationId: prompt_guard_post_v1beta_config_delete |
| 175 | + """ |
| 176 | + return await self.request.post("v1beta/config/delete", data={"id": id}, result_class=PangeaResponseResult) |
| 177 | + |
| 178 | + async def list_service_configs( |
| 179 | + self, |
| 180 | + *, |
| 181 | + filter: ServiceConfigFilter | None = None, |
| 182 | + last: str | None = None, |
| 183 | + order: Literal["asc", "desc"] | None = None, |
| 184 | + order_by: Literal["id", "created_at", "updated_at"] | None = None, |
| 185 | + size: int | None = None, |
| 186 | + ) -> PangeaResponse[ServiceConfigsPage]: |
| 187 | + """ |
| 188 | + OperationId: prompt_guard_post_v1beta_config_list |
| 189 | + """ |
| 190 | + return await self.request.post( |
| 191 | + "v1beta/config/list", |
| 192 | + data={"filter": filter, "last": last, "order": order, "order_by": order_by, "size": size}, |
| 193 | + result_class=ServiceConfigsPage, |
| 194 | + ) |
0 commit comments