recallrai 0.1.0__tar.gz → 0.1.1__tar.gz

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.

@@ -0,0 +1,440 @@
1
+ Metadata-Version: 2.3
2
+ Name: recallrai
3
+ Version: 0.1.1
4
+ Summary: Official Python SDK for RecallrAI - Revolutionary contextual memory system that enables AI assistants to form meaningful connections between conversations, just like human memory.
5
+ License: MIT
6
+ Keywords: ai,memory,context,llm,mem0,getzep,zep
7
+ Author: Devasheesh Mishra
8
+ Author-email: devasheeshmishra4@gmail.com
9
+ Requires-Python: >=3.8,<4.0
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Requires-Dist: httpx (>=0.25.0,<0.26.0)
21
+ Requires-Dist: pydantic (>=2.4.0,<3.0.0)
22
+ Project-URL: Homepage, https://recallrai.com
23
+ Project-URL: Repository, https://github.com/recallrai/sdk-python
24
+ Description-Content-Type: text/markdown
25
+
26
+ # RecallrAI Python SDK
27
+
28
+ Official Python SDK for RecallrAI – a revolutionary contextual memory system that enables AI assistants to form meaningful connections between conversations, just like human memory.
29
+
30
+ ## Installation
31
+
32
+ Install the SDK via Poetry or pip:
33
+
34
+ ```bash
35
+ poetry add recallrai
36
+ # or
37
+ pip install recallrai
38
+ ```
39
+
40
+ ## Initialization
41
+
42
+ Create a client instance with your API key and project ID:
43
+
44
+ ```python
45
+ from recallrai import RecallrAI
46
+
47
+ api_key = "rai_yourapikey"
48
+ project_id = "project-uuid"
49
+ client = RecallrAI(api_key=api_key, project_id=project_id)
50
+ ```
51
+
52
+ ## User Management
53
+
54
+ ### Create a User
55
+
56
+ ```python
57
+ from recallrai.exceptions import UserAlreadyExistsError
58
+ try:
59
+ user = client.create_user(user_id="user123", metadata={"name": "John Doe"})
60
+ print(f"Created user: {user.user_id}")
61
+ print(f"User metadata: {user.metadata}")
62
+ print(f"Created at: {user.created_at}")
63
+ except UserAlreadyExistsError as e:
64
+ print(f"Error: {e}")
65
+ ```
66
+
67
+ ### Get a User
68
+
69
+ ```python
70
+ from recallrai.exceptions import UserNotFoundError
71
+ try:
72
+ user = client.get_user("user123")
73
+ print(f"User metadata: {user.metadata}")
74
+ print(f"Last active: {user.last_active_at}")
75
+ except UserNotFoundError as e:
76
+ print(f"Error: {e}")
77
+ ```
78
+
79
+ ### List Users
80
+
81
+ ```python
82
+ user_list = client.list_users(offset=0, limit=10)
83
+ print(f"Total users: {user_list.total}")
84
+ print(f"Has more users: {user_list.has_more}")
85
+
86
+ for user in user_list.users:
87
+ print(f"User ID: {user.user_id}")
88
+ print(f"Metadata: {user.metadata}")
89
+ print(f"Created at: {user.created_at}")
90
+ print(f"Last active: {user.last_active_at}")
91
+ print("---")
92
+ ```
93
+
94
+ ### Update a User
95
+
96
+ ```python
97
+ from recallrai.exceptions import UserNotFoundError, UserAlreadyExistsError
98
+ try:
99
+ user = client.get_user("user123")
100
+ updated_user = user.update(
101
+ new_metadata={"name": "John Doe", "role": "admin"},
102
+ new_user_id="john_doe"
103
+ )
104
+ print(f"Updated user ID: {updated_user.user_id}")
105
+ print(f"Updated metadata: {updated_user.metadata}")
106
+ except UserNotFoundError as e:
107
+ print(f"Error: {e}")
108
+ except UserAlreadyExistsError as e:
109
+ print(f"Error: {e}")
110
+ ```
111
+
112
+ ### Delete a User
113
+
114
+ ```python
115
+ from recallrai.exceptions import UserNotFoundError
116
+ try:
117
+ user = client.get_user("john_doe")
118
+ user.delete()
119
+ print("User deleted successfully")
120
+ except UserNotFoundError as e:
121
+ print(f"Error: {e}")
122
+ ```
123
+
124
+ ## Session Management
125
+
126
+ ### Create a Session
127
+
128
+ ```python
129
+ from recallrai.exceptions import UserNotFoundError
130
+ from recallrai.session import Session
131
+
132
+ try:
133
+ # First, get the user
134
+ user = client.get_user("user123")
135
+
136
+ # Create a session for the user; auto_process_after_minutes set to -1 disables auto-processing
137
+ session: Session = user.create_session(auto_process_after_minutes=5)
138
+ print("Created session id:", session.session_id)
139
+ except UserNotFoundError as e:
140
+ print(f"Error: {e}")
141
+ ```
142
+
143
+ ### Get an Existing Session
144
+
145
+ ```python
146
+ from recallrai.exceptions import UserNotFoundError, SessionNotFoundError
147
+
148
+ try:
149
+ # First, get the user
150
+ user = client.get_user("user123")
151
+
152
+ # Retrieve an existing session by its ID
153
+ session = user.get_session(session_id="session-uuid")
154
+ print("Session status:", session.get_status())
155
+ except UserNotFoundError as e:
156
+ print(f"Error: {e}")
157
+ except SessionNotFoundError as e:
158
+ print(f"Error: {e}")
159
+ ```
160
+
161
+ ### List Sessions
162
+
163
+ ```python
164
+ from recallrai.exceptions import UserNotFoundError
165
+
166
+ try:
167
+ # First, get the user
168
+ user = client.get_user("user123")
169
+
170
+ # List sessions for this user
171
+ session_list = user.list_sessions(offset=0, limit=10)
172
+ for session in session_list.sessions:
173
+ print(session.session_id, session.status)
174
+ except UserNotFoundError as e:
175
+ print(f"Error: {e}")
176
+ ```
177
+
178
+ ### Session – Adding Messages
179
+
180
+ ```python
181
+ from recallrai.exceptions import UserNotFoundError, SessionNotFoundError, InvalidSessionStateError
182
+
183
+ try:
184
+ # Add a user message
185
+ session.add_user_message("Hello! How are you?")
186
+
187
+ # Add an assistant message
188
+ session.add_assistant_message("I'm an assistant. How can I help you?")
189
+ except UserNotFoundError as e:
190
+ print(f"Error: {e}")
191
+ except SessionNotFoundError as e:
192
+ print(f"Error: {e}")
193
+ except InvalidSessionStateError as e:
194
+ print(f"Error: {e}")
195
+ ```
196
+
197
+ ### Session – Retrieving Context
198
+
199
+ ```python
200
+ from recallrai.exceptions import UserNotFoundError, SessionNotFoundError
201
+
202
+ try:
203
+ context = session.get_context()
204
+ print("Memory used:", context.memory_used)
205
+ print("Context:", context.context)
206
+ except UserNotFoundError as e:
207
+ print(f"Error: {e}")
208
+ except SessionNotFoundError as e:
209
+ print(f"Error: {e}")
210
+ ```
211
+
212
+ ### Session – Process Session
213
+
214
+ ```python
215
+ from recallrai.exceptions import UserNotFoundError, SessionNotFoundError, InvalidSessionStateError
216
+
217
+ try:
218
+ session.process()
219
+ except UserNotFoundError as e:
220
+ print(f"Error: {e}")
221
+ except SessionNotFoundError as e:
222
+ print(f"Error: {e}")
223
+ except InvalidSessionStateError as e:
224
+ print(f"Error: {e}")
225
+ ```
226
+
227
+ ### Session – Get Status and Messages
228
+
229
+ ```python
230
+ from recallrai.exceptions import UserNotFoundError, SessionNotFoundError
231
+ from recallrai.models import SessionStatus
232
+
233
+ try:
234
+ status = session.get_status()
235
+ print("Session status:", status)
236
+
237
+ # Check if the session is in a specific state
238
+ if status == SessionStatus.PROCESSED:
239
+ print("Session has been processed")
240
+
241
+ messages = session.get_messages()
242
+ for message in messages:
243
+ print(f"{message.role}: {message.content} at {message.timestamp}")
244
+ except UserNotFoundError as e:
245
+ print(f"Error: {e}")
246
+ except SessionNotFoundError as e:
247
+ print(f"Error: {e}")
248
+ ```
249
+
250
+ ## Example Usage with LLMs
251
+
252
+ ```python
253
+ import openai
254
+ from recallrai import RecallrAI
255
+ from recallrai.exceptions import UserNotFoundError
256
+
257
+ # Initialize RecallrAI and OpenAI clients
258
+ rai_client = RecallrAI(
259
+ api_key="rai_yourapikey",
260
+ project_id="your-project-uuid"
261
+ )
262
+ oai_client = openai.OpenAI(api_key="your-openai-api-key")
263
+
264
+ def chat_with_memory(user_id, session_id=None):
265
+ # Get or create user
266
+ try:
267
+ user = rai_client.get_user(user_id)
268
+ except UserNotFoundError:
269
+ user = rai_client.create_user(user_id)
270
+
271
+ # Create a new session or get an existing one
272
+ if session_id:
273
+ session = user.get_session(session_id=session_id)
274
+ else:
275
+ session = user.create_session(auto_process_after_minutes=30)
276
+ print(f"Created new session: {session.session_id}")
277
+
278
+ print("Chat session started. Type 'exit' to end the conversation.")
279
+
280
+ while True:
281
+ # Get user input
282
+ user_message = input("You: ")
283
+ if user_message.lower() == 'exit':
284
+ break
285
+
286
+ # Add the user message to RecallrAI
287
+ session.add_user_message(user_message)
288
+
289
+ # Get context from RecallrAI after adding the user message
290
+ context = session.get_context()
291
+
292
+ # Create a system prompt that includes the context
293
+ system_prompt = f"""You are a helpful assistant with memory of previous conversations.
294
+
295
+ MEMORIES ABOUT THE USER:
296
+ {context.context}
297
+
298
+ You can use the above memories to provide better responses to the user.
299
+ Don't mention that you have access to memories unless you are explicitly asked."""
300
+
301
+ # Get previous messages
302
+ previous_messages = session.get_messages()
303
+ previous_messages = [{"role": message.role, "content": message.content} for message in previous_messages]
304
+
305
+ # Call the LLM with the system prompt and conversation history
306
+ response = oai_client.chat.completions.create(
307
+ model="gpt-4o-mini",
308
+ messages=[
309
+ {"role": "system", "content": system_prompt},
310
+ **previous_messages,
311
+ ],
312
+ temperature=0.7
313
+ )
314
+
315
+ assistant_message = response.choices[0].message.content
316
+
317
+ # Print the assistant's response
318
+ print(f"Assistant: {assistant_message}")
319
+
320
+ # Add the assistant's response to RecallrAI
321
+ session.add_assistant_message(assistant_message)
322
+
323
+ # Process the session at the end of the conversation
324
+ print("Processing session to update memory...")
325
+ session.process()
326
+ print(f"Session ended. Session ID: {session.session_id}")
327
+ return session.session_id
328
+
329
+ # Example usage
330
+ if __name__ == "__main__":
331
+ user_id = "user123"
332
+ # To continue a previous session, uncomment below and provide the session ID
333
+ # previous_session_id = "previously-saved-session-uuid"
334
+ # session_id = chat_with_memory(user_id, previous_session_id)
335
+
336
+ # Start a new session
337
+ session_id = chat_with_memory(user_id)
338
+ print(f"To continue this conversation later, use session ID: {session_id}")
339
+ ```
340
+
341
+ ## Exception Handling
342
+
343
+ The RecallrAI SDK implements a comprehensive exception hierarchy to help you handle different error scenarios gracefully:
344
+
345
+ ### Base Exception
346
+
347
+ - **RecallrAIError**: The base exception for all SDK-specific errors. All other exceptions inherit from this.
348
+
349
+ ### Authentication Errors
350
+
351
+ - **AuthenticationError**: Raised when there's an issue with your API key or project ID authentication.
352
+
353
+ ### Network-Related Errors
354
+
355
+ - **NetworkError**: Base exception for all network-related issues.
356
+ - **TimeoutError**: Occurs when a request takes too long to complete.
357
+ - **ConnectionError**: Happens when the SDK cannot establish a connection to the RecallrAI API.
358
+
359
+ ### Server Errors
360
+
361
+ - **ServerError**: Base class for server-side errors.
362
+ - **InternalServerError**: Raised when the RecallrAI API returns a 5xx error code.
363
+
364
+ ### User-Related Errors
365
+
366
+ - **UserError**: Base for all user-related exceptions.
367
+ - **UserNotFoundError**: Raised when attempting to access a user that doesn't exist.
368
+ - **UserAlreadyExistsError**: Occurs when creating a user with an ID that already exists.
369
+
370
+ ### Session-Related Errors
371
+
372
+ - **SessionError**: Base for all session-related exceptions.
373
+ - **SessionNotFoundError**: Raised when attempting to access a non-existent session.
374
+ - **InvalidSessionStateError**: Occurs when performing an operation that's not valid for the current session state (e.g., adding a message to a processed session).
375
+
376
+ ### Input Validation Errors
377
+
378
+ - **ValidationError**: Raised when provided data doesn't meet the required format or constraints.
379
+
380
+ ### Importing Exceptions
381
+
382
+ You can import exceptions directly from the `recallrai.exceptions` module:
383
+
384
+ ```python
385
+ # Import specific exceptions
386
+ from recallrai.exceptions import UserNotFoundError, SessionNotFoundError
387
+
388
+ # Import all exceptions
389
+ from recallrai.exceptions import (
390
+ RecallrAIError,
391
+ AuthenticationError,
392
+ NetworkError,
393
+ TimeoutError,
394
+ ConnectionError,
395
+ ServerError,
396
+ InternalServerError,
397
+ SessionError,
398
+ SessionNotFoundError,
399
+ InvalidSessionStateError,
400
+ UserError,
401
+ UserNotFoundError,
402
+ UserAlreadyExistsError,
403
+ ValidationError,
404
+ )
405
+ ```
406
+
407
+ ### Best Practices for Error Handling
408
+
409
+ When implementing error handling with the RecallrAI SDK, consider these best practices:
410
+
411
+ 1. **Handle specific exceptions first**: Catch more specific exceptions before general ones.
412
+
413
+ ```python
414
+ try:
415
+ # SDK operation
416
+ except UserNotFoundError:
417
+ # Specific handling
418
+ except RecallrAIError:
419
+ # General fallback
420
+ ```
421
+
422
+ 2. **Implement retry logic for transient errors**: Network and timeout errors might be temporary.
423
+
424
+ 3. **Log detailed error information**: Exceptions contain useful information for debugging.
425
+
426
+ 4. **Handle common user flows**: For example, check if a user exists before operations, or create them if they don't:
427
+
428
+ ```python
429
+ try:
430
+ user = client.get_user(user_id)
431
+ except UserNotFoundError:
432
+ user = client.create_user(user_id)
433
+ ```
434
+
435
+ For more detailed information on specific exceptions, refer to the API documentation.
436
+
437
+ ## Conclusion
438
+
439
+ This README outlines the basic usage of the RecallrAI SDK functions for user and session management. For additional documentation and advanced usage, please see the [official documentation](https://recallrai.com) or the source code repository on [GitHub](https://github.com/recallrai/sdk-python).
440
+