recallrai 0.1.0__py3-none-any.whl → 0.2.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.

Potentially problematic release.


This version of recallrai might be problematic. Click here for more details.

recallrai/__init__.py CHANGED
@@ -1,6 +1,3 @@
1
- # Path: recallrai/__init__.py
2
- # Description: Package initialization file with SDK version and main class exports
3
-
4
1
  """
5
2
  RecallrAI Python SDK
6
3
 
@@ -11,7 +8,8 @@ from .client import RecallrAI
11
8
  from .user import User
12
9
  from .session import Session
13
10
 
14
- __version__ = "0.1.0"
11
+ __version__ = "0.2.0"
12
+
15
13
  __all__ = [
16
14
  "RecallrAI",
17
15
  "User",
recallrai/client.py CHANGED
@@ -1,19 +1,18 @@
1
- # Path: recallrai/client.py
2
- # Description: Main client class for the RecallrAI SDK
3
-
4
1
  """
5
2
  Main client class for the RecallrAI SDK.
6
3
 
7
4
  This module provides the RecallrAI class, which is the primary interface for the SDK.
8
5
  """
9
6
 
10
- import uuid
11
7
  from typing import Any, Dict, Optional
12
- from pydantic import HttpUrl
13
- from .utils import HTTPClient, RecallrAIError
14
- from .models import User as UserModel, UserList, SessionStatus, SessionList
8
+ from .models import UserModel, UserList
15
9
  from .user import User
16
- from .session import Session
10
+ from .utils import HTTPClient
11
+ from .exceptions import (
12
+ UserAlreadyExistsError,
13
+ UserNotFoundError,
14
+ RecallrAIError,
15
+ )
17
16
  from logging import getLogger
18
17
 
19
18
  logger = getLogger(__name__)
@@ -28,8 +27,8 @@ class RecallrAI:
28
27
  def __init__(
29
28
  self,
30
29
  api_key: str,
31
- project_id: uuid.UUID,
32
- base_url: HttpUrl = "https://api.recallrai.com",
30
+ project_id: str,
31
+ base_url: str = "https://api.recallrai.com",
33
32
  timeout: int = 30,
34
33
  ):
35
34
  """
@@ -45,8 +44,8 @@ class RecallrAI:
45
44
  raise ValueError("API key must start with 'rai_'")
46
45
 
47
46
  self.api_key = api_key
48
- self.project_id = str(project_id)
49
- self.base_url = str(base_url)
47
+ self.project_id = project_id
48
+ self.base_url = base_url
50
49
 
