trismik 0.9.11__py3-none-any.whl → 1.0.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.
@@ -0,0 +1,27 @@
1
+ """Sync helper functions for Trismik client."""
2
+
3
+ import asyncio
4
+ from typing import Any, Callable
5
+
6
+ from trismik.types import TrismikItem
7
+
8
+
9
+ def process_item(item_processor: Callable[[TrismikItem], Any], item: TrismikItem) -> Any:
10
+ """
11
+ Process a test item with sync processor only.
12
+
13
+ Args:
14
+ item_processor: Function to process the item (must be sync)
15
+ item: The test item to process
16
+
17
+ Returns:
18
+ The processor's response
19
+
20
+ Raises:
21
+ TypeError: If processor is async
22
+ """
23
+ if asyncio.iscoroutinefunction(item_processor):
24
+ raise TypeError(
25
+ "Sync client cannot use async item_processor. Use TrismikAsyncClient instead."
26
+ )
27
+ return item_processor(item)
trismik/_utils.py CHANGED
@@ -33,9 +33,7 @@ class TrismikUtils:
33
33
  return title + ": " + message
34
34
  return title
35
35
  except (httpx.RequestError, ValueError):
36
- error_message: str = response.content.decode(
37
- "utf-8", errors="ignore"
38
- )
36
+ error_message: str = response.content.decode("utf-8", errors="ignore")
39
37
  return error_message
40
38
 
41
39
  @staticmethod
trismik/settings.py CHANGED
@@ -4,7 +4,7 @@ evaluation_settings = {
4
4
  "max_iterations": 150,
5
5
  }
6
6
 
7
- client_settings = {"endpoint": "https://dashboard.trismik.com/api"}
7
+ client_settings = {"endpoint": "https://api.trismik.com/adaptive-testing"}
8
8
 
9
9
  # Environment variable names used by the Trismik client
