beru-ai 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.
@@ -0,0 +1,21 @@
1
+ .env
2
+ .env.*
3
+ !.env.example
4
+ __pycache__/
5
+ *.pyc
6
+ .venv/
7
+ .mypy_cache/
8
+ .ruff_cache/
9
+ .pytest_cache/
10
+ .coverage
11
+ htmlcov/
12
+ node_modules/
13
+ .next/
14
+ out/
15
+ *.tsbuildinfo
16
+ .DS_Store
17
+ var/
18
+ apps/api/evals/results/
19
+ .vercel/
20
+ apps/api/railway.json
21
+ .neon
beru_ai-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,85 @@
1
+ Metadata-Version: 2.5
2
+ Name: beru-ai
3
+ Version: 0.1.0
4
+ Summary: Official Python client for Beru: cited answers and per-user memory from your documents.
5
+ Project-URL: Documentation, https://docs.airesearchlabs.si
6
+ Project-URL: Homepage, https://airesearchlabs.si/beru
7
+ License-Expression: MIT
8
+ Keywords: beru,citations,memory,rag,retrieval
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Typing :: Typed
11
+ Requires-Python: >=3.11
12
+ Requires-Dist: anyio>=4
13
+ Requires-Dist: httpx<1,>=0.27
14
+ Description-Content-Type: text/markdown
15
+
16
+ # Beru for Python
17
+
18
+ The official Python client for [Beru](https://airesearchlabs.si/beru): answers rooted in your
19
+ documents, with citations and per-user memory.
20
+
21
+ ```sh
22
+ pip install beru-ai # imported as `beru`
23
+ ```
24
+
25
+ ```python
26
+ from beru import Beru
27
+
28
+ beru = Beru() # reads BERU_API_KEY; create a key in the Beru console under API keys
29
+
30
+ with open("handbook.pdf", "rb") as f:
31
+ document = beru.documents.upload(f, filename="handbook.pdf")
32
+ beru.documents.wait_until_ready(document["id"])
33
+
34
+ answer = beru.answer("How many days of annual leave do I get?", end_user_id="user_123")
35
+ print(answer["answer"])
36
+ for citation in answer["citations"]:
37
+ print(citation["number"], citation["document_title"], citation["page_from"])
38
+
39
+ # A follow-up in the same conversation
40
+ follow_up = beru.answer(
41
+ "And part-time staff?",
42
+ end_user_id="user_123",
43
+ conversation_id=answer["conversation_id"],
44
+ )
45
+ ```
46
+
47
+ Stream an answer as it's written:
48
+
49
+ ```python
50
+ for event in beru.answer_stream("Is parking free?"):
51
+ if event.type == "delta":
52
+ print(event.text, end="", flush=True)
53
+ else:
54
+ print("\nSources:", event.answer["citations"])
55
+ ```
56
+
57
+ `AsyncBeru` has the same methods, awaited:
58
+
59
+ ```python
60
+ from beru import AsyncBeru
61
+
62
+ async with AsyncBeru() as beru:
63
+ answer = await beru.answer("Is parking free?")
64
+ ```
65
+
66
+ ## What's included
67
+
68
+ | Method | API |
69
+ |---|---|
70
+ | `documents.upload`, `add_url`, `list`, `get`, `delete`, `wait_until_ready` | `/v1/documents` |
71
+ | `retrieve` (for your own model), `answer`, `answer_stream`, `feedback` | `/v1/retrieve`, `/v1/answer`, `/v1/feedback` |
72
+ | `memories.add`, `extract`, `list`, `delete` | `/v1/memories` |
73
+ | `end_users.erase` | `/v1/end-users/{id}` |
74
+ | `usage` | `/v1/usage` |
75
+
76
+ Responses are typed dictionaries (`beru.types`) generated from Beru's OpenAPI file.
77
+
78
+ ## Errors and retries
79
+
80
+ Every error is a `BeruError` with `code` (for example `plan_limit_exceeded`), `status`, `message`
81
+ and `request_id`. Rate limits (429) are retried, honouring `Retry-After`; reads and uploads are also
82
+ retried after timeouts and temporary outages. Uploads carry an `Idempotency-Key`, so a retry never
83
+ uploads twice. Set `max_retries=0` to turn retries off.
84
+
85
+ Docs: [docs.airesearchlabs.si](https://docs.airesearchlabs.si) · Support: support@airesearchlabs.si
@@ -0,0 +1,70 @@
1
+ # Beru for Python
2
+
3
+ The official Python client for [Beru](https://airesearchlabs.si/beru): answers rooted in your
4
+ documents, with citations and per-user memory.
5
+
6
+ ```sh
7
+ pip install beru-ai # imported as `beru`
8
+ ```
9
+
10
+ ```python
11
+ from beru import Beru
12
+
13
+ beru = Beru() # reads BERU_API_KEY; create a key in the Beru console under API keys
14
+
15
+ with open("handbook.pdf", "rb") as f:
16
+ document = beru.documents.upload(f, filename="handbook.pdf")
17
+ beru.documents.wait_until_ready(document["id"])
18
+
19
+ answer = beru.answer("How many days of annual leave do I get?", end_user_id="user_123")
20
+ print(answer["answer"])
21
+ for citation in answer["citations"]:
22
+ print(citation["number"], citation["document_title"], citation["page_from"])
23
+
24
+ # A follow-up in the same conversation
25
+ follow_up = beru.answer(
26
+ "And part-time staff?",
27
+ end_user_id="user_123",
28
+ conversation_id=answer["conversation_id"],
29
+ )
30
+ ```
31
+
32
+ Stream an answer as it's written:
33
+
34
+ ```python
35
+ for event in beru.answer_stream("Is parking free?"):
36
+ if event.type == "delta":
37
+ print(event.text, end="", flush=True)
38
+ else:
39
+ print("\nSources:", event.answer["citations"])
40
+ ```
41
+
42
+ `AsyncBeru` has the same methods, awaited:
43
+
44
+ ```python
45
+ from beru import AsyncBeru
46
+
47
+ async with AsyncBeru() as beru:
48
+ answer = await beru.answer("Is parking free?")
49
+ ```
50
+
51
+ ## What's included
52
+
53
+ | Method | API |
54
+ |---|---|
55
+ | `documents.upload`, `add_url`, `list`, `get`, `delete`, `wait_until_ready` | `/v1/documents` |
56
+ | `retrieve` (for your own model), `answer`, `answer_stream`, `feedback` | `/v1/retrieve`, `/v1/answer`, `/v1/feedback` |
57
+ | `memories.add`, `extract`, `list`, `delete` | `/v1/memories` |
58
+ | `end_users.erase` | `/v1/end-users/{id}` |
59
+ | `usage` | `/v1/usage` |
60
+
61
+ Responses are typed dictionaries (`beru.types`) generated from Beru's OpenAPI file.
62
+
63
+ ## Errors and retries
64
+
65
+ Every error is a `BeruError` with `code` (for example `plan_limit_exceeded`), `status`, `message`
66
+ and `request_id`. Rate limits (429) are retried, honouring `Retry-After`; reads and uploads are also
67
+ retried after timeouts and temporary outages. Uploads carry an `Idempotency-Key`, so a retry never
68
+ uploads twice. Set `max_retries=0` to turn retries off.
69
+
70
+ Docs: [docs.airesearchlabs.si](https://docs.airesearchlabs.si) · Support: support@airesearchlabs.si
@@ -0,0 +1,49 @@
1
+ [project]
2
+ name = "beru-ai"
3
+ version = "0.1.0"
4
+ description = "Official Python client for Beru: cited answers and per-user memory from your documents."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ requires-python = ">=3.11"
8
+ dependencies = ["httpx>=0.27,<1", "anyio>=4"]
9
+ keywords = ["beru", "rag", "retrieval", "citations", "memory"]
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "Typing :: Typed",
13
+ ]
14
+
15
+ [project.urls]
16
+ Documentation = "https://docs.airesearchlabs.si"
17
+ Homepage = "https://airesearchlabs.si/beru"
18
+
19
+ [dependency-groups]
20
+ dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.13", "ruff>=0.8"]
21
+
22
+ [build-system]
23
+ requires = ["hatchling>=1.25"]
24
+ build-backend = "hatchling.build"
25
+
26
+ [tool.hatch.build.targets.wheel]
27
+ packages = ["src/beru"]
28
+
29
+ [tool.ruff]
30
+ line-length = 100
31
+ target-version = "py311"
32
+
33
+ [tool.ruff.lint]
34
+ select = ["E", "F", "W", "I", "B", "UP", "S", "ASYNC", "RUF", "SIM", "PL"]
35
+ ignore = ["PLR0913", "PLR2004", "S101"]
36
+
37
+ [tool.ruff.lint.per-file-ignores]
38
+ "tests/**" = ["S105", "S106"]
39
+ # One return per kind of schema reads clearer than a dispatch table.
40
+ "scripts/**" = ["PLR0911"]
41
+
42
+ [tool.mypy]
43
+ strict = true
44
+ mypy_path = "src"
45
+
46
+ [tool.pytest.ini_options]
47
+ asyncio_mode = "auto"
48
+ asyncio_default_fixture_loop_scope = "function"
49
+ testpaths = ["tests"]
@@ -0,0 +1,91 @@
1
+ """Write src/beru/types.py from the API's OpenAPI file: one TypedDict per schema.
2
+
3
+ Run from packages/sdk-python: python scripts/generate_types.py [--check]
4
+ --check exits 1 if the committed file is out of date (CI runs it).
5
+ """
6
+
7
+ import json
8
+ import keyword
9
+ import sys
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ ROOT = Path(__file__).resolve().parent.parent
14
+ OPENAPI = ROOT.parent / "openapi" / "openapi.json"
15
+ OUTPUT = ROOT / "src" / "beru" / "types.py"
16
+
17
+ HEADER = '''"""Request and response shapes of Beru's API, generated from its OpenAPI file.
18
+
19
+ Don't edit: run `python scripts/generate_types.py`.
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ from typing import Any, Literal, NotRequired, TypedDict
25
+
26
+
27
+ '''
28
+
29
+ PRIMITIVES = {"string": "str", "integer": "int", "number": "float", "boolean": "bool"}
30
+
31
+
32
+ def annotation(schema: dict[str, Any]) -> str:
33
+ if "$ref" in schema:
34
+ return str(schema["$ref"].rsplit("/", 1)[-1])
35
+ if "anyOf" in schema:
36
+ parts = [annotation(s) for s in schema["anyOf"]]
37
+ return " | ".join(dict.fromkeys(parts))
38
+ if "enum" in schema:
39
+ return "Literal[" + ", ".join(json.dumps(v) for v in schema["enum"]) + "]"
40
+ if "const" in schema:
41
+ return f"Literal[{json.dumps(schema['const'])}]"
42
+ kind = schema.get("type")
43
+ if kind == "null":
44
+ return "None"
45
+ if kind == "array":
46
+ return f"list[{annotation(schema.get('items', {}))}]"
47
+ if kind == "object":
48
+ values = schema.get("additionalProperties")
49
+ inner = annotation(values) if isinstance(values, dict) and values else "Any"
50
+ return f"dict[str, {inner}]"
51
+ if isinstance(kind, str) and kind in PRIMITIVES:
52
+ return PRIMITIVES[kind]
53
+ return "Any"
54
+
55
+
56
+ def typed_dict(name: str, schema: dict[str, Any]) -> str:
57
+ properties: dict[str, Any] = schema.get("properties", {})
58
+ required = set(schema.get("required", []))
59
+ doc = schema.get("description", "").strip().replace('"""', "'")
60
+ lines = [f"class {name}(TypedDict):"]
61
+ if doc:
62
+ lines.append(f' """{doc}"""')
63
+ lines.append("")
64
+ usable = {k: v for k, v in properties.items() if k.isidentifier() and not keyword.iskeyword(k)}
65
+ if not usable:
66
+ lines.append(" pass")
67
+ for field, spec in usable.items():
68
+ kind = annotation(spec)
69
+ lines.append(f" {field}: {kind if field in required else f'NotRequired[{kind}]'}")
70
+ return "\n".join(lines)
71
+
72
+
73
+ def render() -> str:
74
+ schemas: dict[str, Any] = json.loads(OPENAPI.read_text())["components"]["schemas"]
75
+ blocks = [typed_dict(name, schema) for name, schema in sorted(schemas.items())]
76
+ return HEADER + "\n\n\n".join(blocks) + "\n"
77
+
78
+
79
+ def main() -> int:
80
+ text = render()
81
+ if "--check" in sys.argv:
82
+ if OUTPUT.read_text() != text:
83
+ print("src/beru/types.py is out of date: run python scripts/generate_types.py")
84
+ return 1
85
+ return 0
86
+ OUTPUT.write_text(text)
87
+ return 0
88
+
89
+
90
+ if __name__ == "__main__":
91
+ sys.exit(main())
@@ -0,0 +1,13 @@
1
+ """Beru: cited answers and per-user memory from your documents.
2
+
3
+ from beru import Beru
4
+
5
+ beru = Beru() # reads BERU_API_KEY
6
+ answer = beru.answer("Is parking free?", end_user_id="user_123")
7
+ print(answer["answer"], answer["citations"])
8
+ """
9
+
10
+ from beru._client import AnswerEvent, AsyncBeru, Beru, BeruError
11
+
12
+ __all__ = ["AnswerEvent", "AsyncBeru", "Beru", "BeruError"]
13
+ __version__ = "0.1.0"