noullama 0.2.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.
noullama-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 parasite6
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,190 @@
1
+ Metadata-Version: 2.4
2
+ Name: noullama
3
+ Version: 0.2.0
4
+ Summary: Ask decision models loaded in Noullama questions from Python.
5
+ Author: parasite6
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://noullama.dev
8
+ Project-URL: Source, https://github.com/Noullama/noullama/tree/sanctuary/python
9
+ Project-URL: Issues, https://github.com/Noullama/noullama/issues
10
+ Keywords: noullama,llama.cpp,decision models,classification,local llm
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Dynamic: license-file
22
+
23
+ # Noullama Python client
24
+
25
+ Ask a model loaded in Noullama questions from your own Python code.
26
+
27
+ ## Install
28
+
29
+ Python 3.10 or newer. It has no dependencies.
30
+
31
+ ```sh
32
+ python -m pip install noullama
33
+ ```
34
+
35
+ Using `python -m pip` makes sure the package goes into the same Python that runs your script.
36
+
37
+ ## Quick start
38
+
39
+ Open Noullama and load a model first.
40
+
41
+ ```python
42
+ from noullama import Choice, Client, Noul, Score
43
+
44
+ nl = Client()
45
+
46
+ decision = nl.decide(
47
+ model="d1-2B-Q8_0",
48
+ state="I was charged twice. Please refund the duplicate payment.",
49
+ questions={
50
+ "route": Choice(
51
+ instructions="Which team should handle this?",
52
+ billing="Charges and refunds",
53
+ technical="App errors",
54
+ ),
55
+ "urgency": Score(
56
+ instructions="How urgent is this?",
57
+ levels=["Can wait", "This week", "Today", "Immediately"],
58
+ ),
59
+ "refund": Noul(instructions="Is the customer asking for a refund?"),
60
+ },
61
+ )
62
+
63
+ answer = decision["route"]
64
+ print(answer.value) # billing
65
+ print(answer.probabilities) # {'billing': 0.98, 'technical': 0.02}
66
+ print(answer.confidence) # 0.98
67
+ print(decision.nl_time) # 0.025 (seconds the whole decision took)
68
+ ```
69
+
70
+ - **`model`:** the model's name or alias as shown in the app's Local API tab. Use `any-available` for any free model.
71
+ - **`state`:** the text (or dict or list) you're asking about.
72
+ - **`questions`:** each question gets a name you choose (`"route"` above). You use that name to read its answer.
73
+ - **`decision`, `answer` and `nl`** are ordinary variable names. Call them whatever you like.
74
+
75
+ ## Questions
76
+
77
+ There are three types. Every question needs `instructions`, which can't be empty. Descriptions are optional: use `None` for no description. An empty one like `technical=""` is an error, so a forgotten description doesn't slip through.
78
+
79
+ **`Choice`: pick one option.** Each option is a name, plus an optional description that helps the model understand it. You get back the name.
80
+
81
+ ```python
82
+ Choice(instructions="Which team?", billing="Charges and refunds", technical="App errors")
83
+ Choice(instructions="Which team?", billing=None, technical=None) # no descriptions
84
+ ```
85
+
86
+ **`Score`: pick a level on a scale.** List the levels lowest first, 2 to 10 of them. You get back the level's number, counting from 0.
87
+
88
+ ```python
89
+ Score(instructions="How urgent?", levels=["Can wait", "This week", "Today", "Immediately"])
90
+ ```
91
+
92
+ **`Noul`: yes or no.** You get back the chance that the answer is yes, from 0 to 1.
93
+
94
+ ```python
95
+ Noul(instructions="Is this a refund request?")
96
+ Noul(instructions="Is this a refund request?", true="asks for money back") # optional descriptions
97
+ ```
98
+
99
+ ## Answers
100
+
101
+ Every answer has the same three fields:
102
+
103
+ | Field | Choice | Score | Noul |
104
+ | --- | --- | --- | --- |
105
+ | `.value` | the picked option, e.g. `"billing"` | the picked level, e.g. `2.0` | chance of yes, e.g. `0.93` |
106
+ | `.probabilities` | chance per option | chance per level (`"0"`, `"1"`, …) | `{"false": 0.07, "true": 0.93}` |
107
+ | `.confidence` | how sure the model is, 0 to 1 | same | same |
108
+
109
+ Native models only send the yes chance for `Noul`, so the client works out `.probabilities` and `.confidence` from it.
110
+
111
+ Native and Winnow models count `Score` and `confidence` differently. Native models give the most likely level and its chance. Winnow models give a weighted average level and an entropy-based confidence. The client shows what the model sends.
112
+
113
+ The decision as a whole has these:
114
+
115
+ - **`decision.nl_time`:** seconds from sending the request to getting the full reply. All questions share one request, so there's one time per decision.
116
+ - **`decision.model` and `decision.usage`:** the model name and token counts.
117
+ - **`decision.raw` and `answer.raw`:** the untouched reply, for anything else, such as a Score's `legend`.
118
+
119
+ ## Settings and the API key
120
+
121
+ `Client()` finds the app's address and your API key, then waits. It sends nothing until you call it. It checks these places in order and uses the first value it finds:
122
+
123
+ 1. Arguments: `Client(base_url="http://127.0.0.1:11440", api_key="da-noul-...")`
124
+ 2. Environment variables `NOULLAMA_URL` and `NOULLAMA_API_KEY`
125
+ 3. A `.env` file in the folder you run from, with the same names
126
+ 4. Defaults: `http://127.0.0.1:11435` and no key
127
+
128
+ You only need a key when **Require API key** is on in the app. Keep it out of your code with a `.env` file:
129
+
130
+ ```dotenv
131
+ NOULLAMA_API_KEY=da-noul-...
132
+ ```
133
+
134
+ The address can be pasted from the Local API tab as is, `/v1` included. The key never appears in printouts or error messages.
135
+
136
+ Make one client and reuse it, for example in a loop:
137
+
138
+ ```python
139
+ nl = Client()
140
+ for email in inbox:
141
+ decision = nl.decide(model="d1-2B-Q8_0", state=email, questions=questions)
142
+ ```
143
+
144
+ ## More
145
+
146
+ - **`nl.models()`:** the model names you can use right now.
147
+ - **`nl.health()`:** whether the app is up and a model is ready.
148
+ - **`nl.wait_until_ready(model="d1-2B-Q8_0", timeout=60)`:** waits until that model is ready. Leave out `model` to wait for any model.
149
+ - **Images:** pass `images=["receipt.png"]` to `decide()`. This only works with models that have a vision projector. Winnow models are text only.
150
+
151
+ ## Errors
152
+
153
+ Each problem has its own exception, so you can catch the ones you care about:
154
+
155
+ ```python
156
+ from noullama import Client, ModelUnavailable, NotRunning, Noul
157
+
158
+ try:
159
+ decision = Client().decide(
160
+ model="d1-2B-Q8_0",
161
+ state="Please refund my duplicate payment.",
162
+ questions={"refund": Noul(instructions="Is this a refund request?")},
163
+ )
164
+ except NotRunning:
165
+ print("Open Noullama first")
166
+ except ModelUnavailable:
167
+ print("That model isn't loaded yet")
168
+ ```
169
+
170
+ | Exception | Meaning |
171
+ | --- | --- |
172
+ | `NotRunning` | The app isn't open, or isn't at that address |
173
+ | `ModelUnavailable` | The model isn't loaded, is still loading, or every model is busy |
174
+ | `UnknownModel` | No model has that name (names are case-sensitive) |
175
+ | `AmbiguousModel` | The name matches more than one model |
176
+ | `BadRequest` | Something in the request is wrong. The message says what |
177
+ | `AuthError` | The API key is missing, wrong or expired |
178
+ | `Forbidden` | The API key isn't allowed to use this model |
179
+ | `InferenceFailed` | The model failed while answering |
180
+ | `NoullamaError` | The base class of all of the above; catches everything |
181
+
182
+ Every exception has `.message` (the app's own wording) and `.status` (the HTTP status code).
183
+
184
+ ## Tested with
185
+
186
+ Noullama 0.5.4.
187
+
188
+ ## License
189
+
190
+ The Python client is [MIT-licensed](https://github.com/Noullama/noullama/blob/sanctuary/python/LICENSE). The rest of Noullama is AGPL-3.0.
@@ -0,0 +1,168 @@
1
+ # Noullama Python client
2
+
3
+ Ask a model loaded in Noullama questions from your own Python code.
4
+
5
+ ## Install
6
+
7
+ Python 3.10 or newer. It has no dependencies.
8
+
9
+ ```sh
10
+ python -m pip install noullama
11
+ ```
12
+
13
+ Using `python -m pip` makes sure the package goes into the same Python that runs your script.
14
+
15
+ ## Quick start
16
+
17
+ Open Noullama and load a model first.
18
+
19
+ ```python
20
+ from noullama import Choice, Client, Noul, Score
21
+
22
+ nl = Client()
23
+
24
+ decision = nl.decide(
25
+ model="d1-2B-Q8_0",
26
+ state="I was charged twice. Please refund the duplicate payment.",
27
+ questions={
28
+ "route": Choice(
29
+ instructions="Which team should handle this?",
30
+ billing="Charges and refunds",
31
+ technical="App errors",
32
+ ),
33
+ "urgency": Score(
34
+ instructions="How urgent is this?",
35
+ levels=["Can wait", "This week", "Today", "Immediately"],
36
+ ),
37
+ "refund": Noul(instructions="Is the customer asking for a refund?"),
38
+ },
39
+ )
40
+
41
+ answer = decision["route"]
42
+ print(answer.value) # billing
43
+ print(answer.probabilities) # {'billing': 0.98, 'technical': 0.02}
44
+ print(answer.confidence) # 0.98
45
+ print(decision.nl_time) # 0.025 (seconds the whole decision took)
46
+ ```
47
+
48
+ - **`model`:** the model's name or alias as shown in the app's Local API tab. Use `any-available` for any free model.
49
+ - **`state`:** the text (or dict or list) you're asking about.
50
+ - **`questions`:** each question gets a name you choose (`"route"` above). You use that name to read its answer.
51
+ - **`decision`, `answer` and `nl`** are ordinary variable names. Call them whatever you like.
52
+
53
+ ## Questions
54
+
55
+ There are three types. Every question needs `instructions`, which can't be empty. Descriptions are optional: use `None` for no description. An empty one like `technical=""` is an error, so a forgotten description doesn't slip through.
56
+
57
+ **`Choice`: pick one option.** Each option is a name, plus an optional description that helps the model understand it. You get back the name.
58
+
59
+ ```python
60
+ Choice(instructions="Which team?", billing="Charges and refunds", technical="App errors")
61
+ Choice(instructions="Which team?", billing=None, technical=None) # no descriptions
62
+ ```
63
+
64
+ **`Score`: pick a level on a scale.** List the levels lowest first, 2 to 10 of them. You get back the level's number, counting from 0.
65
+
66
+ ```python
67
+ Score(instructions="How urgent?", levels=["Can wait", "This week", "Today", "Immediately"])
68
+ ```
69
+
70
+ **`Noul`: yes or no.** You get back the chance that the answer is yes, from 0 to 1.
71
+
72
+ ```python
73
+ Noul(instructions="Is this a refund request?")
74
+ Noul(instructions="Is this a refund request?", true="asks for money back") # optional descriptions
75
+ ```
76
+
77
+ ## Answers
78
+
79
+ Every answer has the same three fields:
80
+
81
+ | Field | Choice | Score | Noul |
82
+ | --- | --- | --- | --- |
83
+ | `.value` | the picked option, e.g. `"billing"` | the picked level, e.g. `2.0` | chance of yes, e.g. `0.93` |
84
+ | `.probabilities` | chance per option | chance per level (`"0"`, `"1"`, …) | `{"false": 0.07, "true": 0.93}` |
85
+ | `.confidence` | how sure the model is, 0 to 1 | same | same |
86
+
87
+ Native models only send the yes chance for `Noul`, so the client works out `.probabilities` and `.confidence` from it.
88
+
89
+ Native and Winnow models count `Score` and `confidence` differently. Native models give the most likely level and its chance. Winnow models give a weighted average level and an entropy-based confidence. The client shows what the model sends.
90
+
91
+ The decision as a whole has these:
92
+
93
+ - **`decision.nl_time`:** seconds from sending the request to getting the full reply. All questions share one request, so there's one time per decision.
94
+ - **`decision.model` and `decision.usage`:** the model name and token counts.
95
+ - **`decision.raw` and `answer.raw`:** the untouched reply, for anything else, such as a Score's `legend`.
96
+
97
+ ## Settings and the API key
98
+
99
+ `Client()` finds the app's address and your API key, then waits. It sends nothing until you call it. It checks these places in order and uses the first value it finds:
100
+
101
+ 1. Arguments: `Client(base_url="http://127.0.0.1:11440", api_key="da-noul-...")`
102
+ 2. Environment variables `NOULLAMA_URL` and `NOULLAMA_API_KEY`
103
+ 3. A `.env` file in the folder you run from, with the same names
104
+ 4. Defaults: `http://127.0.0.1:11435` and no key
105
+
106
+ You only need a key when **Require API key** is on in the app. Keep it out of your code with a `.env` file:
107
+
108
+ ```dotenv
109
+ NOULLAMA_API_KEY=da-noul-...
110
+ ```
111
+
112
+ The address can be pasted from the Local API tab as is, `/v1` included. The key never appears in printouts or error messages.
113
+
114
+ Make one client and reuse it, for example in a loop:
115
+
116
+ ```python
117
+ nl = Client()
118
+ for email in inbox:
119
+ decision = nl.decide(model="d1-2B-Q8_0", state=email, questions=questions)
120
+ ```
121
+
122
+ ## More
123
+
124
+ - **`nl.models()`:** the model names you can use right now.
125
+ - **`nl.health()`:** whether the app is up and a model is ready.
126
+ - **`nl.wait_until_ready(model="d1-2B-Q8_0", timeout=60)`:** waits until that model is ready. Leave out `model` to wait for any model.
127
+ - **Images:** pass `images=["receipt.png"]` to `decide()`. This only works with models that have a vision projector. Winnow models are text only.
128
+
129
+ ## Errors
130
+
131
+ Each problem has its own exception, so you can catch the ones you care about:
132
+
133
+ ```python
134
+ from noullama import Client, ModelUnavailable, NotRunning, Noul
135
+
136
+ try:
137
+ decision = Client().decide(
138
+ model="d1-2B-Q8_0",
139
+ state="Please refund my duplicate payment.",
140
+ questions={"refund": Noul(instructions="Is this a refund request?")},
141
+ )
142
+ except NotRunning:
143
+ print("Open Noullama first")
144
+ except ModelUnavailable:
145
+ print("That model isn't loaded yet")
146
+ ```
147
+
148
+ | Exception | Meaning |
149
+ | --- | --- |
150
+ | `NotRunning` | The app isn't open, or isn't at that address |
151
+ | `ModelUnavailable` | The model isn't loaded, is still loading, or every model is busy |
152
+ | `UnknownModel` | No model has that name (names are case-sensitive) |
153
+ | `AmbiguousModel` | The name matches more than one model |
154
+ | `BadRequest` | Something in the request is wrong. The message says what |
155
+ | `AuthError` | The API key is missing, wrong or expired |
156
+ | `Forbidden` | The API key isn't allowed to use this model |
157
+ | `InferenceFailed` | The model failed while answering |
158
+ | `NoullamaError` | The base class of all of the above; catches everything |
159
+
160
+ Every exception has `.message` (the app's own wording) and `.status` (the HTTP status code).
161
+
162
+ ## Tested with
163
+
164
+ Noullama 0.5.4.
165
+
166
+ ## License
167
+
168
+ The Python client is [MIT-licensed](https://github.com/Noullama/noullama/blob/sanctuary/python/LICENSE). The rest of Noullama is AGPL-3.0.
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "noullama"
7
+ dynamic = ["version"]
8
+ description = "Ask decision models loaded in Noullama questions from Python."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ dependencies = []
12
+ license = "MIT"
13
+ license-files = ["LICENSE"]
14
+ authors = [{ name = "parasite6" }]
15
+ keywords = ["noullama", "llama.cpp", "decision models", "classification", "local llm"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Intended Audience :: Developers",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
23
+ "Typing :: Typed",
24
+ ]
25
+
26
+ [project.urls]
27
+ Homepage = "https://noullama.dev"
28
+ Source = "https://github.com/Noullama/noullama/tree/sanctuary/python"
29
+ Issues = "https://github.com/Noullama/noullama/issues"
30
+
31
+ [tool.setuptools.dynamic]
32
+ version = { attr = "noullama.__version__" }
33
+
34
+ [tool.setuptools.packages.find]
35
+ where = ["src"]
36
+
37
+ [tool.setuptools.package-data]
38
+ noullama = ["py.typed"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,35 @@
1
+ __version__ = "0.2.0"
2
+
3
+ from .answers import Answer, Decision
4
+ from .client import Client
5
+ from .errors import (
6
+ BadRequest,
7
+ AuthError,
8
+ Forbidden,
9
+ UnknownModel,
10
+ AmbiguousModel,
11
+ InferenceFailed,
12
+ ModelUnavailable,
13
+ NotRunning,
14
+ NoullamaError,
15
+ )
16
+ from .questions import Choice, Noul, Score
17
+
18
+ __all__ = [
19
+ "__version__",
20
+ "Answer",
21
+ "Choice",
22
+ "Client",
23
+ "Decision",
24
+ "Noul",
25
+ "Score",
26
+ "BadRequest",
27
+ "AuthError",
28
+ "Forbidden",
29
+ "UnknownModel",
30
+ "AmbiguousModel",
31
+ "InferenceFailed",
32
+ "ModelUnavailable",
33
+ "NotRunning",
34
+ "NoullamaError",
35
+ ]
@@ -0,0 +1,52 @@
1
+ from collections.abc import Iterator
2
+ from dataclasses import dataclass
3
+ from typing import Any
4
+
5
+
6
+ @dataclass
7
+ class Answer:
8
+ type: str
9
+ value: Any
10
+ probabilities: dict[str, float] | None
11
+ confidence: float | None
12
+ raw: dict
13
+
14
+ @classmethod
15
+ def from_raw(cls, raw: dict) -> "Answer":
16
+ kind = raw["type"]
17
+ value = raw.get(kind)
18
+ probabilities = raw.get("probabilities")
19
+ confidence = raw.get("confidence")
20
+ if kind == "noul":
21
+ if "probabilities" not in raw:
22
+ probabilities = {"false": 1 - value, "true": value}
23
+ if "confidence" not in raw:
24
+ confidence = max(value, 1 - value)
25
+ return cls(kind, value, probabilities, confidence, raw)
26
+
27
+
28
+ @dataclass
29
+ class Decision:
30
+ answers: dict[str, Answer]
31
+ model: str | None
32
+ usage: dict | None
33
+ raw: dict
34
+ nl_time: float | None = None
35
+ """Seconds from sending the request to reading the full response."""
36
+
37
+ @classmethod
38
+ def from_raw(cls, raw: dict, *, nl_time: float | None = None) -> "Decision":
39
+ answers = {name: Answer.from_raw(answer) for name, answer in raw["answers"].items()}
40
+ return cls(answers, raw.get("model"), raw.get("usage"), raw, nl_time)
41
+
42
+ def __getitem__(self, name: str) -> Answer:
43
+ return self.answers[name]
44
+
45
+ def __contains__(self, name: str) -> bool:
46
+ return name in self.answers
47
+
48
+ def __iter__(self) -> Iterator[str]:
49
+ return iter(self.answers)
50
+
51
+ def __len__(self) -> int:
52
+ return len(self.answers)