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/utils/http.py DELETED
@@ -1,167 +0,0 @@
1
- # Path: recallrai/utils/http.py
2
- # Description: HTTP client utilities for the RecallrAI SDK
3
-
4
- """
5
- HTTP client utilities for making requests to the RecallrAI API.
6
- """
7
-
8
- import json
9
- from typing import Any, Dict, Optional, Tuple, Union
10
-
11
- import httpx
12
-
13
- from .exceptions import (
14
- AuthenticationError,
15
- BadRequestError,
16
- NotFoundError,
17
- RateLimitError,
18
- RecallrAIError,
19
- ServerError,
20
- ValidationError,
21
- )
22
-
23
- ACCEPTED_STATUS_CODES = [
24
- 200, # OK
25
- 201, # Created
26
- 204, # No Content
27
- ]
28
-
29
- class HTTPClient:
30
- """HTTP client for making requests to the RecallrAI API."""
31
-
32
- def __init__(
33
- self,
34
- api_key: str,
35
- project_id: str,
36
- base_url: str,
37
- timeout: int = 30,
38
- ):
39
- """
40
- Initialize the HTTP client.
41
-
42
- Args:
43
- api_key: Your RecallrAI API key
44
- project_id: Your project ID
45
- base_url: The base URL for the RecallrAI API
46
- timeout: Request timeout in seconds
47
- """
48
- self.api_key = api_key
49
- self.project_id = project_id
50
- self.base_url = base_url.rstrip("/")
51
- self.timeout = timeout
52
- self.client = httpx.Client(
53
- timeout=self.timeout,
54
- headers={
55
- "X-Api-Key": self.api_key,
56
- "X-Project-Id": self.project_id,
57
- "Content-Type": "application/json",
58
- "Accept": "application/json",
59
- "User-Agent": "RecallrAI-Python-SDK",
60
- # TODO: "SDK-Version": "0.1.0",
61
- },
62
- )
63
-
64
- def _handle_response(self, response: httpx.Response) -> Dict[str, Any]:
65
- """
66
- Handle the HTTP response and raise appropriate exceptions for errors.
67
-
68
- Args:
69
- response: The HTTP response from the API
70
-
71
- Returns:
72
- The parsed JSON response body
73
-
74
- Raises:
75
- AuthenticationError: When the API key or project ID is invalid
76
- NotFoundError: When the requested resource is not found
77
- ValidationError: When the API rejects the request due to validation errors
78
- RateLimitError: When the API rate limit has been exceeded
79
- ServerError: When the API encounters an unexpected server error
80
- RecallrAIError: For other types of errors
81
- """
82
- if response.status_code == 204:
83
- return {}
84
-
85
- try:
86
- data = response.json() if response.content else {}
87
- except json.JSONDecodeError:
88
- data = {}
89
-
90
- error_detail = data.get("detail", "Unknown error")
91
-
92
- if response.status_code in ACCEPTED_STATUS_CODES:
93
- return data
94
- elif response.status_code == 400:
95
- raise BadRequestError(message=f"Bad request: {error_detail}", details=data)
96
- elif response.status_code == 401:
97
- raise AuthenticationError(message="Invalid API key or project ID", details=data)
98
- elif response.status_code == 404:
99
- raise NotFoundError(message=f"Resource not found: {error_detail}", details=data)
100
- elif response.status_code == 422:
101
- raise ValidationError(message=f"Validation error: {error_detail}", details=data)
102
- elif response.status_code == 429:
103
- raise RateLimitError(message="API rate limit exceeded", details=data)
104
- elif response.status_code >= 500:
105
- raise ServerError(message=f"Server error: {error_detail}", details=data)
106
- else:
107
- raise RecallrAIError(
108
- message=f"Unexpected error: {response.status_code} - {error_detail}",
109
- details=data,
110
- )
111
-
112
- def request(
113
- self,
114
- method: str,
115
- path: str,
116
- params: Optional[Dict[str, Any]] = None,
117
- data: Optional[Dict[str, Any]] = None,
118
- ) -> Dict[str, Any]:
119
- """
120
- Make a request to the RecallrAI API.
121
-
122
- Args:
123
- method: HTTP method (GET, POST, PUT, DELETE)
124
- path: API endpoint path
125
- params: Query parameters
126
- data: Request body data
127
-
128
- Returns:
129
- The parsed JSON response
130
- """
131
- url = f"{self.base_url}{path}"
132
-
133
- # Filter out None values in params and data
134
- if params:
135
- params = {k: v for k, v in params.items() if v is not None}
136
-
137
- if data:
138
- data = {k: v for k, v in data.items() if v is not None}
139
-
140
- try:
141
- response = self.client.request(
142
- method=method,
143
- url=url,
144
- params=params,
145
- json=data,
146
- )
147
- return self._handle_response(response)
148
- except httpx.HTTPError as e:
149
- raise RecallrAIError(f"HTTP error: {str(e)}")
150
- except Exception as e:
151
- raise RecallrAIError(f"Unexpected error: {str(e)}")
152
-
153
- def get(self, path: str, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
154
- """Make a GET request."""
155
- return self.request("GET", path, params=params)
156
-
157
- def post(self, path: str, data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
158
- """Make a POST request."""
159
- return self.request("POST", path, data=data)
160
-
161
- def put(self, path: str, data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
162
- """Make a PUT request."""
163
- return self.request("PUT", path, data=data)
164
-
165
- def delete(self, path: str) -> Dict[str, Any]:
166
- """Make a DELETE request."""
167
- return self.request("DELETE", path)
@@ -1,268 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: recallrai
3
- Version: 0.1.0
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.user import User
58
-
59
- user_id = "user123"
60
- metadata = {"key": "value"}
61
- user = client.create_user(user_id=user_id, metadata=metadata)
62
- print("Created user:", user.user_id)
63
- ```
64
-
65
- ### Get a User
66
-
67
- ```python
68
- user = client.get_user("user123")
69
- print("User metadata:", user.metadata)
70
- ```
71
-
72
- ### List Users
73
-
74
- ```python
75
- user_list = client.list_users(offset=0, limit=10)
76
- for user in user_list.users:
77
- print(user.user_id, user.metadata)
78
- ```
79
-
80
- ### Update a User
81
-
82
- ```python
83
- # Update the user's metadata and/or change the user ID
84
- updated_user = client.update_user(user_id="user123", new_metadata={"role": "user"}, new_user_id="user1234")
85
- print("Updated user id:", updated_user.user_id)
86
- ```
87
-
88
- ### Delete a User
89
-
90
- ```python
91
- client.delete_user("user1234")
92
- print("User deleted.")
93
- ```
94
-
95
- ## Session Management
96
-
97
- ### Create a Session
98
-
99
- ```python
100
- from recallrai.session import Session
101
-
102
- # Create a session for a user; auto_process_after_minutes set to -1 disables auto-processing.
103
- session = client.create_session(user_id="user123", auto_process_after_minutes=5)
104
- print("Created session id:", session.session_id)
105
- ```
106
-
107
- ### Get an Existing Session
108
-
109
- ```python
110
- # Retrieve an existing session by its ID
111
- session = client.get_session(user_id="user123", session_id="session-uuid")
112
- print("Session status:", session.get_status())
113
- ```
114
-
115
- ### List Sessions
116
-
117
- ```python
118
- session_list = client.list_sessions(user_id="user123", offset=0, limit=10)
119
- for session in session_list.sessions:
120
- print(session.session_id, session.status)
121
- ```
122
-
123
- ### Session – Adding Messages
124
-
125
- #### Add a User Message
126
-
127
- ```python
128
- session.add_user_message("Hello! How are you?")
129
- ```
130
-
131
- ### Session – Retrieving Context
132
-
133
- ```python
134
- context = session.get_context()
135
- print("Memory used:", context.memory_used)
136
- print("Context:", context.context)
137
- ```
138
-
139
- #### Add an Assistant Message
140
-
141
- ```python
142
- session.add_assistant_message("I'm an assistant. How can I help you?")
143
- ```
144
-
145
- ### Session – Process Session
146
-
147
- ```python
148
- session.process()
149
- ```
150
-
151
- ### Session – Get Status and Messages
152
-
153
- ```python
154
- status = session.get_status()
155
- print("Session status:", status)
156
-
157
- messages = session.get_messages()
158
- for message in messages:
159
- print(f"{message.role}: {message.content} at {message.timestamp}")
160
- ```
161
-
162
- ## Example Usage with LLMs
163
-
164
- ```python
165
- import openai
166
- from recallrai import RecallrAI
167
-
168
- # Initialize RecallrAI and OpenAI clients
169
- recallrai_client = RecallrAI(api_key="rai_yourapikey", project_id="project-uuid")
170
- openai_client = openai.OpenAI(api_key="your-openai-api-key")
171
-
172
- def chat_with_memory(user_id, session_id=None):
173
- # Get or create user
174
- try:
175
- user = recallrai_client.get_user(user_id)
176
- except:
177
- user = recallrai_client.create_user(user_id)
178
-
179
- # Create a new session or get an existing one
180
- if session_id:
181
- session = recallrai_client.get_session(user_id=user_id, session_id=session_id)
182
- else:
183
- session = recallrai_client.create_session(user_id=user_id, auto_process_after_minutes=30)
184
- print(f"Created new session: {session.session_id}")
185
-
186
- print("Chat session started. Type 'exit' to end the conversation.")
187
-
188
- while True:
189
- # Get user input
190
- user_message = input("You: ")
191
- if user_message.lower() == 'exit':
192
- break
193
-
194
- # Add the user message to RecallrAI
195
- session.add_user_message(user_message)
196
-
197
- # Get context from RecallrAI after adding the user message
198
- context = session.get_context()
199
-
200
- # Create a system prompt that includes the context
201
- system_prompt = f"""You are a helpful assistant with memory of previous conversations.
202
-
203
- MEMORIES ABOUT THE USER:
204
- {context.context}
205
-
206
- You can use the above memories to provide better responses to the user.
207
- Don't mention that you have access to memories unless you are explicitly asked."""
208
-
209
- # Get previous messages
210
- previous_messages = session.get_messages()
211
- previous_messages = [{"role": message.role, "content": message.content} for message in previous_messages]
212
-
213
- # Call the LLM with the system prompt and user message
214
- response = openai_client.chat.completions.create(
215
- model="gpt-4o-mini",
216
- messages=[
217
- {"role": "system", "content": system_prompt},
218
- **previous_messages,
219
- ],
220
- temperature=0.7
221
- )
222
-
223
- assistant_message = response.choices[0].message.content
224
-
225
- # Print the assistant's response
226
- print(f"Assistant: {assistant_message}")
227
-
228
- # Add the assistant's response to RecallrAI
229
- session.add_assistant_message(assistant_message)
230
-
231
- # Process the session at the end of the conversation
232
- print("Processing session to update memory...")
233
- session.process()
234
- print(f"Session ended. Session ID: {session.session_id}")
235
- return session.session_id
236
-
237
- # Example usage
238
- if __name__ == "__main__":
239
- user_id = "user123"
240
- # To continue a previous session, uncomment below and provide the session ID
241
- # previous_session_id = "previously-saved-session-uuid"
242
- # session_id = chat_with_memory(user_id, previous_session_id)
243
-
244
- # Start a new session
245
- session_id = chat_with_memory(user_id)
246
- print(f"To continue this conversation later, use session ID: {session_id}")
247
- ```
248
-
249
- ## Exception Handling
250
-
251
- > Exception handling will be improved in future.
252
- Each operation may raise custom exceptions defined in the SDK:
253
-
254
- ```python
255
- from recallrai.utils.exceptions import NotFoundError, ValidationError
256
-
257
- try:
258
- user = client.get_user("nonexistent_id")
259
- except NotFoundError as e:
260
- print("User not found:", e.message)
261
- except ValidationError as e:
262
- print("Invalid input:", e.message)
263
- ```
264
-
265
- ## Conclusion
266
-
267
- 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).
268
-
@@ -1,13 +0,0 @@
1
- recallrai/__init__.py,sha256=lw4pmQKtKkfTZ50xY3Z3J9IRxaG1XMrvEsN-jSazeHY,385
2
- recallrai/client.py,sha256=lzD4DYL8kedr6P-9zJbf93CCt9PxmmHcSE2HzKBIU0w,6976
3
- recallrai/models/__init__.py,sha256=2wwbyVAY4IgBn1a7YcbA4i1_pXJpYPYuQo80N8PVTlI,361
4
- recallrai/models/session.py,sha256=Okn2tMmnl0UPL9q-Bl4cBaUcgs_U_nnvmKj3CHWavGY,3701
5
- recallrai/models/user.py,sha256=yu7HzceZ-U2Hp6lbRjA31SQsyfD3dmuBoQ9dVGvfZ14,2190
6
- recallrai/session.py,sha256=r045TL3a4_g0JjbCJ7VyRdhMX4JsUpVTDmMeeVwpGtY,5690
7
- recallrai/user.py,sha256=VwQhKSJrwEEV7LgGDHOIRbIfwRi7OE5V-F146CGD8kY,4035
8
- recallrai/utils/__init__.py,sha256=p_RBdfNvgBWQ62psiokCPCmZI5H7AQm8EJiRLxfHUjA,212
9
- recallrai/utils/exceptions.py,sha256=b-8ONmtUgcjJxUg68pXwnana-5zt4C0cR2rTliFBGBE,1581
10
- recallrai/utils/http.py,sha256=dGd4uUWtRDRBLZctNDNfdDr5njekMjCPBYSWcvKRpJM,5513
11
- recallrai-0.1.0.dist-info/METADATA,sha256=WU87emxQgZ4t5p8k9ipp8MwbbwDLWDmzrWyYzY_-TJg,7801
12
- recallrai-0.1.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
13
- recallrai-0.1.0.dist-info/RECORD,,