mistralai-evaluations 0.7.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 (89) hide show
  1. mistralai_evaluations-0.7.0/.gitignore +2 -0
  2. mistralai_evaluations-0.7.0/AGENTS.md +96 -0
  3. mistralai_evaluations-0.7.0/CLAUDE.md +1 -0
  4. mistralai_evaluations-0.7.0/LICENSE +190 -0
  5. mistralai_evaluations-0.7.0/Makefile +34 -0
  6. mistralai_evaluations-0.7.0/PKG-INFO +244 -0
  7. mistralai_evaluations-0.7.0/README.md +221 -0
  8. mistralai_evaluations-0.7.0/docs/OFFEV-303-PLAN.md +207 -0
  9. mistralai_evaluations-0.7.0/docs/docs/getting-started/_category_.json +8 -0
  10. mistralai_evaluations-0.7.0/docs/docs/getting-started/installation.mdx +90 -0
  11. mistralai_evaluations-0.7.0/docs/docs/getting-started/introduction.mdx +142 -0
  12. mistralai_evaluations-0.7.0/docs/docs/guides/_category_.json +8 -0
  13. mistralai_evaluations-0.7.0/docs/docs/guides/basic-evaluation.mdx +222 -0
  14. mistralai_evaluations-0.7.0/docs/docs/guides/context-objects.mdx +143 -0
  15. mistralai_evaluations-0.7.0/docs/docs/guides/examples.mdx +220 -0
  16. mistralai_evaluations-0.7.0/docs/docs/guides/goals.mdx +212 -0
  17. mistralai_evaluations-0.7.0/docs/docs/guides/llm-as-judge.mdx +180 -0
  18. mistralai_evaluations-0.7.0/docs/docs/guides/local-mode.mdx +59 -0
  19. mistralai_evaluations-0.7.0/docs/docs/guides/migrating.mdx +145 -0
  20. mistralai_evaluations-0.7.0/docs/docs/guides/multiple-evaluators.mdx +78 -0
  21. mistralai_evaluations-0.7.0/docs/docs/guides/num-generations.mdx +83 -0
  22. mistralai_evaluations-0.7.0/docs/docs/guides/optimization.mdx +340 -0
  23. mistralai_evaluations-0.7.0/docs/docs/guides/retry-failed-records.mdx +112 -0
  24. mistralai_evaluations-0.7.0/docs/docs/guides/run-evaluators.mdx +91 -0
  25. mistralai_evaluations-0.7.0/docs/docs/guides/system-params.mdx +70 -0
  26. mistralai_evaluations-0.7.0/docs/docs/reference/_category_.json +8 -0
  27. mistralai_evaluations-0.7.0/docs/docs/reference/api-reference.mdx +174 -0
  28. mistralai_evaluations-0.7.0/docs/docs/reference/models.mdx +168 -0
  29. mistralai_evaluations-0.7.0/docs/docs/reference/optimization.mdx +264 -0
  30. mistralai_evaluations-0.7.0/docs/docs/reference/retry-failed-records.mdx +64 -0
  31. mistralai_evaluations-0.7.0/docs/docs/reference/step-by-step-api.mdx +127 -0
  32. mistralai_evaluations-0.7.0/docs/sidebars.js +24 -0
  33. mistralai_evaluations-0.7.0/examples/README.md +23 -0
  34. mistralai_evaluations-0.7.0/examples/fact_extraction/code.py +179 -0
  35. mistralai_evaluations-0.7.0/examples/fact_extraction/expected_output.txt +52 -0
  36. mistralai_evaluations-0.7.0/examples/goals/code.py +85 -0
  37. mistralai_evaluations-0.7.0/examples/language_detection/code.py +92 -0
  38. mistralai_evaluations-0.7.0/examples/language_detection/expected_output.txt +176 -0
  39. mistralai_evaluations-0.7.0/examples/utils.py +6 -0
  40. mistralai_evaluations-0.7.0/mistralai/evaluations/__init__.py +140 -0
  41. mistralai_evaluations-0.7.0/mistralai/evaluations/_api.py +228 -0
  42. mistralai_evaluations-0.7.0/mistralai/evaluations/_client.py +23 -0
  43. mistralai_evaluations-0.7.0/mistralai/evaluations/_endpoints.py +236 -0
  44. mistralai_evaluations-0.7.0/mistralai/evaluations/_internal_metadata.py +41 -0
  45. mistralai_evaluations-0.7.0/mistralai/evaluations/_managers.py +1055 -0
  46. mistralai_evaluations-0.7.0/mistralai/evaluations/_run_info.py +51 -0
  47. mistralai_evaluations-0.7.0/mistralai/evaluations/_upload.py +141 -0
  48. mistralai_evaluations-0.7.0/mistralai/evaluations/_version.py +7 -0
  49. mistralai_evaluations-0.7.0/mistralai/evaluations/api_models.py +423 -0
  50. mistralai_evaluations-0.7.0/mistralai/evaluations/display.py +340 -0
  51. mistralai_evaluations-0.7.0/mistralai/evaluations/execution.py +390 -0
  52. mistralai_evaluations-0.7.0/mistralai/evaluations/goal.py +79 -0
  53. mistralai_evaluations-0.7.0/mistralai/evaluations/helpers.py +38 -0
  54. mistralai_evaluations-0.7.0/mistralai/evaluations/models.py +306 -0
  55. mistralai_evaluations-0.7.0/mistralai/evaluations/optimization/__init__.py +54 -0
  56. mistralai_evaluations-0.7.0/mistralai/evaluations/optimization/_rng.py +63 -0
  57. mistralai_evaluations-0.7.0/mistralai/evaluations/optimization/gepa.py +201 -0
  58. mistralai_evaluations-0.7.0/mistralai/evaluations/optimization/objective.py +195 -0
  59. mistralai_evaluations-0.7.0/mistralai/evaluations/optimization/pareto.py +68 -0
  60. mistralai_evaluations-0.7.0/mistralai/evaluations/optimization/reflection.py +240 -0
  61. mistralai_evaluations-0.7.0/mistralai/evaluations/optimization/result.py +332 -0
  62. mistralai_evaluations-0.7.0/mistralai/evaluations/optimization/runtime.py +481 -0
  63. mistralai_evaluations-0.7.0/mistralai/evaluations/optimization/search_space.py +115 -0
  64. mistralai_evaluations-0.7.0/mistralai/evaluations/optimization/simple.py +129 -0
  65. mistralai_evaluations-0.7.0/mistralai/evaluations/optimization/types.py +225 -0
  66. mistralai_evaluations-0.7.0/mistralai/evaluations/py.typed +0 -0
  67. mistralai_evaluations-0.7.0/mistralai/evaluations/statistics.py +92 -0
  68. mistralai_evaluations-0.7.0/mistralai/evaluations/utils.py +34 -0
  69. mistralai_evaluations-0.7.0/pyproject.toml +96 -0
  70. mistralai_evaluations-0.7.0/tests/__init__.py +0 -0
  71. mistralai_evaluations-0.7.0/tests/conftest.py +51 -0
  72. mistralai_evaluations-0.7.0/tests/test_api.py +310 -0
  73. mistralai_evaluations-0.7.0/tests/test_api_models_goal_results.py +148 -0
  74. mistralai_evaluations-0.7.0/tests/test_display.py +82 -0
  75. mistralai_evaluations-0.7.0/tests/test_execution.py +1368 -0
  76. mistralai_evaluations-0.7.0/tests/test_goal.py +315 -0
  77. mistralai_evaluations-0.7.0/tests/test_helpers.py +109 -0
  78. mistralai_evaluations-0.7.0/tests/test_managers.py +1151 -0
  79. mistralai_evaluations-0.7.0/tests/test_managers_legacy_direction.py +56 -0
  80. mistralai_evaluations-0.7.0/tests/test_optimization_gepa.py +415 -0
  81. mistralai_evaluations-0.7.0/tests/test_optimization_objective.py +187 -0
  82. mistralai_evaluations-0.7.0/tests/test_optimization_pareto.py +83 -0
  83. mistralai_evaluations-0.7.0/tests/test_optimization_persistence.py +310 -0
  84. mistralai_evaluations-0.7.0/tests/test_optimization_reflection.py +73 -0
  85. mistralai_evaluations-0.7.0/tests/test_optimization_result.py +387 -0
  86. mistralai_evaluations-0.7.0/tests/test_optimization_search_space.py +82 -0
  87. mistralai_evaluations-0.7.0/tests/test_optimization_simple.py +201 -0
  88. mistralai_evaluations-0.7.0/tests/test_statistics.py +62 -0
  89. mistralai_evaluations-0.7.0/tests/test_utils.py +116 -0