10
10
  environment_settings = {
trismik/types.py CHANGED
@@ -317,6 +317,6 @@ class TrismikProject:
317
317
  id: str
318
318
  name: str
319
319
  description: Optional[str]
320
- organizationId: str
320
+ accountId: str
321
321
  createdAt: str
322
322
  updatedAt: str
@@ -0,0 +1,258 @@
1
+ Metadata-Version: 2.4
2
+ Name: trismik
3
+ Version: 1.0.0
4
+ Summary:
5
+ License-File: LICENSE
6
+ Author: Bartosz Kielczewski
7
+ Author-email: bk352@cam.ac.uk
8
+ Requires-Python: >=3.9, <3.14
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Provides-Extra: examples
16
+ Requires-Dist: accelerate (>=1.7.0,<2.0.0) ; extra == "examples"
17
+ Requires-Dist: httpx (>=0.27.2,<1.0.0)
18
+ Requires-Dist: jupyterlab (>=4.4.8) ; extra == "examples"
19
+ Requires-Dist: nest-asyncio (>=1.6.0,<2.0.0)
20
+ Requires-Dist: notebook (>=7.4.4,<8.0.0) ; extra == "examples"
21
+ Requires-Dist: openai (>=1.81.0,<2.0.0) ; extra == "examples"
22
+ Requires-Dist: torch (>=2.8.0,<3.0.0) ; extra == "examples"
23
+ Requires-Dist: torchaudio (>=2.7.0,<3.0.0) ; extra == "examples"
24
+ Requires-Dist: torchvision (>=0.22.0,<1.0.0) ; extra == "examples"
25
+ Requires-Dist: tqdm (>=4.67.1,<5.0.0) ; extra == "examples"
26
+ Requires-Dist: transformers (>=4.51.3,<5.0.0) ; extra == "examples"
27
+ Description-Content-Type: text/markdown
28
+
29
+ <h1 align="center"> Trismik SDK</h1>
30
+
31
+ <p align="center">
32
+ <img alt="PyPI - Version" src="https://img.shields.io/pypi/v/trismik">
33
+ <img alt="Python Version" src="https://img.shields.io/badge/python-3.9%2B-blue">
34
+ <img alt="License" src="https://img.shields.io/badge/license-MIT-green">
35
+ </p>
36
+
37
+ ## Table of Contents
38
+ - [Overview](#overview)
39
+ - [Quick Start](#quick-start)
40
+ - [Installation](#installation)
41
+ - [API Key Setup](#api-key-setup)
42
+ - [Basic Usage](#basic-usage)
43
+ - [Features](#features)
44
+ - [Progress Reporting](#progress-reporting)
45
+ - [Replay Functionality](#replay-functionality)
46
+ - [Examples](#examples)
47
+ - [Interpreting Results](#interpreting-results)
48
+ - [Theta (θ)](#theta-θ)
49
+ - [Other Metrics](#other-metrics)
50
+ - [Contributing](#contributing)
51
+ - [License](#license)
52
+
53
+ ## Overview
54
+
55
+ [**Trismik**](https://trismik.com) is a Cambridge, UK based startup offering adversarial testing for LLMs. The APIs we provide through this library allow you to call our adaptive test engine and evaluate LLMs up to 95% faster (and cheaper!) than traditional evaluation techniques.
56
+
57
+ Our **adaptive testing** algorithm allows to estimate the precision of the model by looking only at a small portion of a dataset. Through this library, we provide access to a number of open source datasets over several dimensions (reasoning, toxicity, tool use...) to speed up model testing in several scenarios, like foundation model training, supervised fine tuning, prompt engineering, and so on.
58
+
59
+ ## Quick Start
60
+
61
+ ### Installation
62
+
63
+ To use our API, you need to get an API key first. Please register on [dashboard.trismik.com](https://dashboard.trismik.com) and obtain an API key.
64
+
65
+ Trismik is available via [pypi](https://pypi.org/project/trismik/). To install Trismik, run the following in your terminal (in a virtualenv, if you use one):
66
+
67
+ ```bash
68
+ pip install trismik
69
+ ```
70
+
71
+ ### API Key Setup
72
+
73
+ You can provide your API key in one of the following ways:
74
+
75
+ 1. **Environment Variable**:
76
+ ```bash
77
+ export TRISMIK_API_KEY="your-api-key"
78
+ ```
79
+
80
+ 2. **`.env` File**:
81
+ ```bash
82
+ # .env
83
+ TRISMIK_API_KEY=your-api-key
84
+ ```
85
+ Then load it with `python-dotenv`:
86
+ ```python
87
+ from dotenv import load_dotenv
88
+ load_dotenv()
89
+ ```
90
+
91
+ 3. **Direct Initialization**:
92
+ ```python
93
+ client = TrismikClient(api_key="YOUR_API_KEY")
94
+ ```
95
+
96
+ ### Basic Usage
97
+
98
+ Here's the simplest way to run an adaptive test:
99
+
100
+ ```python
101
+ from trismik import TrismikClient, TrismikRunMetadata
102
+ from trismik.types import TrismikItem
103
+
104
+ # Define your item processor
105
+ def model_inference(item: TrismikItem) -> str:
106
+ # Your model inference logic here
107
+ # See examples/ folder for real-world implementations
108
+ return item.choices[0].id # Example: pick first choice
109
+
110
+ # Run the test
111
+ with TrismikClient() as client:
112
+ results = client.run(
113
+ test_id="MMLUPro2024",
114
+ project_id="your-project-id", # Get from dashboard or create with client.create_project()
115
+ experiment="my-experiment",
116
+ run_metadata=TrismikRunMetadata(
117
+ model_metadata={"name": "my-model", "provider": "local"},
118
+ test_configuration={"task_name": "MMLUPro2024"},
119
+ inference_setup={},
120
+ ),
121
+ item_processor=model_inference,
122
+ )
123
+
124
+ print(f"Theta: {results.score.theta}")
125
+ print(f"Standard Error: {results.score.std_error}")
126
+ ```
127
+
128
+ **For async usage:**
129
+
130
+ ```python
131
+ from trismik import TrismikAsyncClient
132
+
133
+ async with TrismikAsyncClient() as client:
134
+ results = await client.run(
135
+ test_id="MMLUPro2024",
136
+ project_id="your-project-id",
137
+ experiment="my-experiment",
138
+ run_metadata=TrismikRunMetadata(...),
139
+ item_processor=model_inference, # Can be sync or async
140
+ )
141
+ ```
142
+
143
+ ## Features
144
+
145
+ ### Progress Reporting
146
+
147
+ Add optional progress tracking with a callback:
148
+
149
+ ```python
150
+ from tqdm.auto import tqdm
151
+ from trismik.settings import evaluation_settings
152
+
153
+ def create_progress_callback():
154
+ pbar = tqdm(total=evaluation_settings["max_iterations"], desc="Running test")
155
+
156
+ def callback(current: int, total: int):
157
+ pbar.total = total
158
+ pbar.n = current
159
+ pbar.refresh()
160
+ if current >= total:
161
+ pbar.close()
162
+
163
+ return callback
164
+
165
+ # Use it in your run
166
+ with TrismikClient() as client:
167
+ results = client.run(
168
+ # ... other parameters ...
169
+ on_progress=create_progress_callback(),
170
+ )
171
+ ```
172
+
173
+ The library is silent by default - progress reporting is entirely optional.
174
+
175
+ ### Replay Functionality
176
+
177
+ Replay the exact sequence of questions from a previous run to test model stability:
178
+
179
+ ```python
180
+ with TrismikClient() as client:
181
+ # Run initial test
182
+ results = client.run(
183
+ test_id="MMLUPro2024",
184
+ project_id="your-project-id",
185
+ experiment="experiment-1",
186
+ run_metadata=metadata,
187
+ item_processor=model_inference,
188
+ )
189
+
190
+ # Replay with same questions
191
+ replay_results = client.run_replay(
192
+ previous_run_id=results.run_id,
193
+ run_metadata=new_metadata,
194
+ item_processor=model_inference,
195
+ with_responses=True, # Include individual responses
196
+ )
197
+ ```
198
+
199
+ ## Examples
200
+
201
+ Complete working examples are available in the `examples/` folder:
202
+
203
+ - **[`example_adaptive_test.py`](examples/example_adaptive_test.py)** - Basic adaptive testing with both sync and async patterns, including replay functionality
204
+ - **[`example_openai.py`](examples/example_openai.py)** - Integration with OpenAI API models
205
+ - **[`example_transformers.py`](examples/example_transformers.py)** - Integration with Hugging Face Transformers models
206
+
207
+ To run the examples:
208
+
209
+ ```bash
210
+ # Clone the repository and install with examples dependencies
211
+ git clone https://github.com/trismik/trismik-python
212
+ cd trismik-python
213
+ poetry install --with examples
214
+
215
+ # Run an example
216
+ poetry run python examples/example_adaptive_test.py --dataset-name MMLUPro2024
217
+ ```
218
+
219
+ ## Interpreting Results
220
+
221
+ ### Theta (θ)
222
+
223
+ Our adaptive test returns several values; however, you will be interested mainly in `theta`. Theta ($\theta$) is our metric; it measures the ability of the model on a certain dataset, and it can be used as a proxy to approximate the original metric used on that dataset. For example, on an accuracy-based dataset, a high theta correlates with a high accuracy, and low theta correlates with low accuracy.
224
+
225
+ $\theta$ is intrinsically linked to the difficulty of the items a model can answer correctly. On a datasets where the item difficulties are balanced and evenly distributed, $\theta=0$ corresponds to a 50% chance for a model to get an answer right - in other words, to an accuracy of 50%.
226
+ A negative theta means that the model will give more bad answers than good ones, while a positive theta means that the model will give more good answers than bad answers.
227
+ While theta is unbounded in our implementation (i.e. $-\infty < \theta < \infty$), in practice we have that for most cases $\theta$ will take values between -3 and 3.
228
+
229
+ Compared to classical benchmark testing, $\theta$ from adaptive testing uses fewer but more informative items while avoiding noise from overly easy or difficult questions. This makes it a more efficient and stable measure, especially on very large datasets.
230
+
231
+ ### Other Metrics
232
+
233
+ - **Standard Deviation (`std`)**:
234
+ - A measure of the uncertainty or error in the theta estimate
235
+ - A smaller `std` indicates a more precise estimate
236
+ - You should see a `std` around or below 0.25
237
+
238
+ - **Correct Responses (`responsesCorrect`)**:
239
+ - The number of correct answers delivered by the model
240
+
241
+ - **Important note**: A higher number of correct answers does not necessarily
242
+ correlate with a high theta. Our algorithm navigates the dataset to find a
243
+ balance of "hard" and "easy" items for your model, so by the end of the test,
244
+ it encounters a representative mix of inputs it can and cannot handle. In
245
+ practice, expect responsesCorrect to be roughly half of responsesTotal.
246
+
247
+ - **Total Responses (`responsesTotal`)**:
248
+ - The number of items processed before reaching a stable theta.
249
+ - Expected range: 60 ≤ responses_total ≤ 150
250
+
251
+ ## Contributing
252
+
253
+ See `CONTRIBUTING.md`.
254
+
255
+ ## License
256
+
257
+ This library is licensed under the MIT license. See `LICENSE` file.
258
+
@@ -0,0 +1,18 @@
1
+ trismik/__init__.py,sha256=LiS6Mo8iHMPKerVWFNVmn-V8dsoXHrHo-qG1FAakHcY,770
2
+ trismik/_async/__init__.py,sha256=9ZJB9Amqym2QQT_aLzM_6gx9qNCOY14cq_Oc7gu7O1I,64
3
+ trismik/_async/_test_transform.py,sha256=N5eS1dSHXBTLXaB7kO3IPHD4gScm4XSMMcg8nVc7Dl4,1760
4
+ trismik/_async/client.py,sha256=QcQBRW26mdow5LiInZUpnwS37llx9v-AX5bi1OMcNks,25481
5
+ trismik/_async/helpers.py,sha256=7Kd6w0KRs_MsBpBM4ctstsEGHIf_vq9QmdqWcIFlYjE,694
6
+ trismik/_mapper.py,sha256=E8vK2KDP_o9zUkOiTTtjEC324UYBuyElug0b-JgY5NE,10706
7
+ trismik/_sync/__init__.py,sha256=9ZJB9Amqym2QQT_aLzM_6gx9qNCOY14cq_Oc7gu7O1I,64
8
+ trismik/_sync/_test_transform.py,sha256=bJn4Yorqyqinb9Tv5257vSwy42oCrdXvvut0ZbbCeL4,1675
9
+ trismik/_sync/client.py,sha256=VQLxUfxpnfWGs34Rq9zLeVT3lUkyuuTzkZeAr_GUmmw,25245
10
+ trismik/_sync/helpers.py,sha256=9mPILjtT-Yh9EMtiILdYSy0Pt3De9jId5F-iJAPL1Pw,723
11
+ trismik/_utils.py,sha256=ckOg4PEjbTPaSH_q7QSGdoML4Rn1G5TRcSMnEluYhHk,3818
12
+ trismik/exceptions.py,sha256=2wb4_K7GdDf00s3xUaiSfw6718ZV3Eaa4M2lYbiEZl4,1945
13
+ trismik/settings.py,sha256=ErXj3f9Uw1AgewytjxmIY7TmM5jB7RE_LJMp3T7szBY,419
14
+ trismik/types.py,sha256=zo6QcXpo7ZfdEntvJDzftBPq_8_g0fS-XDfNTtKVg8k,6555
15
+ trismik-1.0.0.dist-info/METADATA,sha256=5x1MteAAr0g0Dzv8gv6xC69zylecjcG_M6VLUtnxFXI,9339
16
+ trismik-1.0.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
17
+ trismik-1.0.0.dist-info/licenses/LICENSE,sha256=tgetRhapGLh7ZxfknW6Mm-WobfziPd64nAK52X5XKaw,1077
18
+ trismik-1.0.0.dist-info/RECORD,,