libro-sdk 0.1.0__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.
- libro_sdk-0.1.0/PKG-INFO +45 -0
- libro_sdk-0.1.0/README.md +33 -0
- libro_sdk-0.1.0/libro/__init__.py +3 -0
- libro_sdk-0.1.0/libro/client.py +77 -0
- libro_sdk-0.1.0/libro_sdk.egg-info/PKG-INFO +45 -0
- libro_sdk-0.1.0/libro_sdk.egg-info/SOURCES.txt +9 -0
- libro_sdk-0.1.0/libro_sdk.egg-info/dependency_links.txt +1 -0
- libro_sdk-0.1.0/libro_sdk.egg-info/requires.txt +5 -0
- libro_sdk-0.1.0/libro_sdk.egg-info/top_level.txt +1 -0
- libro_sdk-0.1.0/pyproject.toml +22 -0
- libro_sdk-0.1.0/setup.cfg +4 -0
libro_sdk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: libro-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for the Libro AI memory infrastructure.
|
|
5
|
+
Author: Libro Team
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: requests>=2.25.0
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
11
|
+
Requires-Dist: mypy>=1.0; extra == "dev"
|
|
12
|
+
|
|
13
|
+
# Libro Python SDK
|
|
14
|
+
|
|
15
|
+
Official Python SDK for Libro, the open-source AI memory infrastructure.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install libro-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from libro import LibroClient
|
|
27
|
+
|
|
28
|
+
# Initialize the client
|
|
29
|
+
client = LibroClient(api_key="your_api_key", base_url="http://localhost:3000")
|
|
30
|
+
|
|
31
|
+
# 1. Ingest a memory
|
|
32
|
+
client.ingest(
|
|
33
|
+
user_id="user_123",
|
|
34
|
+
text="User prefers Python over Java",
|
|
35
|
+
metadata={"source": "slack"}
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# 2. Retrieve context
|
|
39
|
+
context = client.get_context(
|
|
40
|
+
user_id="user_123",
|
|
41
|
+
query="What programming language do they like?"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
print(context)
|
|
45
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Libro Python SDK
|
|
2
|
+
|
|
3
|
+
Official Python SDK for Libro, the open-source AI memory infrastructure.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install libro-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from libro import LibroClient
|
|
15
|
+
|
|
16
|
+
# Initialize the client
|
|
17
|
+
client = LibroClient(api_key="your_api_key", base_url="http://localhost:3000")
|
|
18
|
+
|
|
19
|
+
# 1. Ingest a memory
|
|
20
|
+
client.ingest(
|
|
21
|
+
user_id="user_123",
|
|
22
|
+
text="User prefers Python over Java",
|
|
23
|
+
metadata={"source": "slack"}
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
# 2. Retrieve context
|
|
27
|
+
context = client.get_context(
|
|
28
|
+
user_id="user_123",
|
|
29
|
+
query="What programming language do they like?"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
print(context)
|
|
33
|
+
```
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import requests
|
|
3
|
+
from typing import Dict, Any, List, Optional
|
|
4
|
+
|
|
5
|
+
class LibroError(Exception):
|
|
6
|
+
"""Base exception for Libro SDK errors."""
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
class LibroClient:
|
|
10
|
+
def __init__(self, api_key: Optional[str] = None, base_url: str = "https://api.libro.ai"):
|
|
11
|
+
self.api_key = api_key or os.environ.get("LIBRO_API_KEY")
|
|
12
|
+
if not self.api_key:
|
|
13
|
+
raise ValueError("API key is required. Pass it to the client or set LIBRO_API_KEY env var.")
|
|
14
|
+
|
|
15
|
+
# Remove trailing slash
|
|
16
|
+
self.base_url = base_url.rstrip("/")
|
|
17
|
+
self.session = requests.Session()
|
|
18
|
+
self.session.headers.update({
|
|
19
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
20
|
+
"Content-Type": "application/json"
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
def ingest(self, user_id: str, text: str, metadata: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
24
|
+
"""Ingest a new memory for a user."""
|
|
25
|
+
payload = {"userId": user_id, "text": text}
|
|
26
|
+
if metadata is not None:
|
|
27
|
+
payload["metadata"] = metadata
|
|
28
|
+
|
|
29
|
+
res = self.session.post(f"{self.base_url}/api/v1/ingest", json=payload)
|
|
30
|
+
self._check_response(res)
|
|
31
|
+
return res.json()
|
|
32
|
+
|
|
33
|
+
def get_context(self, user_id: str, query: str) -> Dict[str, Any]:
|
|
34
|
+
"""Retrieve relevant context for a user based on a query."""
|
|
35
|
+
payload = {"userId": user_id, "query": query}
|
|
36
|
+
res = self.session.post(f"{self.base_url}/api/v1/get-context", json=payload)
|
|
37
|
+
self._check_response(res)
|
|
38
|
+
return res.json()
|
|
39
|
+
|
|
40
|
+
def forget(self, user_id: str, memory_id: Optional[str] = None, query: Optional[str] = None) -> Dict[str, Any]:
|
|
41
|
+
"""Delete a specific memory by ID, or memories matching a query for a user."""
|
|
42
|
+
if not memory_id and not query:
|
|
43
|
+
raise ValueError("Must provide either memory_id or query to forget.")
|
|
44
|
+
|
|
45
|
+
payload = {"userId": user_id}
|
|
46
|
+
if memory_id:
|
|
47
|
+
payload["memoryId"] = memory_id
|
|
48
|
+
if query:
|
|
49
|
+
payload["query"] = query
|
|
50
|
+
|
|
51
|
+
res = self.session.post(f"{self.base_url}/api/v1/forget", json=payload)
|
|
52
|
+
self._check_response(res)
|
|
53
|
+
return res.json()
|
|
54
|
+
|
|
55
|
+
def update(self, user_id: str, memory_id: str, text: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
56
|
+
"""Update an existing memory's text or metadata."""
|
|
57
|
+
if not text and not metadata:
|
|
58
|
+
raise ValueError("Must provide either text or metadata to update.")
|
|
59
|
+
|
|
60
|
+
payload = {"userId": user_id, "memoryId": memory_id}
|
|
61
|
+
if text:
|
|
62
|
+
payload["text"] = text
|
|
63
|
+
if metadata is not None:
|
|
64
|
+
payload["metadata"] = metadata
|
|
65
|
+
|
|
66
|
+
res = self.session.post(f"{self.base_url}/api/v1/update", json=payload)
|
|
67
|
+
self._check_response(res)
|
|
68
|
+
return res.json()
|
|
69
|
+
|
|
70
|
+
def _check_response(self, response: requests.Response):
|
|
71
|
+
if not response.ok:
|
|
72
|
+
try:
|
|
73
|
+
err_data = response.json()
|
|
74
|
+
msg = err_data.get("error", response.text)
|
|
75
|
+
except Exception:
|
|
76
|
+
msg = response.text
|
|
77
|
+
raise LibroError(f"API Error {response.status_code}: {msg}")
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: libro-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for the Libro AI memory infrastructure.
|
|
5
|
+
Author: Libro Team
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: requests>=2.25.0
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
11
|
+
Requires-Dist: mypy>=1.0; extra == "dev"
|
|
12
|
+
|
|
13
|
+
# Libro Python SDK
|
|
14
|
+
|
|
15
|
+
Official Python SDK for Libro, the open-source AI memory infrastructure.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install libro-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from libro import LibroClient
|
|
27
|
+
|
|
28
|
+
# Initialize the client
|
|
29
|
+
client = LibroClient(api_key="your_api_key", base_url="http://localhost:3000")
|
|
30
|
+
|
|
31
|
+
# 1. Ingest a memory
|
|
32
|
+
client.ingest(
|
|
33
|
+
user_id="user_123",
|
|
34
|
+
text="User prefers Python over Java",
|
|
35
|
+
metadata={"source": "slack"}
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# 2. Retrieve context
|
|
39
|
+
context = client.get_context(
|
|
40
|
+
user_id="user_123",
|
|
41
|
+
query="What programming language do they like?"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
print(context)
|
|
45
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
libro
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=42", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "libro-sdk"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Official Python SDK for the Libro AI memory infrastructure."
|
|
9
|
+
authors = [
|
|
10
|
+
{ name="Libro Team" }
|
|
11
|
+
]
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
dependencies = [
|
|
15
|
+
"requests>=2.25.0"
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[project.optional-dependencies]
|
|
19
|
+
dev = [
|
|
20
|
+
"pytest>=7.0",
|
|
21
|
+
"mypy>=1.0"
|
|
22
|
+
]
|