@@ -0,0 +1,2 @@
1
+ training_capture_enriched_data.ndjson
2
+ customer_capture_enriched_data.ndjson
@@ -0,0 +1,96 @@
1
+ # mistralai-evaluations
2
+
3
+ ## Overview
4
+
5
+ This package sets up the `mistralai.evaluations` namespace, extending the Mistral AI SDK v2 (see [CLAUDE.md](../../openapi/CLAUDE.md)) to allow evaluation features to be developed and released from this repository.
6
+
7
+ It is an LLM evaluation runner that creates entities and uploads results using Dora endpoints (see `offline_evaluations_router` in [public_routes.py](../dora/api/public_routes.py)). Results are displayed in AI Studio (see [Projects page](<../../ts/apps/la-console/src/app/(basic-layout)/observability/projects>)).
8
+
9
+ Laperf is a POC that does the same without eval runners. It has an API (see [laperf_routes.py](../dora/api/laperf_routes.py)) and a UI (see [Initiatives page](<../../ts/apps/la-console/src/app/(basic-layout)/observability/initiatives>)).
10
+
11
+ ## TypeScript Mirror
12
+
13
+ This Python SDK has an idiomatic TypeScript adaptation at `ts/packages/local-observability-sdk/`.
14
+ **Any change here must be replicated in the TypeScript SDK** — adapting to TypeScript conventions rather than translating line-for-line.
15
+
16
+ See `ts/packages/local-observability-sdk/AGENTS.md` for the full file mapping, adaptation philosophy, and replication workflow.
17
+
18
+ ### Quick checklist after making changes
19
+
20
+ 1. Replicate the change in the TS SDK — see `ts/packages/local-observability-sdk/AGENTS.md` for the full workflow
21
+
22
+ ## Project Structure
23
+
24
+ This is a **namespace package** — the wheel ships `mistralai/evaluations/` to extend the `mistralai` SDK namespace:
25
+
26
+ ```
27
+ mistralai/evaluations/
28
+ __init__.py
29
+ client.py # Main client interface
30
+ api.py # API communication with Dora backend
31
+ api_models.py # API request/response models
32
+ models.py # Core domain models (evaluations, datasets, etc.)
33
+ managers.py # High-level orchestration logic
34
+ execution.py # Evaluation execution engine
35
+ display.py # Terminal output formatting
36
+ utils.py # Shared helpers
37
+ examples/ # Example evaluation scripts (see examples/README.md)
38
+ ```
39
+
40
+ ## Development
41
+
42
+ ```sh
43
+ make install # Install dependencies (uv sync)
44
+ make test # Run pytest
45
+ make lint # Format + typecheck + ruff check
46
+ make format # Auto-format with ruff, use it after each code change
47
+ make typecheck # Run mypy
48
+ make build # Build the wheel
49
+ make publish # Manual Gemfury publish (requires GEMFURY_USERNAME/GEMFURY_PASSWORD)
50
+ ```
51
+
52
+
53
+ ### Releasing
54
+
55
+ The version is **not** stored in code. This package uses
56
+ [`uv-dynamic-versioning`](https://github.com/ninoseki/uv-dynamic-versioning): the
57
+ published version is derived from the release tag (`evaluations-sdk/vX.Y.Z`), and
58
+ the release workflow stamps the version you pass onto the build via
59
+ `UV_DYNAMIC_VERSIONING_BYPASS`. **There is no version-bump PR** — just run the
60
+ workflow with the version you want. This matches the workflow evaluation plugin.
61
+
62
+ To release:
63
+
64
+ 1. Run the "Release Evaluations SDK" GitHub workflow from `main` or the relevant
65
+ `mais-*` release branch.
66
+ 2. Set the `version` input (PEP 440, e.g. `0.7.0` or `0.7.0rc1`). The workflow
67
+ rejects a version whose tag `evaluations-sdk/vX.Y.Z` already exists.
68
+ 3. Pick the target registries via the boolean inputs (PyPI on, Gemfury on,
69
+ Cloudsmith off by default). To dogfood privately first, publish an `rc` to
70
+ Gemfury only; the rc tag won't collide with the later public release.
71
+ 4. The workflow tags `evaluations-sdk/vX.Y.Z` on the released commit as soon as
72
+ **any** requested registry publishes successfully.
73
+
74
+ An agent can run and monitor the release with the GitHub CLI:
75
+
76
+ ```sh
77
+ gh workflow run evaluations-sdk-release.yaml --ref main -f version=X.Y.Z
78
+ gh run list --workflow evaluations-sdk-release.yaml --branch main --limit 1
79
+ gh run watch <run-id>
80
+ gh run rerun <run-id> --failed
81
+ ```
82
+
83
+ Use the relevant `mais-*` branch instead of `main` when releasing an on-prem patch line. If one package index succeeds
84
+ and the other fails, do not rerun the full workflow because the already-successful package index may reject the
85
+ duplicate version; use `gh run rerun <run-id> --failed`.
86
+
87
+ > **TypeScript mirror:** `ts/packages/local-observability-sdk/` still carries its own
88
+ > `package.json` / `cli.ts` version and is not published by this workflow. Keep it in
89
+ > sync when practical; it is not gated by the Python release.
90
+
91
+ ### Run Examples
92
+
93
+ ```sh
94
+ uv run examples/language_detection/code.py
95
+ uv run examples/fact_extraction/code.py
96
+ ```
@@ -0,0 +1 @@
1
+ AGENTS.md
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Mistral AI
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,34 @@
1
+ .PHONY: lint format typecheck test install build clean publish
2
+
3
+ # Standard targets (per CLAUDE.md convention)
4
+
5
+ lint: format typecheck
6
+ uv run ruff check .
7
+
8
+ format:
9
+ uv run ruff format .
10
+ uv run ruff check --fix .
11
+
12
+ typecheck:
13
+ uv run mypy mistralai
14
+
15
+ test:
16
+ uv run pytest
17
+
18
+ install:
19
+ uv sync
20
+
21
+ # Build and publish targets
22
+
23
+ clean:
24
+ rm -rf dist/
25
+
26
+ build: clean
27
+ uv build
28
+
29
+ publish: build
30
+ @if [ -z "$$GEMFURY_USERNAME" ] || [ -z "$$GEMFURY_PASSWORD" ]; then \
31
+ echo "Error: GEMFURY_USERNAME and GEMFURY_PASSWORD must be set"; \
32
+ exit 1; \
33
+ fi
34
+ uv publish --publish-url https://push.fury.io/mistralai/ --username $$GEMFURY_USERNAME --password $$GEMFURY_PASSWORD
@@ -0,0 +1,244 @@
1
+ Metadata-Version: 2.5
2
+ Name: mistralai-evaluations
3
+ Version: 0.7.0
4
+ Summary: Mistral AI Studio evaluation tools
5
+ Project-URL: Homepage, https://mistral.ai
6
+ Author-email: Mistral AI <support@mistral.ai>
7
+ License: Apache-2.0
8
+ License-File: LICENSE
9
+ Keywords: ai,evaluation,llm,mistral,observability
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Requires-Python: >=3.12
18
+ Requires-Dist: colorama>=0.4.0
19
+ Requires-Dist: mistralai<3.0.0,>=2.4.7
20
+ Requires-Dist: pydantic>=2.0.0
21
+ Requires-Dist: structlog>=24.0.0
22
+ Description-Content-Type: text/markdown
23
+
24
+ # Mistral Evaluations
25
+
26
+ Namespace package for Mistral AI evaluation (Dora) utilities.
27
+
28
+ ## Overview
29
+
30
+ This package sets up the `mistralai.evaluations` namespace for Dora-specific utilities. It extends the Mistral AI SDK
31
+ v2 namespace structure to allow evaluation features to be developed and released from this repository.
32
+
33
+ ## SDK v2 Namespace Package
34
+
35
+ This package follows [PEP 420](https://peps.python.org/pep-0420/) implicit namespace packaging to integrate with the
36
+ Mistral AI SDK v2 structure. The code lives in this repository (Dora) but will be importable from
37
+ `mistralai.evaluations` once SDK v2 is released.
38
+
39
+ ### Package Structure
40
+
41
+ ```
42
+ mistralai/ # Shared namespace (no __init__.py)
43
+ ├── client/ # Core SDK (mistralai package on PyPI)
44
+ ├── workflows/ # Workflows SDK
45
+ ├── evaluations/ # This package (Dora utilities)
46
+ └── extra/ # Extra utilities
47
+ ```
48
+
49
+ The `mistralai/` directory has no `__init__.py`, allowing multiple packages to coexist under the shared `mistralai`
50
+ namespace.
51
+
52
+ ## Installation
53
+
54
+ This package is currently under development. Once SDK v2 is released, it will be available as part of the `mistralai`
55
+ namespace.
56
+
57
+ For local development:
58
+
59
+ ```bash
60
+ uv sync
61
+ ```
62
+
63
+ ## Usage
64
+
65
+ ### Basic evaluation
66
+
67
+ ```python
68
+ from mistralai.evaluations import Evaluation, Evaluator, Project
69
+
70
+ run = await client.evaluation.run(
71
+ project=Project(name="My Project"),
72
+ evaluation=Evaluation(name="My Evaluation"),
73
+ dataset=[{"input": "hello", "expected": "greeting"}],
74
+ task=lambda input_record: classify(input_record["input"]),
75
+ evaluators=[
76
+ Evaluator(name="accuracy", scorer=lambda input_record, output: 1 if output == input_record["expected"] else 0),
77
+ ],
78
+ )
79
+ run.show(level="scores")
80
+ ```
81
+
82
+ ### Run-level evaluators
83
+
84
+ Run evaluators execute after all records are processed and receive the full run context (records, statistics, metrics, metadata). Use them for global assertions or aggregate metrics.
85
+
86
+ ```python
87
+ from mistralai.evaluations import RunEvaluator
88
+
89
+ run = await client.evaluation.run(
90
+ ...,
91
+ evaluators=[
92
+ Evaluator(name="accuracy", scorer=lambda input_record, output: 1 if output == input_record["expected"] else 0),
93
+ ],
94
+ run_evaluators=[
95
+ RunEvaluator(
96
+ name="accuracy_above_50pct",
97
+ scorer=lambda ctx: ctx.statistics["accuracy"].avg > 0.5,
98
+ ),
99
+ RunEvaluator(
100
+ name="all_records_scored",
101
+ scorer=lambda ctx: all(
102
+ len(r.output.generations) > 0 for r in ctx.records
103
+ ),
104
+ ),
105
+ ],
106
+ )
107
+ # Results are in run.run_scores
108
+ print(run.run_scores) # {"accuracy_above_50pct": True, "all_records_scored": True}
109
+ ```
110
+
111
+ The `RunEvaluatorContext` provides:
112
+
113
+ | Field | Type | Description |
114
+ | ------------ | -------------------------------- | --------------------------------------------- |
115
+ | `records` | `list[RunEvaluatorRecord]` | Each record's input and output (with scores). |
116
+ | `statistics` | `dict[str, EvaluatorStatistics]` | Run-level statistics from regular evaluators. |
117
+ | `metrics` | `dict[str, JsonValue]` | Run-level `run_aggregator` results. |
118
+ | `metadata` | `dict[str, JsonValue]` | Metadata attached to the run. |
119
+
120
+ ### Retrying failed records
121
+
122
+ If an evaluation only partially fails, use `retry_failed_records` instead of re-running the entire evaluation from
123
+ scratch. It re-runs only the failed records and patches the original run in place, avoiding work on successful records
124
+ when failures came from transient API errors, rate limits, or a bug in the task or scorer.
125
+
126
+ ```python
127
+ from mistralai.evaluations import Evaluation, Evaluator
128
+
129
+ run = await client.evaluation.run(
130
+ evaluation=Evaluation(name="My Evaluation"),
131
+ dataset=dataset,
132
+ task=flaky_task,
133
+ evaluators=[Evaluator(name="accuracy", scorer=scorer)],
134
+ )
135
+
136
+ # Fix the task or scorer if needed, then retry only the failed records.
137
+ result = await client.evaluation.retry_failed_records(
138
+ run_id=run.run_id,
139
+ dataset=dataset,
140
+ task=fixed_task,
141
+ evaluators=[Evaluator(name="accuracy", scorer=scorer)],
142
+ )
143
+
144
+ print(f"Retried: {result.retried_count}, Patched: {result.patched_count}")
145
+ ```
146
+
147
+ Pass the same `dataset` used in the original run so the SDK can map failed records back to their inputs. You can pass a
148
+ fixed `task` or updated evaluators before retrying. When run-level evaluators are provided, their scores are recomputed
149
+ after patching.
150
+
151
+ ### `get_score` helper
152
+
153
+ When writing run evaluators, accessing individual scores requires navigating through generations and score lists. The `get_score` helper simplifies this:
154
+
155
+ ```python
156
+ from mistralai.evaluations import RunEvaluatorContext, Score, get_score
157
+
158
+ def f1_scorer(ctx: RunEvaluatorContext) -> Score:
159
+ tp = fp = fn = 0
160
+ for record in ctx.records:
161
+ expected = str(record.input["expected"]).lower()
162
+ # Instead of: record.output.generations[0].scores["accuracy"][0].value
163
+ is_correct = get_score(record, "accuracy").value == 1
164
+ ...
165
+ ```
166
+
167
+ Returns a `Score` object (with `value`, `rationale`, `metadata`).
168
+
169
+ | Parameter | Type | Default | Description |
170
+ | ---------------- | -------------------------------- | ------- | ----------------------------------------------------------- |
171
+ | `record` | `RunEvaluatorRecord` | — | The record to extract scores from. |
172
+ | `evaluator_name` | `str` | — | Name of the evaluator whose scores to retrieve. |
173
+ | `aggregate` | `Callable[[list[Score]], Score]` | `None` | Required when multiple scores exist (multiple generations). |
174
+
175
+ Raises if no scores are found. When `num_generations > 1`, raises with a helpful message unless an `aggregate` function is provided. For pre-computed aggregations, use `record.output.statistics[evaluator_name]` instead.
176
+
177
+ ## Development
178
+
179
+ ```bash
180
+ # Install dependencies
181
+ uv sync
182
+
183
+ # Run tests
184
+ uv run pytest
185
+
186
+ # Lint and format
187
+ uv run ruff check --fix .
188
+ uv run ruff format .
189
+
190
+ # Type check
191
+ uv run mypy mistralai
192
+ ```
193
+
194
+ ## Publishing
195
+
196
+ ### Release from GitHub
197
+
198
+ The version is **not** stored in code. This package uses
199
+ [`uv-dynamic-versioning`](https://github.com/ninoseki/uv-dynamic-versioning): the published version comes from the
200
+ release tag (`evaluations-sdk/vX.Y.Z`), and the workflow stamps the version you pass onto the build via
201
+ `UV_DYNAMIC_VERSIONING_BYPASS`. **There is no version-bump PR** — just run the workflow with the version you want.
202
+
203
+ Run the "Release Evaluations SDK" GitHub workflow manually. Choose which registries to publish to via the boolean
204
+ inputs — they're independent, so you can dogfood internally without shipping to clients:
205
+
206
+ 1. **PyPI** (public), via a trusted publisher (OIDC) — the primary channel. Default on.
207
+ 2. **Gemfury**, for internal distribution. Default on.
208
+ 3. **Cloudsmith** (`mistral-ai/sdk-distribution`), for private-preview client distribution. Default off — opt in when previewing to specific clients.
209
+
210
+ Run the workflow from `main` for normal SDK releases, or from the relevant `mais-*` release branch for on-prem patch
211
+ lines. Enter the version as the workflow `version` input (PEP 440, e.g. `0.7.0` or `0.7.0rc1`); the workflow fails if
212
+ the tag `evaluations-sdk/vX.Y.Z` already exists.
213
+
214
+ The git tag `evaluations-sdk/vX.Y.Z` records the released commit for that version, so it is created as soon as **any**
215
+ selected registry publishes successfully (and none of the selected ones failed). To dogfood privately, publish an `rc`
216
+ to Gemfury only; the rc tag won't collide with the later public release.
217
+
218
+ If one registry succeeds and another fails, rerun the failed GitHub Actions jobs only. Do not rerun the full workflow,
219
+ because the already-successful registry may reject the duplicate version.
220
+
221
+ The TypeScript mirror (`ts/packages/local-observability-sdk/`) still carries its own `package.json` / `cli.ts` version
222
+ and is not published by this workflow; keep it in sync when practical.
223
+
224
+ ### Manual Gemfury publish
225
+
226
+ Retrieve the "Gemfury Upload Token - Mistral" credentials from Bitwarden. The `make publish` command expects `GEMFURY_USERNAME` and `GEMFURY_PASSWORD` environment variables.
227
+
228
+ ```bash
229
+ # Publish to Gemfury
230
+ # this will clean up the dist/ directory then build and publish
231
+ make publish
232
+ ```
233
+
234
+ ### Installing from PyPI (public)
235
+
236
+ ```bash
237
+ pip install mistralai-evaluations
238
+ ```
239
+
240
+ ### Installing from Gemfury (internal)
241
+
242
+ ```bash
243
+ pip install --index-url https://pypi.fury.io/mistralai/ mistralai-evaluations --extra-index-url https://pypi.org/simple/
244
+ ```