pynatlas 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.
Files changed (41) hide show
  1. pynatlas-0.1.0/.gitignore +13 -0
  2. pynatlas-0.1.0/CHANGELOG.md +48 -0
  3. pynatlas-0.1.0/LICENSE +202 -0
  4. pynatlas-0.1.0/NOTICE +23 -0
  5. pynatlas-0.1.0/PKG-INFO +337 -0
  6. pynatlas-0.1.0/README.md +294 -0
  7. pynatlas-0.1.0/pyproject.toml +118 -0
  8. pynatlas-0.1.0/src/pynatlas/__init__.py +53 -0
  9. pynatlas-0.1.0/src/pynatlas/_extras.py +19 -0
  10. pynatlas-0.1.0/src/pynatlas/_toolcalls.py +90 -0
  11. pynatlas-0.1.0/src/pynatlas/asr.py +129 -0
  12. pynatlas-0.1.0/src/pynatlas/bench/__init__.py +5 -0
  13. pynatlas-0.1.0/src/pynatlas/bench/data.py +210 -0
  14. pynatlas-0.1.0/src/pynatlas/bench/runner.py +180 -0
  15. pynatlas-0.1.0/src/pynatlas/bench/scoring.py +104 -0
  16. pynatlas-0.1.0/src/pynatlas/bench/tool_cases.json +62 -0
  17. pynatlas-0.1.0/src/pynatlas/cli.py +165 -0
  18. pynatlas-0.1.0/src/pynatlas/client.py +715 -0
  19. pynatlas-0.1.0/src/pynatlas/defaults.py +19 -0
  20. pynatlas-0.1.0/src/pynatlas/engine.py +158 -0
  21. pynatlas-0.1.0/src/pynatlas/errors.py +81 -0
  22. pynatlas-0.1.0/src/pynatlas/language_profile.json +1 -0
  23. pynatlas-0.1.0/src/pynatlas/languages.py +69 -0
  24. pynatlas-0.1.0/src/pynatlas/models.py +103 -0
  25. pynatlas-0.1.0/src/pynatlas/py.typed +0 -0
  26. pynatlas-0.1.0/src/pynatlas/server.py +381 -0
  27. pynatlas-0.1.0/src/pynatlas/settings.py +107 -0
  28. pynatlas-0.1.0/src/pynatlas/tools.py +102 -0
  29. pynatlas-0.1.0/src/pynatlas/types.py +85 -0
  30. pynatlas-0.1.0/tests/test_asr_audio.py +38 -0
  31. pynatlas-0.1.0/tests/test_bench.py +110 -0
  32. pynatlas-0.1.0/tests/test_client.py +209 -0
  33. pynatlas-0.1.0/tests/test_helpers.py +119 -0
  34. pynatlas-0.1.0/tests/test_live.py +230 -0
  35. pynatlas-0.1.0/tests/test_models.py +108 -0
  36. pynatlas-0.1.0/tests/test_packaging.py +22 -0
  37. pynatlas-0.1.0/tests/test_playground.py +90 -0
  38. pynatlas-0.1.0/tests/test_server.py +302 -0
  39. pynatlas-0.1.0/tests/test_server_disconnect.py +63 -0
  40. pynatlas-0.1.0/tests/test_settings.py +74 -0
  41. pynatlas-0.1.0/tests/test_tools.py +226 -0