51
50
  self.http = HTTPClient(
52
51
  api_key=self.api_key,
@@ -68,11 +67,19 @@ class RecallrAI:
68
67
  The created user object
69
68
 
70
69
  Raises:
71
- ValidationError: If the user_id is invalid
72
- BadRequestError: If a user with the same ID already exists
70
+ UserAlreadyExistsError: If a user with the same ID already exists
71
+ AuthenticationError: If the API key or project ID is invalid
72
+ InternalServerError: If the server encounters an error
73
+ NetworkError: If there are network issues
74
+ TimeoutError: If the request times out
75
+ RecallrAIError: For other API-related errors
73
76
  """
74
77
  response = self.http.post("/api/v1/users", data={"user_id": user_id, "metadata": metadata or {}})
75
- user_data = UserModel.from_api_response(response)
78
+ if response.status_code == 409:
79
+ raise UserAlreadyExistsError(user_id=user_id)
80
+ elif response.status_code != 201:
81
+ raise RecallrAIError("Failed to create user", http_status=response.status_code)
82
+ user_data = UserModel.from_api_response(response.json())
76
83
  return User(self.http, user_data)
77
84
 
78
85
  def get_user(self, user_id: str) -> User:
@@ -86,10 +93,19 @@ class RecallrAI:
86
93
  A User object representing the user
87
94
 
88
95
  Raises:
89
- NotFoundError: If the user is not found
96
+ UserNotFoundError: If the user is not found
97
+ AuthenticationError: If the API key or project ID is invalid
98
+ InternalServerError: If the server encounters an error
99
+ NetworkError: If there are network issues
100
+ TimeoutError: If the request times out
101
+ RecallrAIError: For other API-related errors
90
102
  """
91
103
  response = self.http.get(f"/api/v1/users/{user_id}")
92
- user_data = UserModel.from_api_response(response)
104
+ if response.status_code == 404:
105
+ raise UserNotFoundError(user_id=user_id)
106
+ elif response.status_code != 200:
107
+ raise RecallrAIError("Failed to retrieve user", http_status=response.status_code)
108
+ user_data = UserModel.from_api_response(response.json())
93
109
  return User(self.http, user_data)
94
110
 
95
111
  def list_users(self, offset: int = 0, limit: int = 10) -> UserList:
@@ -102,119 +118,15 @@ class RecallrAI:
102
118
 
103
119
  Returns:
104
120
  List of users with pagination info
105
- """
106
- response = self.http.get("/api/v1/users", params={"offset": offset, "limit": limit})
107
- return UserList.from_api_response(response)
108
-
109
- def update_user(
110
- self,
111
- user_id: str,
112
- new_metadata: Optional[Dict[str, Any]] = None,
113
- new_user_id: Optional[str] = None
114
- ) -> User:
115
- """
116
- Update a user's metadata or ID.
117
-
118
- Args:
119
- user_id: Current ID of the user
120
- new_metadata: New metadata to associate with the user
121
- new_user_id: New ID for the user
122
-
123
- Returns:
124
- The updated user
125
-
126
- Raises:
127
- NotFoundError: If the user is not found
128
- ValidationError: If the new_user_id is invalid
129
- BadRequestError: If a user with the new_user_id already exists
130
- """
131
- data = {}
132
- if new_metadata is not None:
133
- data["new_metadata"] = new_metadata
134
- if new_user_id is not None:
135
- data["new_user_id"] = new_user_id
136
-
137
- response = self.http.put(f"/api/v1/users/{user_id}", data=data)
138
- user_data = UserModel.from_api_response(response)
139
- return User(self.http, user_data)
140
-
141
- def delete_user(self, user_id: str) -> None:
142
- """
143
- Delete a user.
144
-
145
- Args:
146
- user_id: ID of the user to delete
147
-
148
- Raises:
149
- NotFoundError: If the user is not found
150
- """
151
- self.http.delete(f"/api/v1/users/{user_id}")
152
-
153
- # Session management
154
- def create_session(self, user_id: str, auto_process_after_minutes: int = -1) -> Session:
155
- """
156
- Create a new session for a user.
157
-
158
- Args:
159
- user_id: ID of the user to create the session for
160
- auto_process_after_minutes: Minutes to wait before auto-processing (-1 to disable)
161
-
162
- Returns:
163
- A Session object to interact with the created session
164
-
165
- Raises:
166
- NotFoundError: If the user is not found
167
- ValidationError: If auto_process_after_minutes is invalid
168
- """
169
- response = self.http.post(
170
- f"/api/v1/users/{user_id}/sessions",
171
- data={"auto_process_after_minutes": auto_process_after_minutes},
172
- )
173
121
 
174
- session_id = response["session_id"]
175
- return Session(self.http, user_id, session_id)
176
-
177
- def get_session(self, user_id: str, session_id: str) -> Session:
178
- """
179
- Get an existing session.
180
-
181
- Args:
182
- user_id: ID of the user who owns the session
183
- session_id: ID of the session to retrieve
184
-
185
- Returns:
186
- A Session object to interact with the session
187
-
188
122
  Raises:
189
- NotFoundError: If the user or session is not found
123
+ AuthenticationError: If the API key or project ID is invalid
124
+ InternalServerError: If the server encounters an error
125
+ NetworkError: If there are network issues
126
+ TimeoutError: If the request times out
127
+ RecallrAIError: For other API-related errors
190
128
  """
191
- # Ensure the session exists by checking its status
192
- session = Session(self.http, user_id, session_id)
193
- status = session.get_status()
194
- if status == SessionStatus.PROCESSING:
195
- raise RecallrAIError("Session is already processing. You can't add messages to it. Create a new session instead.")
196
- elif status == SessionStatus.PROCESSED:
197
- raise RecallrAIError("Session has already been processed. You can't add messages to it. Create a new session instead.")
198
-
199
- return session
200
-
201
- def list_sessions(self, user_id: str, offset: int = 0, limit: int = 10) -> SessionList:
202
- """
203
- List sessions for a user with pagination.
204
-
205
- Args:
206
- user_id: ID of the user
207
- offset: Number of records to skip
208
- limit: Maximum number of records to return
209
-
210
- Returns:
211
- List of sessions with pagination info
212
-
213
- Raises:
214
- NotFoundError: If the user is not found
215
- """
216
- response = self.http.get(
217
- f"/api/v1/users/{user_id}/sessions",
218
- params={"offset": offset, "limit": limit},
219
- )
220
- return SessionList.from_api_response(response)
129
+ response = self.http.get("/api/v1/users", params={"offset": offset, "limit": limit})
130
+ if response.status_code != 200:
131
+ raise RecallrAIError("Failed to list users", http_status=response.status_code)
132
+ return UserList.from_api_response(response.json())
@@ -0,0 +1,28 @@
1
+ """
2
+ Exceptions for the RecallrAI SDK.
3
+ """
4
+
5
+ from .auth import AuthenticationError
6
+ from .base import RecallrAIError
7
+ from .network import NetworkError, TimeoutError, ConnectionError
8
+ from .server import ServerError, InternalServerError
9
+ from .sessions import SessionError, SessionNotFoundError, InvalidSessionStateError
10
+ from .users import UserError, UserNotFoundError, UserAlreadyExistsError
11
+ from .validation import ValidationError
12
+
13
+ __all__ = [
14
+ "RecallrAIError",
15
+ "AuthenticationError",
16
+ "NetworkError",
17
+ "TimeoutError",
18
+ "ConnectionError",
19
+ "ServerError",
20
+ "InternalServerError",
21
+ "SessionError",
22
+ "SessionNotFoundError",
23
+ "InvalidSessionStateError",
24
+ "UserError",
25
+ "UserNotFoundError",
26
+ "UserAlreadyExistsError",
27
+ "ValidationError",
28
+ ]
@@ -0,0 +1,24 @@
1
+ """
2
+ Authentication-related exceptions for the RecallrAI SDK.
3
+ """
4
+
5
+ from typing import Any, Dict, Optional
6
+ from .base import RecallrAIError
7
+
8
+
9
+ class AuthenticationError(RecallrAIError):
10
+ """
11
+ Raised when there is an authentication issue with the API key.
12
+
13
+ This exception is typically raised when the API key is invalid,
14
+ has been revoked, or doesn't have the necessary permissions.
15
+ """
16
+
17
+ def __init__(
18
+ self,
19
+ message: str = "Invalid API key or authentication failed",
20
+ code: str = "authentication_error",
21
+ http_status: int = 401,
22
+ details: Optional[Dict[str, Any]] = None
23
+ ):
24
+ super().__init__(message, code, http_status, details)
@@ -0,0 +1,35 @@
1
+ """
2
+ Base exception classes for the RecallrAI SDK.
3
+ """
4
+
5
+ from typing import Any, Dict, Optional
6
+
7
+
8
+ class RecallrAIError(Exception):
9
+ """Base exception for all RecallrAI SDK errors."""
10
+
11
+ def __init__(
12
+ self,
13
+ message: str,
14
+ code: Optional[str] = None,
15
+ http_status: Optional[int] = None,
16
+ details: Optional[Dict[str, Any]] = None
17
+ ):
18
+ """
19
+ Initialize a RecallrAI error.
20
+
21
+ Args:
22
+ message: A human-readable error message
23
+ code: An optional error code
24
+ http_status: The HTTP status code that triggered this error
25
+ details: Optional additional details about the error
26
+ """
27
+ self.message = message
28
+ self.code = code
29
+ self.http_status = http_status
30
+ self.details = details or {}
31
+ super().__init__(self.message)
32
+
33
+ def __str__(self) -> str:
34
+ """Return a string representation of the error."""
35
+ return f"{self.message}. HTTP Status: {self.http_status}."
@@ -0,0 +1,58 @@
1
+ """
2
+ Network-related exceptions for the RecallrAI SDK.
3
+ """
4
+
5
+ from typing import Any, Dict, Optional
6
+ from .base import RecallrAIError
7
+
8
+
9
+ class NetworkError(RecallrAIError):
10
+ """
11
+ Base class for network-related exceptions.
12
+
13
+ This exception is raised for errors related to network connectivity
14
+ and communication with the RecallrAI API.
15
+ """
16
+
17
+ def __init__(
18
+ self,
19
+ message: str = "Network error occurred",
20
+ code: str = "network_error",
21
+ http_status: Optional[int] = None,
22
+ details: Optional[Dict[str, Any]] = None
23
+ ):
24
+ super().__init__(message, code, http_status, details)
25
+
26
+
27
+ class TimeoutError(NetworkError):
28
+ """
29
+ Raised when a request times out.
30
+
31
+ This exception is raised when a request to the RecallrAI API
32
+ takes longer than the configured timeout.
33
+ """
34
+
35
+ def __init__(
36
+ self,
37
+ message: str = "Request timed out",
38
+ code: str = "timeout",
39
+ details: Optional[Dict[str, Any]] = None
40
+ ):
41
+ super().__init__(message, code, None, details)
42
+
43
+
44
+ class ConnectionError(NetworkError):
45
+ """
46
+ Raised when a connection error occurs.
47
+
48
+ This exception is raised when there's an issue connecting to
49
+ the RecallrAI API, such as DNS resolution issues or network unavailability.
50
+ """
51
+
52
+ def __init__(
53
+ self,
54
+ message: str = "Failed to connect to the RecallrAI API",
55
+ code: str = "connection_error",
56
+ details: Optional[Dict[str, Any]] = None
57
+ ):
58
+ super().__init__(message, code, None, details)
@@ -0,0 +1,82 @@
1
+ """
2
+ Server-related exceptions for the RecallrAI SDK.
3
+ """
4
+
5
+ from typing import Any, Dict, Optional
6
+ from .base import RecallrAIError
7
+
8
+
9
+ class ServerError(RecallrAIError):
10
+ """
11
+ Base class for server-related exceptions.
12
+ """
13
+ def __init__(
14
+ self,
15
+ message: str = "Server error occurred",
16
+ code: str = "server_error",
17
+ http_status: int = 500,
18
+ details: Optional[Dict[str, Any]] = None
19
+ ):
20
+ super().__init__(message, code, http_status, details)
21
+
22
+ class InternalServerError(ServerError):
23
+ """
24
+ Raised when the RecallrAI API encounters an internal server error.
25
+
26
+ This exception is typically raised when the API returns a 5xx error code.
27
+ """
28
+
29
+ def __init__(
30
+ self,
31
+ message: str = "Internal server error",
32
+ code: str = "server_error",
33
+ http_status: int = 500,
34
+ details: Optional[Dict[str, Any]] = None
35
+ ):
36
+ super().__init__(message, code, http_status, details)
37
+
38
+
39
+ # class RateLimitError(ServerError):
40
+ # """
41
+ # Raised when the API rate limit has been exceeded.
42
+ #
43
+ # This exception is raised when too many requests are made in a
44
+ # short period of time.
45
+ # """
46
+
47
+ # def __init__(
48
+ # self,
49
+ # message: str = "API rate limit exceeded",
50
+ # code: str = "rate_limit_exceeded",
51
+ # http_status: int = 429,
52
+ # retry_after: Optional[int] = None,
53
+ # details: Optional[Dict[str, Any]] = None
54
+ # ):
55
+ # details = details or {}
56
+ # if retry_after:
57
+ # details["retry_after"] = retry_after
58
+ # super().__init__(message, code, http_status, details)
59
+ # self.retry_after = retry_after
60
+
61
+
62
+ # class ServiceUnavailableError(ServerError):
63
+ # """
64
+ # Raised when the RecallrAI service is temporarily unavailable.
65
+ #
66
+ # This exception is raised when the API is down for maintenance
67
+ # or experiencing issues.
68
+ # """
69
+
70
+ # def __init__(
71
+ # self,
72
+ # message: str = "Service temporarily unavailable",
73
+ # code: str = "service_unavailable",
74
+ # http_status: int = 503,
75
+ # retry_after: Optional[int] = None,
76
+ # details: Optional[Dict[str, Any]] = None
77
+ # ):
78
+ # details = details or {}
79
+ # if retry_after:
80
+ # details["retry_after"] = retry_after
81
+ # super().__init__(message, code, http_status, details)
82
+ # self.retry_after = retry_after
@@ -0,0 +1,60 @@
1
+ """
2
+ Sessions-related exceptions for the RecallrAI SDK.
3
+ """
4
+
5
+ from typing import Any, Dict, Optional
6
+ from .base import RecallrAIError
7
+
8
+ class SessionError(RecallrAIError):
9
+ """
10
+ Base class for session-related exceptions.
11
+
12
+ This exception is raised for errors related to session management
13
+ in the RecallrAI API.
14
+ """
15
+
16
+ def __init__(
17
+ self,
18
+ message: str = "Session error occurred",
19
+ code: str = "session_error",
20
+ http_status: Optional[int] = None,
21
+ details: Optional[Dict[str, Any]] = None
22
+ ):
23
+ super().__init__(message, code, http_status, details)
24
+
25
+ class InvalidSessionStateError(SessionError):
26
+ """
27
+ Raised when a session is in an invalid state.
28
+
29
+ This exception is typically raised when trying to perform an action
30
+ on a session that is not in the expected state.
31
+ """
32
+
33
+ def __init__(
34
+ self,
35
+ message: str = "Invalid session state",
36
+ code: str = "invalid_session_state",
37
+ http_status: int = 400,
38
+ details: Optional[Dict[str, Any]] = None
39
+ ):
40
+ super().__init__(message, code, http_status, details)
41
+
42
+ class SessionNotFoundError(SessionError):
43
+ """
44
+ Raised when a session is not found.
45
+
46
+ This exception is typically raised when trying to access or modify
47
+ a session that doesn't exist.
48
+ """
49
+
50
+ def __init__(
51
+ self,
52
+ session_id: Optional[str] = None,
53
+ message: Optional[str] = None,
54
+ code: str = "session_not_found",
55
+ http_status: int = 404,
56
+ details: Optional[Dict[str, Any]] = None
57
+ ):
58
+ message = message or f"Session{f' {session_id}' if session_id else ''} not found"
59
+ super().__init__(message, code, http_status, details)
60
+ self.session_id = session_id
@@ -0,0 +1,61 @@
1
+ """
2
+ Users-related exceptions for the RecallrAI SDK.
3
+ """
4
+
5
+ from typing import Any, Dict, Optional
6
+ from .base import RecallrAIError
7
+
8
+ class UserError(RecallrAIError):
9
+ """
10
+ Base class for user-related exceptions.
11
+
12
+ This exception is raised for errors related to user management
13
+ in the RecallrAI API.
14
+ """
15
+
16
+ def __init__(
17
+ self,
18
+ message: str = "User error occurred",
19
+ code: str = "user_error",
20
+ http_status: Optional[int] = None,
21
+ details: Optional[Dict[str, Any]] = None
22
+ ):
23
+ super().__init__(message, code, http_status, details)
24
+
25
+ class UserNotFoundError(UserError):
26
+ """
27
+ Raised when a user is not found.
28
+
29
+ This exception is typically raised when trying to access or modify
30
+ a user that doesn't exist.
31
+ """
32
+ def __init__(
33
+ self,
34
+ user_id: Optional[str] = None,
35
+ message: Optional[str] = None,
36
+ code: str = "user_not_found",
37
+ http_status: int = 404,
38
+ details: Optional[Dict[str, Any]] = None
39
+ ):
40
+ message = message or f"User{f' {user_id}' if user_id else ''} not found"
41
+ super().__init__(message, code, http_status, details)
42
+ self.user_id = user_id
43
+
44
+ class UserAlreadyExistsError(UserError):
45
+ """
46
+ Raised when a user already exists.
47
+
48
+ This exception is typically raised when trying to create a user
49
+ that already exists in the system.
50
+ """
51
+ def __init__(
52
+ self,
53
+ user_id: Optional[str] = None,
54
+ message: Optional[str] = None,
55
+ code: str = "user_already_exists",
56
+ http_status: int = 409,
57
+ details: Optional[Dict[str, Any]] = None
58
+ ):
59
+ message = message or f"User{f' {user_id}' if user_id else ''} already exists"
60
+ super().__init__(message, code, http_status, details)
61
+ self.user_id = user_id
@@ -0,0 +1,24 @@
1
+ """
2
+ Validation-related exceptions for the RecallrAI SDK.
3
+ """
4
+
5
+ from typing import Any, Dict, Optional, Union
6
+ from .base import RecallrAIError
7
+
8
+
9
+ class ValidationError(RecallrAIError):
10
+ """
11
+ Raised when request parameters fail validation.
12
+
13
+ This exception is raised when the API rejects a request
14
+ due to invalid or missing parameters.
15
+ """
16
+
17
+ def __init__(
18
+ self,
19
+ message: str = "Validation error",
20
+ code: str = "validation_error",
21
+ http_status: int = 422,
22
+ details: Optional[Dict[str, Any]] = None
23
+ ):
24
+ super().__init__(message, code, http_status, details)
@@ -1,13 +1,13 @@
1
- # Path: recallrai/models/__init__.py
2
- # Description: Package initialization for data models
3
-
4
- from .session import Context, Message, MessageRole, Session, SessionList, SessionStatus
5
- from .user import User, UserList
1
+ """
2
+ Models used in the SDK.
3
+ """
4
+ from .session import Context, Message, MessageRole, SessionModel, SessionList, SessionStatus
5
+ from .user import UserModel, UserList
6
6
 
7
7
  __all__ = [
8
- "User",
8
+ "UserModel",
9
9
  "UserList",
10
- "Session",
10
+ "SessionModel",
11
11
  "SessionList",
12
12
  "SessionStatus",
13
13
  "Message",