sonzai 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sonzai/__init__.py +281 -0
- sonzai/_client.py +171 -0
- sonzai/_exceptions.py +44 -0
- sonzai/_http.py +275 -0
- sonzai/py.typed +0 -0
- sonzai/resources/__init__.py +26 -0
- sonzai/resources/agents.py +1927 -0
- sonzai/resources/custom_states.py +326 -0
- sonzai/resources/eval_runs.py +95 -0
- sonzai/resources/eval_templates.py +186 -0
- sonzai/resources/generation.py +383 -0
- sonzai/resources/instances.py +147 -0
- sonzai/resources/inventory.py +347 -0
- sonzai/resources/knowledge.py +662 -0
- sonzai/resources/memory.py +314 -0
- sonzai/resources/notifications.py +99 -0
- sonzai/resources/personality.py +197 -0
- sonzai/resources/priming.py +208 -0
- sonzai/resources/sessions.py +140 -0
- sonzai/resources/voice.py +689 -0
- sonzai/resources/webhooks.py +119 -0
- sonzai/types.py +1382 -0
- sonzai-1.0.0.dist-info/METADATA +479 -0
- sonzai-1.0.0.dist-info/RECORD +26 -0
- sonzai-1.0.0.dist-info/WHEEL +4 -0
- sonzai-1.0.0.dist-info/licenses/LICENSE +21 -0
sonzai/__init__.py
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"""Sonzai Python SDK - Client for the Sonzai Character Engine API."""
|
|
2
|
+
|
|
3
|
+
from ._client import AsyncSonzai, Sonzai
|
|
4
|
+
from ._exceptions import (
|
|
5
|
+
APIError,
|
|
6
|
+
AuthenticationError,
|
|
7
|
+
BadRequestError,
|
|
8
|
+
InternalServerError,
|
|
9
|
+
NotFoundError,
|
|
10
|
+
PermissionDeniedError,
|
|
11
|
+
RateLimitError,
|
|
12
|
+
SonzaiError,
|
|
13
|
+
StreamError,
|
|
14
|
+
)
|
|
15
|
+
from .types import (
|
|
16
|
+
Agent,
|
|
17
|
+
AgentCapabilities,
|
|
18
|
+
AgentIndex,
|
|
19
|
+
AgentInstance,
|
|
20
|
+
AgentListResponse,
|
|
21
|
+
AtomicFact,
|
|
22
|
+
BatchPersonalityEntry,
|
|
23
|
+
BatchPersonalityResponse,
|
|
24
|
+
Big5,
|
|
25
|
+
Big5Trait,
|
|
26
|
+
BreakthroughsResponse,
|
|
27
|
+
ChatMessage,
|
|
28
|
+
ChatResponse,
|
|
29
|
+
ChatStreamEvent,
|
|
30
|
+
ChatUsage,
|
|
31
|
+
ConsolidateResponse,
|
|
32
|
+
ConstellationResponse,
|
|
33
|
+
CustomState,
|
|
34
|
+
CustomStateListResponse,
|
|
35
|
+
CustomToolDefinition,
|
|
36
|
+
CustomToolListResponse,
|
|
37
|
+
DeleteResponse,
|
|
38
|
+
DeliveryAttemptsResponse,
|
|
39
|
+
DialogueResponse,
|
|
40
|
+
DiaryResponse,
|
|
41
|
+
EvalCategory,
|
|
42
|
+
EvalRun,
|
|
43
|
+
EvalRunListResponse,
|
|
44
|
+
EvalTemplate,
|
|
45
|
+
EvalTemplateCategory,
|
|
46
|
+
EvalTemplateListResponse,
|
|
47
|
+
EvaluationResult,
|
|
48
|
+
Fact,
|
|
49
|
+
FactHistoryResponse,
|
|
50
|
+
FactListResponse,
|
|
51
|
+
GenerateBioResponse,
|
|
52
|
+
GenerateCharacterResponse,
|
|
53
|
+
GeneratedGoal,
|
|
54
|
+
GenerateSeedMemoriesResponse,
|
|
55
|
+
Goal,
|
|
56
|
+
GoalsResponse,
|
|
57
|
+
HabitsResponse,
|
|
58
|
+
ImageGenerateResponse,
|
|
59
|
+
InitialGoal,
|
|
60
|
+
InstanceListResponse,
|
|
61
|
+
InterestsResponse,
|
|
62
|
+
InventoryBatchImportResponse,
|
|
63
|
+
InventoryDirectUpdateResponse,
|
|
64
|
+
InventoryGroupResult,
|
|
65
|
+
InventoryItem,
|
|
66
|
+
InventoryQueryResponse,
|
|
67
|
+
# Inventory
|
|
68
|
+
InventoryUpdateResponse,
|
|
69
|
+
# KB Bulk Update
|
|
70
|
+
KBBulkUpdateEntry,
|
|
71
|
+
KBBulkUpdateResponse,
|
|
72
|
+
KBCandidate,
|
|
73
|
+
KBResolutionInfo,
|
|
74
|
+
ListAllFactsResponse,
|
|
75
|
+
MemoryNode,
|
|
76
|
+
MemoryResetResponse,
|
|
77
|
+
MemoryResponse,
|
|
78
|
+
MemorySearchResponse,
|
|
79
|
+
MemorySearchResult,
|
|
80
|
+
MemorySummary,
|
|
81
|
+
MemoryTimelineResponse,
|
|
82
|
+
MoodAggregateResponse,
|
|
83
|
+
MoodResponse,
|
|
84
|
+
Notification,
|
|
85
|
+
NotificationListResponse,
|
|
86
|
+
PersonalityBehaviors,
|
|
87
|
+
PersonalityDelta,
|
|
88
|
+
PersonalityDimensions,
|
|
89
|
+
PersonalityPreferences,
|
|
90
|
+
PersonalityProfile,
|
|
91
|
+
PersonalityResponse,
|
|
92
|
+
PersonalityShift,
|
|
93
|
+
PersonalityUpdateResponse,
|
|
94
|
+
RecentShiftsResponse,
|
|
95
|
+
RelationshipResponse,
|
|
96
|
+
RunRef,
|
|
97
|
+
ScheduledWakeup,
|
|
98
|
+
SeedMemoriesResponse,
|
|
99
|
+
SessionResponse,
|
|
100
|
+
SetStatusResponse,
|
|
101
|
+
SignificantMoment,
|
|
102
|
+
SignificantMomentsResponse,
|
|
103
|
+
SimulationEvent,
|
|
104
|
+
StoredFact,
|
|
105
|
+
StructuredColumnMapping,
|
|
106
|
+
StructuredImportSpec,
|
|
107
|
+
SummariesResponse,
|
|
108
|
+
TimelineSession,
|
|
109
|
+
TimeMachineMoodSnapshot,
|
|
110
|
+
TimeMachineResponse,
|
|
111
|
+
TriggerEventResponse,
|
|
112
|
+
TTSResponse,
|
|
113
|
+
UpdateProjectResponse,
|
|
114
|
+
UserOverlayDetailResponse,
|
|
115
|
+
UserOverlaysListResponse,
|
|
116
|
+
UserPersona,
|
|
117
|
+
UserPersonalityOverlay,
|
|
118
|
+
UsersResponse,
|
|
119
|
+
Voice,
|
|
120
|
+
VoiceChatResponse,
|
|
121
|
+
VoiceListResponse,
|
|
122
|
+
VoiceMatchResponse,
|
|
123
|
+
VoiceStreamEvent,
|
|
124
|
+
VoiceStreamToken,
|
|
125
|
+
WakeupsResponse,
|
|
126
|
+
WebhookDeliveryAttempt,
|
|
127
|
+
WebhookEndpoint,
|
|
128
|
+
WebhookListResponse,
|
|
129
|
+
WebhookRegisterResponse,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
__version__ = "1.0.0"
|
|
133
|
+
|
|
134
|
+
__all__ = [
|
|
135
|
+
# Clients
|
|
136
|
+
"Sonzai",
|
|
137
|
+
"AsyncSonzai",
|
|
138
|
+
# Exceptions
|
|
139
|
+
"SonzaiError",
|
|
140
|
+
"APIError",
|
|
141
|
+
"AuthenticationError",
|
|
142
|
+
"BadRequestError",
|
|
143
|
+
"InternalServerError",
|
|
144
|
+
"NotFoundError",
|
|
145
|
+
"PermissionDeniedError",
|
|
146
|
+
"RateLimitError",
|
|
147
|
+
"StreamError",
|
|
148
|
+
# Types - Agent CRUD
|
|
149
|
+
"Agent",
|
|
150
|
+
"AgentCapabilities",
|
|
151
|
+
"AgentIndex",
|
|
152
|
+
"AgentListResponse",
|
|
153
|
+
"DeleteResponse",
|
|
154
|
+
"SetStatusResponse",
|
|
155
|
+
"UpdateProjectResponse",
|
|
156
|
+
# Types - Chat
|
|
157
|
+
"ChatMessage",
|
|
158
|
+
"ChatResponse",
|
|
159
|
+
"ChatStreamEvent",
|
|
160
|
+
"ChatUsage",
|
|
161
|
+
# Types - Dialogue / Events
|
|
162
|
+
"DialogueResponse",
|
|
163
|
+
"TriggerEventResponse",
|
|
164
|
+
# Types - Memory
|
|
165
|
+
"AtomicFact",
|
|
166
|
+
"Fact",
|
|
167
|
+
"FactHistoryResponse",
|
|
168
|
+
"FactListResponse",
|
|
169
|
+
"MemoryNode",
|
|
170
|
+
"MemoryResetResponse",
|
|
171
|
+
"MemoryResponse",
|
|
172
|
+
"MemorySearchResponse",
|
|
173
|
+
"MemorySearchResult",
|
|
174
|
+
"MemorySummary",
|
|
175
|
+
"MemoryTimelineResponse",
|
|
176
|
+
"SeedMemoriesResponse",
|
|
177
|
+
"TimelineSession",
|
|
178
|
+
# Types - Personality
|
|
179
|
+
"BatchPersonalityEntry",
|
|
180
|
+
"BatchPersonalityResponse",
|
|
181
|
+
"Big5",
|
|
182
|
+
"Big5Trait",
|
|
183
|
+
"PersonalityBehaviors",
|
|
184
|
+
"PersonalityDelta",
|
|
185
|
+
"PersonalityDimensions",
|
|
186
|
+
"PersonalityPreferences",
|
|
187
|
+
"PersonalityProfile",
|
|
188
|
+
"PersonalityResponse",
|
|
189
|
+
"PersonalityShift",
|
|
190
|
+
"PersonalityUpdateResponse",
|
|
191
|
+
"RecentShiftsResponse",
|
|
192
|
+
"SignificantMoment",
|
|
193
|
+
"SignificantMomentsResponse",
|
|
194
|
+
"UserOverlayDetailResponse",
|
|
195
|
+
"UserOverlaysListResponse",
|
|
196
|
+
"UserPersonalityOverlay",
|
|
197
|
+
# Types - Context Engine
|
|
198
|
+
"BreakthroughsResponse",
|
|
199
|
+
"ConstellationResponse",
|
|
200
|
+
"DiaryResponse",
|
|
201
|
+
"Goal",
|
|
202
|
+
"GoalsResponse",
|
|
203
|
+
"InitialGoal",
|
|
204
|
+
"HabitsResponse",
|
|
205
|
+
"InterestsResponse",
|
|
206
|
+
"MoodAggregateResponse",
|
|
207
|
+
"MoodResponse",
|
|
208
|
+
"RelationshipResponse",
|
|
209
|
+
"UsersResponse",
|
|
210
|
+
"WakeupsResponse",
|
|
211
|
+
# Types - Instances
|
|
212
|
+
"AgentInstance",
|
|
213
|
+
"InstanceListResponse",
|
|
214
|
+
# Types - Notifications
|
|
215
|
+
"Notification",
|
|
216
|
+
"NotificationListResponse",
|
|
217
|
+
# Types - Sessions
|
|
218
|
+
"SessionResponse",
|
|
219
|
+
# Types - Voice
|
|
220
|
+
"TTSResponse",
|
|
221
|
+
"Voice",
|
|
222
|
+
"VoiceChatResponse",
|
|
223
|
+
"VoiceListResponse",
|
|
224
|
+
"VoiceMatchResponse",
|
|
225
|
+
"VoiceStreamEvent",
|
|
226
|
+
"VoiceStreamToken",
|
|
227
|
+
# Types - Generation
|
|
228
|
+
"GenerateBioResponse",
|
|
229
|
+
"GenerateCharacterResponse",
|
|
230
|
+
"GeneratedGoal",
|
|
231
|
+
"GenerateSeedMemoriesResponse",
|
|
232
|
+
"ImageGenerateResponse",
|
|
233
|
+
# Types - Custom States
|
|
234
|
+
"CustomState",
|
|
235
|
+
"CustomStateListResponse",
|
|
236
|
+
# Types - Webhooks
|
|
237
|
+
"DeliveryAttemptsResponse",
|
|
238
|
+
"WebhookDeliveryAttempt",
|
|
239
|
+
"WebhookEndpoint",
|
|
240
|
+
"WebhookListResponse",
|
|
241
|
+
"WebhookRegisterResponse",
|
|
242
|
+
# Types - Wakeups
|
|
243
|
+
"ScheduledWakeup",
|
|
244
|
+
# Types - Capabilities
|
|
245
|
+
"CustomToolDefinition",
|
|
246
|
+
"CustomToolListResponse",
|
|
247
|
+
# Types - Consolidation / Summaries
|
|
248
|
+
"ConsolidateResponse",
|
|
249
|
+
"SummariesResponse",
|
|
250
|
+
# Types - Time Machine
|
|
251
|
+
"TimeMachineMoodSnapshot",
|
|
252
|
+
"TimeMachineResponse",
|
|
253
|
+
# Types - Evaluation
|
|
254
|
+
"EvalCategory",
|
|
255
|
+
"EvalRun",
|
|
256
|
+
"EvalRunListResponse",
|
|
257
|
+
"EvalTemplate",
|
|
258
|
+
"EvalTemplateCategory",
|
|
259
|
+
"EvalTemplateListResponse",
|
|
260
|
+
"EvaluationResult",
|
|
261
|
+
"RunRef",
|
|
262
|
+
"SimulationEvent",
|
|
263
|
+
# Types - User Persona
|
|
264
|
+
"UserPersona",
|
|
265
|
+
# Types - Inventory
|
|
266
|
+
"InventoryUpdateResponse",
|
|
267
|
+
"InventoryQueryResponse",
|
|
268
|
+
"InventoryItem",
|
|
269
|
+
"InventoryGroupResult",
|
|
270
|
+
"InventoryBatchImportResponse",
|
|
271
|
+
"InventoryDirectUpdateResponse",
|
|
272
|
+
"KBResolutionInfo",
|
|
273
|
+
"KBCandidate",
|
|
274
|
+
"StoredFact",
|
|
275
|
+
"ListAllFactsResponse",
|
|
276
|
+
"StructuredColumnMapping",
|
|
277
|
+
"StructuredImportSpec",
|
|
278
|
+
# Types - KB Bulk Update
|
|
279
|
+
"KBBulkUpdateEntry",
|
|
280
|
+
"KBBulkUpdateResponse",
|
|
281
|
+
]
|
sonzai/_client.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""Main Sonzai client classes."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from ._http import AsyncHTTPClient, HTTPClient
|
|
8
|
+
from .resources.agents import Agents, AsyncAgents
|
|
9
|
+
from .resources.eval_runs import AsyncEvalRuns, EvalRuns
|
|
10
|
+
from .resources.eval_templates import AsyncEvalTemplates, EvalTemplates
|
|
11
|
+
from .resources.knowledge import AsyncKnowledge, Knowledge
|
|
12
|
+
from .resources.voice import AsyncVoices, Voices
|
|
13
|
+
from .resources.webhooks import AsyncWebhooks, Webhooks
|
|
14
|
+
|
|
15
|
+
DEFAULT_BASE_URL = "https://api.sonz.ai"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Sonzai:
|
|
19
|
+
"""Synchronous client for the Sonzai Character Engine API.
|
|
20
|
+
|
|
21
|
+
Usage::
|
|
22
|
+
|
|
23
|
+
from sonzai import Sonzai
|
|
24
|
+
|
|
25
|
+
client = Sonzai(api_key="your-api-key")
|
|
26
|
+
|
|
27
|
+
# Create an agent
|
|
28
|
+
agent = client.agents.create(name="Luna")
|
|
29
|
+
|
|
30
|
+
# Chat with an agent
|
|
31
|
+
response = client.agents.chat(
|
|
32
|
+
agent_id="agent-id",
|
|
33
|
+
messages=[{"role": "user", "content": "Hello!"}],
|
|
34
|
+
)
|
|
35
|
+
print(response.content)
|
|
36
|
+
|
|
37
|
+
# Stream chat
|
|
38
|
+
for event in client.agents.chat(
|
|
39
|
+
agent_id="agent-id",
|
|
40
|
+
messages=[{"role": "user", "content": "Tell me a story"}],
|
|
41
|
+
stream=True,
|
|
42
|
+
):
|
|
43
|
+
print(event.content, end="", flush=True)
|
|
44
|
+
|
|
45
|
+
client.close()
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
agents: Agents
|
|
49
|
+
knowledge: Knowledge
|
|
50
|
+
eval_templates: EvalTemplates
|
|
51
|
+
eval_runs: EvalRuns
|
|
52
|
+
voices: Voices
|
|
53
|
+
webhooks: Webhooks
|
|
54
|
+
|
|
55
|
+
def __init__(
|
|
56
|
+
self,
|
|
57
|
+
*,
|
|
58
|
+
api_key: str | None = None,
|
|
59
|
+
base_url: str | None = None,
|
|
60
|
+
timeout: float = 30.0,
|
|
61
|
+
max_retries: int = 2,
|
|
62
|
+
) -> None:
|
|
63
|
+
"""Initialize the Sonzai client.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
api_key: Your project API key. Falls back to ``SONZAI_API_KEY`` env var.
|
|
67
|
+
base_url: API base URL. Falls back to ``SONZAI_BASE_URL`` or the default.
|
|
68
|
+
timeout: Request timeout in seconds.
|
|
69
|
+
max_retries: Maximum number of retries for failed requests.
|
|
70
|
+
"""
|
|
71
|
+
resolved_key = api_key or os.environ.get("SONZAI_API_KEY", "")
|
|
72
|
+
if not resolved_key:
|
|
73
|
+
raise ValueError(
|
|
74
|
+
"api_key must be provided or set via the SONZAI_API_KEY environment variable"
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
resolved_url = base_url or os.environ.get("SONZAI_BASE_URL", DEFAULT_BASE_URL)
|
|
78
|
+
|
|
79
|
+
self._http = HTTPClient(
|
|
80
|
+
base_url=resolved_url,
|
|
81
|
+
api_key=resolved_key,
|
|
82
|
+
timeout=timeout,
|
|
83
|
+
max_retries=max_retries,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
self.agents = Agents(self._http)
|
|
87
|
+
self.knowledge = Knowledge(self._http)
|
|
88
|
+
self.eval_templates = EvalTemplates(self._http)
|
|
89
|
+
self.eval_runs = EvalRuns(self._http)
|
|
90
|
+
self.voices = Voices(self._http)
|
|
91
|
+
self.webhooks = Webhooks(self._http)
|
|
92
|
+
|
|
93
|
+
def close(self) -> None:
|
|
94
|
+
"""Close the underlying HTTP client."""
|
|
95
|
+
self._http.close()
|
|
96
|
+
|
|
97
|
+
def __enter__(self) -> Sonzai:
|
|
98
|
+
return self
|
|
99
|
+
|
|
100
|
+
def __exit__(self, *args: object) -> None:
|
|
101
|
+
self.close()
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class AsyncSonzai:
|
|
105
|
+
"""Asynchronous client for the Sonzai Character Engine API.
|
|
106
|
+
|
|
107
|
+
Usage::
|
|
108
|
+
|
|
109
|
+
import asyncio
|
|
110
|
+
from sonzai import AsyncSonzai
|
|
111
|
+
|
|
112
|
+
async def main():
|
|
113
|
+
client = AsyncSonzai(api_key="your-api-key")
|
|
114
|
+
|
|
115
|
+
response = await client.agents.chat(
|
|
116
|
+
"agent-id",
|
|
117
|
+
messages=[{"role": "user", "content": "Hello!"}],
|
|
118
|
+
)
|
|
119
|
+
print(response.content)
|
|
120
|
+
|
|
121
|
+
await client.close()
|
|
122
|
+
|
|
123
|
+
asyncio.run(main())
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
agents: AsyncAgents
|
|
127
|
+
knowledge: AsyncKnowledge
|
|
128
|
+
eval_templates: AsyncEvalTemplates
|
|
129
|
+
eval_runs: AsyncEvalRuns
|
|
130
|
+
voices: AsyncVoices
|
|
131
|
+
webhooks: AsyncWebhooks
|
|
132
|
+
|
|
133
|
+
def __init__(
|
|
134
|
+
self,
|
|
135
|
+
*,
|
|
136
|
+
api_key: str | None = None,
|
|
137
|
+
base_url: str | None = None,
|
|
138
|
+
timeout: float = 30.0,
|
|
139
|
+
max_retries: int = 2,
|
|
140
|
+
) -> None:
|
|
141
|
+
resolved_key = api_key or os.environ.get("SONZAI_API_KEY", "")
|
|
142
|
+
if not resolved_key:
|
|
143
|
+
raise ValueError(
|
|
144
|
+
"api_key must be provided or set via the SONZAI_API_KEY environment variable"
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
resolved_url = base_url or os.environ.get("SONZAI_BASE_URL", DEFAULT_BASE_URL)
|
|
148
|
+
|
|
149
|
+
self._http = AsyncHTTPClient(
|
|
150
|
+
base_url=resolved_url,
|
|
151
|
+
api_key=resolved_key,
|
|
152
|
+
timeout=timeout,
|
|
153
|
+
max_retries=max_retries,
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
self.agents = AsyncAgents(self._http)
|
|
157
|
+
self.knowledge = AsyncKnowledge(self._http)
|
|
158
|
+
self.eval_templates = AsyncEvalTemplates(self._http)
|
|
159
|
+
self.eval_runs = AsyncEvalRuns(self._http)
|
|
160
|
+
self.voices = AsyncVoices(self._http)
|
|
161
|
+
self.webhooks = AsyncWebhooks(self._http)
|
|
162
|
+
|
|
163
|
+
async def close(self) -> None:
|
|
164
|
+
"""Close the underlying HTTP client."""
|
|
165
|
+
await self._http.close()
|
|
166
|
+
|
|
167
|
+
async def __aenter__(self) -> AsyncSonzai:
|
|
168
|
+
return self
|
|
169
|
+
|
|
170
|
+
async def __aexit__(self, *args: object) -> None:
|
|
171
|
+
await self.close()
|
sonzai/_exceptions.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SonzaiError(Exception):
|
|
5
|
+
"""Base exception for all Sonzai SDK errors."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AuthenticationError(SonzaiError):
|
|
9
|
+
"""Raised when the API key is invalid or missing."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, message: str = "Invalid or missing API key") -> None:
|
|
12
|
+
super().__init__(message)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class NotFoundError(SonzaiError):
|
|
16
|
+
"""Raised when the requested resource is not found."""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class BadRequestError(SonzaiError):
|
|
20
|
+
"""Raised when the request is invalid."""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class PermissionDeniedError(SonzaiError):
|
|
24
|
+
"""Raised when the API key lacks permission for the operation."""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class RateLimitError(SonzaiError):
|
|
28
|
+
"""Raised when rate limit is exceeded."""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class InternalServerError(SonzaiError):
|
|
32
|
+
"""Raised when the server returns a 5xx error."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class APIError(SonzaiError):
|
|
36
|
+
"""Raised for unexpected API errors."""
|
|
37
|
+
|
|
38
|
+
def __init__(self, status_code: int, message: str) -> None:
|
|
39
|
+
self.status_code = status_code
|
|
40
|
+
super().__init__(f"[{status_code}] {message}")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class StreamError(SonzaiError):
|
|
44
|
+
"""Raised when an error occurs during SSE streaming."""
|