@@ -0,0 +1,13 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ .uv-cache/
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+ .models/
11
+ *.gguf
12
+ .env
13
+ .DS_Store
@@ -0,0 +1,48 @@
1
+ # Changelog
2
+
3
+ All notable changes to pynatlas are recorded here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow
5
+ [Semantic Versioning](https://semver.org/). Until 1.0, minor versions may
6
+ include breaking changes, each called out under its release.
7
+
8
+ ## [0.1.0] - 2026-10-12
9
+
10
+ First release.
11
+
12
+ ### Client
13
+
14
+ - `NAtlas` and `AsyncNAtlas` for any OpenAI-compatible endpoint serving
15
+ N-ATLaS, sending standard OpenAI fields only. Provider-specific options pass
16
+ through as keyword arguments.
17
+ - Chat, streaming, translation and speech to text.
18
+ - Tool calling from plain Python functions, with `run_tools()` to run the
19
+ call-and-answer loop.
20
+ - Structured output from a Pydantic model or JSON schema, with recovery of
21
+ JSON from code fences and one corrective retry where the endpoint does not
22
+ enforce schemas.
23
+ - `summarize()`, `classify()` (enforced label set) and `voice_chat()`.
24
+ - `detect_language()`, offline, above 99% accurate on held-out text.
25
+ - Retries with backoff for connection errors, 408, 409, 429 and 5xx, and typed
26
+ exceptions under `NAtlasError`.
27
+ - Settings validated once from `NATLAS_*` environment variables.
28
+
29
+ ### Server
30
+
31
+ - `pynatlas serve`: N-ATLaS GGUF weights behind the OpenAI API through
32
+ llama.cpp, with tool calling, schema-enforced JSON output and speech
33
+ recognition through the official NCAIR1 models.
34
+ - API keys, OpenAI error bodies, and recovery when a client disconnects
35
+ mid-stream.
36
+ - Replies independent of earlier requests, and `--date` to make benchmark runs
37
+ reproducible.
38
+ - `Engine` and `Transcriber` protocols for other backends.
39
+ - A container image and documented GPU routes.
40
+
41
+ ### Tooling
42
+
43
+ - `pynatlas download`: pinned, SHA-256 verified, resumable weight downloads.
44
+ - `pynatlas bench`: AfriMMLU, AfriXNLI, AfriMGSM, MAFAND, FLEURS and a held-out
45
+ tool-calling set, with every reply saved for audit.
46
+ - A Streamlit playground and runnable examples.
47
+
48
+ [0.1.0]: https://github.com/open-lab-technologies/natlas-sdk/releases/tag/v0.1.0
pynatlas-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
pynatlas-0.1.0/NOTICE ADDED
@@ -0,0 +1,23 @@
1
+ pynatlas
2
+ Copyright 2026 Open Lab Technologies. Licensed under the Apache License, Version 2.0
3
+ (see LICENSE).
4
+
5
+ This package's code is Apache-2.0. The N-ATLaS language model and the NCAIR1
6
+ speech models it downloads and serves are not: they are released by Awarri
7
+ Technologies and the Federal Ministry of Communications, Innovation and Digital
8
+ Economy under the N-ATLaS Open-Source Research and Innovation License, published
9
+ on https://huggingface.co/NCAIR1/N-ATLaS. Anyone deploying them through this
10
+ package must follow those terms, which include:
11
+
12
+ - Attribution in all public use:
13
+ "N-ATLaS is an initiative of the Federal Ministry of Communications, Innovation
14
+ and Digital Economy, and powered by Awarri Technologies."
15
+ - A cap of 1,000 active end-users in any rolling 30-day period. Above that, a
16
+ commercial licence from Awarri Technologies is required.
17
+ - Derivative works released under the same terms, and renamed models carrying
18
+ the suffix "Powered by Awarri".
19
+ - No surveillance, discriminatory profiling, disinformation, impersonation,
20
+ fraud, or military use.
21
+
22
+ The quantised GGUF weights fetched by `pynatlas download` are a community
23
+ conversion by QuantFactory of NCAIR1/N-ATLaS and carry the same terms.
@@ -0,0 +1,337 @@
1
+ Metadata-Version: 2.5
2
+ Name: pynatlas
3
+ Version: 0.1.0
4
+ Summary: Python SDK, OpenAI-compatible server and benchmark kit for N-ATLaS, Nigeria's open multilingual LLM
5
+ Project-URL: Repository, https://github.com/open-lab-technologies/natlas-sdk
6
+ Project-URL: Issues, https://github.com/open-lab-technologies/natlas-sdk/issues
7
+ Project-URL: Changelog, https://github.com/open-lab-technologies/natlas-sdk/blob/main/CHANGELOG.md
8
+ Author: Nazeh Abel
9
+ Maintainer: Open Lab Technologies
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Keywords: hausa,igbo,llm,n-atlas,nigeria,speech-recognition,yoruba
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Natural Language :: English
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: httpx>=0.27
27
+ Provides-Extra: asr
28
+ Requires-Dist: numpy>=1.24; extra == 'asr'
29
+ Requires-Dist: soundfile>=0.12; extra == 'asr'
30
+ Requires-Dist: soxr>=0.3; extra == 'asr'
31
+ Requires-Dist: torch>=2.4; extra == 'asr'
32
+ Requires-Dist: transformers>=4.44; extra == 'asr'
33
+ Provides-Extra: bench
34
+ Requires-Dist: jiwer>=3.0; extra == 'bench'
35
+ Requires-Dist: sacrebleu>=2.4; extra == 'bench'
36
+ Provides-Extra: server
37
+ Requires-Dist: fastapi>=0.115; extra == 'server'
38
+ Requires-Dist: jinja2>=3.1; extra == 'server'
39
+ Requires-Dist: llama-cpp-python>=0.3.8; extra == 'server'
40
+ Requires-Dist: python-multipart>=0.0.9; extra == 'server'
41
+ Requires-Dist: uvicorn>=0.30; extra == 'server'
42
+ Description-Content-Type: text/markdown
43
+
44
+ # pynatlas
45
+
46
+ Python SDK for [N-ATLaS](https://huggingface.co/NCAIR1/N-ATLaS), Nigeria's open
47
+ language model for English, Hausa, Igbo and Yoruba, and its speech recognition
48
+ models. It works with any OpenAI-compatible endpoint serving N-ATLaS, can run
49
+ one locally, and publishes measured results for every language it supports.
50
+
51
+ ## Install
52
+
53
+ ```bash
54
+ pip install pynatlas
55
+ ```
56
+
57
+ | Install | Adds | Size |
58
+ | ------------------ | --------------------------------------------------------------- | ------ |
59
+ | `pynatlas` | Sync and async clients | 2.5 MB |
60
+ | `pynatlas[server]` | `pynatlas serve`: N-ATLaS on your machine behind the OpenAI API | 109 MB |
61
+ | `pynatlas[asr]` | Speech recognition for `pynatlas serve --asr` | 690 MB |
62
+ | `pynatlas[bench]` | `pynatlas bench`: benchmarks for any endpoint | 51 MB |
63
+
64
+ Python 3.10 or newer. `import pynatlas` loads only httpx. Release notes are in
65
+ the [changelog](https://github.com/open-lab-technologies/natlas-sdk/blob/main/CHANGELOG.md).
66
+
67
+ ## Quick start
68
+
69
+ ```python
70
+ from pynatlas import NAtlas
71
+
72
+ client = NAtlas(base_url="http://localhost:8000/v1")
73
+
74
+ client.chat("Kí ni olú ìlú Nàìjíríà?").text # 'Olú ìlú Nàìjíríà ni Abuja.'
75
+ client.translate("Wash your hands before eating.", to="ig")
76
+ client.transcribe("voice-note.ogg", language="ha") # needs a server with speech
77
+
78
+ for piece in client.stream("Ka bayyana mini menene noma a takaice"):
79
+ print(piece, end="")
80
+ ```
81
+
82
+ To run N-ATLaS locally:
83
+
84
+ ```bash
85
+ pip install "pynatlas[server]"
86
+ pynatlas download # 4.9 GB, 4-bit weights
87
+ pynatlas serve # http://127.0.0.1:8000/v1
88
+ ```
89
+
90
+ To run the model on the GPU, install the server extra with
91
+ `CMAKE_ARGS="-DGGML_METAL=on"` on Apple Silicon or `CMAKE_ARGS="-DGGML_CUDA=on"`
92
+ on NVIDIA.
93
+
94
+ ## Client
95
+
96
+ ### Providers
97
+
98
+ | Provider | `base_url` | `model` |
99
+ | ------------------------------ | --------------------------- | ------------------- |
100
+ | `pynatlas serve` | `http://localhost:8000/v1` | `n-atlas` (default) |
101
+ | vLLM with the official weights | `http://host:8000/v1` | `NCAIR1/N-ATLaS` |
102
+ | llama.cpp server | `http://host:8080/v1` | its `--model_alias` |
103
+ | Ollama | `http://localhost:11434/v1` | your model tag |
104
+
105
+ Requests carry standard OpenAI fields only. Provider-specific options pass
106
+ through as keyword arguments, such as `repetition_penalty=1.12` on vLLM. Tested
107
+ end to end against `pynatlas serve` and llama.cpp's server.
108
+
109
+ ### Helpers
110
+
111
+ ```python
112
+ from pynatlas import detect_language
113
+
114
+ detect_language("Bawo ni o se wa?") # 'yo', offline, no model call
115
+ client.summarize(article) # in the article's own language
116
+ client.classify(message, ["complaint", "praise", "question"])
117
+ client.voice_chat("voice-note.ogg", language="ha") # transcript and reply
118
+ ```
119
+
120
+ `detect_language` needs no model and is over 99% accurate on held-out text.
121
+ `classify` enforces the label set, so the answer is always one of your labels.
122
+
123
+ ### Tool calling
124
+
125
+ Pass plain functions; type hints and the docstring become the tool definition.
126
+
127
+ ```python
128
+ def get_market_price(commodity: str, market: str) -> dict:
129
+ """Today's price of a food commodity at a named market."""
130
+ return {"naira_per_kg": 1450}
131
+
132
+ reply = client.run_tools("Nawa ne farashin shinkafa a kasuwar Kano?", [get_market_price])
133
+ reply.text # answer written from the tool's result
134
+ ```
135
+
136
+ `run_tools` loops until the model answers in text; a tool's exception goes back
137
+ to the model instead of being raised. For step-by-step control, pass
138
+ `tools=[...]` to `chat()` and read `reply.tool_calls`. `tool_choice` takes
139
+ `"auto"`, `"none"`, `"required"` or a function name.
140
+
141
+ ### Structured output
142
+
143
+ ```python
144
+ from typing import Literal
145
+ from pydantic import BaseModel
146
+
147
+ class Feedback(BaseModel):
148
+ language: Literal["en", "ha", "ig", "yo"]
149
+ sentiment: Literal["positive", "neutral", "negative"]
150
+
151
+ client.chat("Classify: Kayan sun iso a makare.", response_format=Feedback).parsed
152
+ ```
153
+
154
+ `response_format` also takes a JSON schema dict. `pynatlas serve`, vLLM and
155
+ llama.cpp enforce the schema while generating, so the reply is always valid.
156
+ Elsewhere the client reads JSON out of code fences, and if the reply still does
157
+ not match, it shows the model the error and asks again (`format_retries`)
158
+ before raising `StructuredOutputError`. Pydantic is needed only if you pass a
159
+ Pydantic model.
160
+
161
+ ### Async
162
+
163
+ `AsyncNAtlas` has the same methods as coroutines, and `run_tools` accepts
164
+ async functions.
165
+
166
+ ```python
167
+ async with AsyncNAtlas() as client:
168
+ reply = await client.chat("Sannu!")
169
+ ```
170
+
171
+ ### Errors and retries
172
+
173
+ Connection failures and 408, 409, 429 and 5xx responses are retried with
174
+ backoff, honouring `Retry-After`. A retried chat request can run the model
175
+ twice; pass `max_retries=0` where that matters. Everything raised derives from
176
+ `NAtlasError`:
177
+
178
+ | Exception | When |
179
+ | --------------------------------------- | ------------------------------------------------------------- |
180
+ | `APIConnectionError`, `APITimeoutError` | Endpoint unreachable or too slow |
181
+ | `BadRequestError` | 400 or 422, including a prompt longer than the context window |
182
+ | `AuthenticationError` | 401 or 403 |
183
+ | `NotFoundError` | 404, or the endpoint lacks the feature |
184
+ | `RateLimitError`, `InternalServerError` | 429 or 5xx after retries |
185
+ | `StructuredOutputError` | Reply does not match `response_format` |
186
+ | `ToolLoopError` | `run_tools` hit `max_rounds` |
187
+ | `ConfigError` | A setting is malformed |
188
+
189
+ ### Configuration
190
+
191
+ | Variable | Default |
192
+ | -------------------- | -------------------------------------------- |
193
+ | `NATLAS_BASE_URL` | `http://localhost:8000/v1` |
194
+ | `NATLAS_API_KEY` | none |
195
+ | `NATLAS_MODEL` | `n-atlas` |
196
+ | `NATLAS_TIMEOUT` | `120` seconds |
197
+ | `NATLAS_MAX_RETRIES` | `2` |
198
+ | `NATLAS_MODEL_PATH` | the downloaded weights, for `pynatlas serve` |
199
+ | `NATLAS_CACHE` | `~/.cache/pynatlas` |
200
+
201
+ Client arguments override these. A malformed value raises `ConfigError` naming
202
+ the variable, and `pynatlas config` shows what is in effect.
203
+
204
+ ## Server
205
+
206
+ `pynatlas serve` puts a GGUF build behind the OpenAI API, so the official
207
+ `openai` package works unchanged, including tool calls, streaming and
208
+ `chat.completions.parse()`.
209
+
210
+ ```bash
211
+ pynatlas serve --asr # speech to text too
212
+ pynatlas serve --host 0.0.0.0 --api-key "$(openssl rand -hex 16)" # to share it
213
+ ```
214
+
215
+ It handles one request at a time; for concurrent users, serve the official
216
+ weights with vLLM (see Deployment). Other backends plug in through the `Engine`
217
+ protocol in `pynatlas.engine`, and speech backends through
218
+ `pynatlas.asr.Transcriber`.
219
+
220
+ The NCAIR1 speech models are gated: accept the terms on each model page on
221
+ Hugging Face, then run `hf auth login`. m4a and webm audio need ffmpeg.
222
+
223
+ ## Deployment
224
+
225
+ ### Docker
226
+
227
+ ```bash
228
+ docker build -t pynatlas .
229
+ docker run -p 8000:8000 -v pynatlas-data:/data -e NATLAS_API_KEY=change-me pynatlas
230
+ ```
231
+
232
+ Weights download to the `/data` volume on first start. For speech, build with
233
+ `--build-arg EXTRAS=server,asr`, pass `HF_TOKEN` and add `--asr` to the run.
234
+
235
+ ### On a GPU
236
+
237
+ Point `base_url` at the GPU host; the client does not change.
238
+
239
+ - vLLM, for many users: `vllm serve NCAIR1/N-ATLaS` with
240
+ `model="NCAIR1/N-ATLaS"`. Tool-call safeguards are `pynatlas serve` features,
241
+ so run `pynatlas bench --tasks tool-calling` against vLLM before relying on
242
+ tool calls.
243
+ - `pynatlas serve`, for demos: install with `CMAKE_ARGS="-DGGML_CUDA=on"`.
244
+
245
+ ## Command line
246
+
247
+ | Command | Does |
248
+ | ------------------------------------------------------ | ----------------------------------------- |
249
+ | `pynatlas download [--quant Q4_K_M]` | Fetch weights, resumable and hash-checked |
250
+ | `pynatlas serve [--asr] [--api-key KEY] [--date DATE]` | Run the local server |
251
+ | `pynatlas chat ["prompt"]` | Chat, or answer one prompt |
252
+ | `pynatlas translate "text" --to yo` | Translate between en, ha, ig and yo |
253
+ | `pynatlas transcribe file --language ha` | Speech to text |
254
+ | `pynatlas bench [--tasks ...] [-n 100]` | Run benchmarks |
255
+ | `pynatlas config` | Show settings in effect |
256
+
257
+ `--base-url` and `--model` point every command except `serve` and `download` at
258
+ any endpoint.
259
+
260
+ ## Benchmarks
261
+
262
+ `pynatlas bench` scores any endpoint and saves every reply next to its expected
263
+ answer. Results for the 4-bit model on Apple Silicon, temperature 0:
264
+
265
+ | | English | Hausa | Igbo | Yoruba |
266
+ | ---------------------------------------- | ------: | ----: | ---: | -----: |
267
+ | AfriMMLU knowledge, % (chance 25) | 53 | 35 | 41 | 37 |
268
+ | AfriXNLI reasoning, % (chance 33) | 69 | 58 | 57 | 53 |
269
+ | AfriMGSM maths, % | 69 | 43 | 36 | 40 |
270
+ | MAFAND translation from English, chrF++ | | 33.7 | 41.0 | 28.0 |
271
+ | MAFAND translation into English, chrF++ | | 37.4 | 40.7 | 41.7 |
272
+ | FLEURS speech, WER % (lower is better) | 9.0 | 31.3 | 43.8 | 55.7 |
273
+ | FLEURS speech ignoring tone marks, WER % | 9.0 | 31.3 | 37.3 | 28.8 |
274
+ | Tool calling, held-out set, % correct | 100 | 90 | 80 | 80 |
275
+ | Language detection, held-out text, % | 99.8 | 99.9 | 99.6 | 99.6 |
276
+
277
+ - 100 items per language for text tasks (about ±10 points), 50 clips for
278
+ speech, 10 questions for tool calling.
279
+ - Many FLEURS Yoruba references omit tone marks the model writes, which inflates
280
+ the strict Yoruba WER.
281
+ - Tool calling uses questions and tools kept out of its design. Plain prompting
282
+ scores 21 of 40 and calls a tool for every question that needs none; this SDK
283
+ scores 35 of 40. Non-English questions are not reviewed by native speakers.
284
+ - Language detection is trained on AfriXNLI dev and scored on its test split.
285
+ - Some test items may have been in N-ATLaS's training data.
286
+ - Runs used `pynatlas serve --date "10 Oct 2026"`; the template dates every
287
+ prompt, so only the same date reproduces them exactly.
288
+
289
+ Datasets: [IrokoBench](https://huggingface.co/collections/masakhane/irokobench)
290
+ (Apache-2.0), [MAFAND-MT](https://github.com/masakhane-io/lafand-mt) (GPL-3.0)
291
+ and [FLEURS](https://huggingface.co/datasets/google/fleurs) (CC-BY-4.0), all
292
+ downloaded at run time. Full replies are in
293
+ [bench-results](https://github.com/open-lab-technologies/natlas-sdk/tree/main/bench-results/).
294
+
295
+ ## Known limitations
296
+
297
+ - Yoruba output is the weakest: free-form answers are often incoherent and drop
298
+ tone marks, and Yoruba words inside tool arguments can come out garbled.
299
+ - Structured output guarantees the JSON's shape, not its content. Field values
300
+ can be wrong, such as a Hausa message labelled English.
301
+ - The model makes at most one tool call per turn.
302
+ - `detect_language` knows only English, Hausa, Igbo and Yoruba; text in any
303
+ other language is still labelled as one of them.
304
+ - Q2_K and Q3_K_M weights lose real quality; use Q4_K_M or larger.
305
+ - The GGUF weights are a community conversion (QuantFactory), pinned and
306
+ hash-checked, not published by NCAIR.
307
+
308
+ ## Development
309
+
310
+ ```bash
311
+ uv venv && uv pip install -e ".[server,asr,bench]" --group dev
312
+ pytest # unit tests, no model needed
313
+ ruff check src tests playground examples
314
+ mypy # strict type check
315
+ ```
316
+
317
+ End-to-end tests run against a live server:
318
+
319
+ ```bash
320
+ pynatlas serve --asr --api-key test-key
321
+ NATLAS_E2E_URL=http://127.0.0.1:8000/v1 NATLAS_E2E_API_KEY=test-key pytest tests/test_live.py
322
+ ```
323
+
324
+ `examples/` has runnable scripts, and `streamlit run playground/app.py` (after
325
+ `uv pip install --group playground`) opens a browser playground.
326
+
327
+ ## Licence
328
+
329
+ The code is Apache-2.0, maintained by Open Lab Technologies. The N-ATLaS and
330
+ speech models it runs are under the N-ATLaS Open-Source Research and Innovation
331
+ License, which requires attribution in all public use and caps deployments at
332
+ 1,000 active end-users a month without a commercial licence. Read the
333
+ [NOTICE](https://github.com/open-lab-technologies/natlas-sdk/blob/main/NOTICE) before
334
+ deploying.
335
+
336
+ N-ATLaS is an initiative of the Federal Ministry of Communications, Innovation
337
+ and Digital Economy, and powered by Awarri Technologies.