ai-eval-platform 1.0.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.
- ai_eval_platform-1.0.0/LICENSE +202 -0
- ai_eval_platform-1.0.0/PKG-INFO +162 -0
- ai_eval_platform-1.0.0/README.md +132 -0
- ai_eval_platform-1.0.0/ai_eval/__init__.py +6 -0
- ai_eval_platform-1.0.0/ai_eval/_version.py +2 -0
- ai_eval_platform-1.0.0/ai_eval/cli.py +139 -0
- ai_eval_platform-1.0.0/ai_eval/client.py +157 -0
- ai_eval_platform-1.0.0/ai_eval/gate.py +134 -0
- ai_eval_platform-1.0.0/ai_eval/monitor.py +107 -0
- ai_eval_platform-1.0.0/ai_eval/py.typed +0 -0
- ai_eval_platform-1.0.0/ai_eval/tracing.py +166 -0
- ai_eval_platform-1.0.0/ai_eval_platform.egg-info/PKG-INFO +162 -0
- ai_eval_platform-1.0.0/ai_eval_platform.egg-info/SOURCES.txt +19 -0
- ai_eval_platform-1.0.0/ai_eval_platform.egg-info/dependency_links.txt +1 -0
- ai_eval_platform-1.0.0/ai_eval_platform.egg-info/entry_points.txt +2 -0
- ai_eval_platform-1.0.0/ai_eval_platform.egg-info/top_level.txt +1 -0
- ai_eval_platform-1.0.0/pyproject.toml +49 -0
- ai_eval_platform-1.0.0/setup.cfg +4 -0
- ai_eval_platform-1.0.0/tests/test_cli.py +104 -0
- ai_eval_platform-1.0.0/tests/test_monitor.py +43 -0
- ai_eval_platform-1.0.0/tests/test_tracing.py +59 -0
|
@@ -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.
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ai-eval-platform
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python SDK and `ai-eval` CI quality-gate CLI for the AI Evaluation Platform
|
|
5
|
+
Author: AssertThat
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://ai-evaluation-platform.com
|
|
8
|
+
Project-URL: Documentation, https://ai-evaluation-platform.com/docs#ci
|
|
9
|
+
Project-URL: AWS Marketplace, https://aws.amazon.com/marketplace/pp/prodview-qejr2yng5xgc6
|
|
10
|
+
Project-URL: GitHub Action, https://github.com/marketplace/actions/ai-evaluation-platform-quality-gate
|
|
11
|
+
Keywords: llm,evaluation,llm-as-a-judge,quality-gate,ci,ragas,opentelemetry,tracing
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
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 :: Software Development :: Quality Assurance
|
|
24
|
+
Classifier: Topic :: Software Development :: Testing
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# ai-eval-platform (Python SDK + CLI)
|
|
32
|
+
|
|
33
|
+
Standard-library-only client for the AI Evaluation Platform API, plus an `ai-eval` command
|
|
34
|
+
that runs an evaluation and fails your CI build when quality drops.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install ai-eval-platform
|
|
38
|
+
export AI_EVAL_API_KEY=... # Settings > API keys in the app
|
|
39
|
+
export AI_EVAL_API_URL=https://api.ai-evaluation-platform.com
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Quality gate in CI
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# 1. Your pipeline runs your app over the dataset's prompts and writes outputs.json:
|
|
46
|
+
# {"case-1": "the app's answer", "case-2": "..."}
|
|
47
|
+
# 2. Evaluate and gate:
|
|
48
|
+
ai-eval run --project <project_id> --dataset <dataset_id> --outputs outputs.json \
|
|
49
|
+
--fail-under pass_rate=0.9 --metric factual_accuracy=0.8 --version-label "$GIT_SHA"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
- `--fail-under NAME=VALUE` (repeatable or comma-separated): `pass_rate` (share of cases
|
|
53
|
+
where every metric meets its pass mark), `good_rate` (share labelled Good), or a run
|
|
54
|
+
average: `overall`, `safety`, `truth`, `quality`.
|
|
55
|
+
- `--metric KEY=VALUE`: the run average of metric `KEY` must be at least `VALUE`; `VALUE`
|
|
56
|
+
is also that metric's pass mark for `pass_rate`. Other metrics use the project's
|
|
57
|
+
thresholds, else 0.70.
|
|
58
|
+
- Instead of a dataset: `--file cases.jsonl` (cases with `prompt`, `llm_output`, ...) or
|
|
59
|
+
`--file results.csv` (uploaded with the same column mapping as the app), or
|
|
60
|
+
`--job <job_id>` to gate a run that already exists.
|
|
61
|
+
- Exit code 0 = passed, 1 = gate failed, 2 = error (bad arguments, API error, timeout).
|
|
62
|
+
`--report-json gate.json` writes the numbers for later steps.
|
|
63
|
+
|
|
64
|
+
The run shows up in the app with its version label, so you can compare it with the
|
|
65
|
+
previous build's run on the same dataset version.
|
|
66
|
+
|
|
67
|
+
### GitHub Actions
|
|
68
|
+
|
|
69
|
+
The [AI Evaluation Platform quality gate](https://github.com/marketplace/actions/ai-evaluation-platform-quality-gate)
|
|
70
|
+
action wraps the CLI:
|
|
71
|
+
|
|
72
|
+
```yaml
|
|
73
|
+
- run: python scripts/generate_outputs.py > outputs.json # your app
|
|
74
|
+
- uses: assertthat/ai-eval-action@v1
|
|
75
|
+
with:
|
|
76
|
+
api-key: ${{ secrets.AI_EVAL_API_KEY }}
|
|
77
|
+
project: ${{ vars.AI_EVAL_PROJECT }}
|
|
78
|
+
dataset: ${{ vars.AI_EVAL_DATASET }}
|
|
79
|
+
outputs: outputs.json
|
|
80
|
+
fail-under: pass_rate=0.9
|
|
81
|
+
metric-thresholds: factual_accuracy=0.8
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Bitbucket Pipelines
|
|
85
|
+
|
|
86
|
+
With the pipe:
|
|
87
|
+
|
|
88
|
+
```yaml
|
|
89
|
+
- step:
|
|
90
|
+
name: LLM quality gate
|
|
91
|
+
script:
|
|
92
|
+
- python scripts/generate_outputs.py > outputs.json # your app
|
|
93
|
+
- pipe: docker://assertthat/ai-eval-pipe:1.0.0
|
|
94
|
+
variables:
|
|
95
|
+
AI_EVAL_API_KEY: $AI_EVAL_API_KEY
|
|
96
|
+
PROJECT: $AI_EVAL_PROJECT
|
|
97
|
+
DATASET: $AI_EVAL_DATASET
|
|
98
|
+
OUTPUTS: outputs.json
|
|
99
|
+
FAIL_UNDER: pass_rate=0.9
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Or with the CLI directly:
|
|
103
|
+
|
|
104
|
+
```yaml
|
|
105
|
+
- step:
|
|
106
|
+
name: LLM quality gate
|
|
107
|
+
image: python:3.12-slim
|
|
108
|
+
script:
|
|
109
|
+
- pip install ai-eval-platform
|
|
110
|
+
- python scripts/generate_outputs.py > outputs.json
|
|
111
|
+
- ai-eval run --project $AI_EVAL_PROJECT --dataset $AI_EVAL_DATASET --outputs outputs.json
|
|
112
|
+
--fail-under pass_rate=0.9 --version-label $BITBUCKET_COMMIT --run-name "$BITBUCKET_BRANCH"
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
(Set `AI_EVAL_API_KEY` as a secured repository variable.)
|
|
116
|
+
|
|
117
|
+
## Tracing agents
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from ai_eval import Client
|
|
121
|
+
from ai_eval.tracing import Tracer
|
|
122
|
+
|
|
123
|
+
tracer = Tracer(Client(), project_id="...")
|
|
124
|
+
with tracer.trace("support-agent", session_id=conversation_id, input=question) as t:
|
|
125
|
+
with tracer.span("lookup_order", kind="tool", input={"id": 42}) as s:
|
|
126
|
+
s.output = lookup_order(42)
|
|
127
|
+
t.output = answer
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Or point any OpenTelemetry OTLP/HTTP exporter at `<api>/v1/traces` with the header
|
|
131
|
+
`X-API-Key` - see the [tracing docs](https://ai-evaluation-platform.com/docs#traces).
|
|
132
|
+
|
|
133
|
+
## Production monitoring
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from ai_eval.monitor import Monitor
|
|
137
|
+
|
|
138
|
+
monitor = Monitor(Client(), project_id="...") # sends in the background
|
|
139
|
+
monitor.log(prompt=question, llm_output=answer, id=request_id, latency_ms=812)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Turn monitoring on and set the sample rate per project in the app (Monitoring > Setup); only
|
|
143
|
+
sampled records are evaluated.
|
|
144
|
+
|
|
145
|
+
## Library use
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from ai_eval import Client, evaluate_gate
|
|
149
|
+
|
|
150
|
+
c = Client()
|
|
151
|
+
job = c.evaluate_batch(dataset_id="...", outputs={"case-1": "..."}, project_id="...",
|
|
152
|
+
version={"label": "v2", "model": "claude-sonnet", "prompt": open("system.txt").read()})
|
|
153
|
+
results = c.wait_for_results(job["job_id"])
|
|
154
|
+
gate = evaluate_gate(results, {"pass_rate": 0.9}, {"factual_accuracy": 0.8})
|
|
155
|
+
print(gate.passed, gate.stats["pass_rate"])
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Links
|
|
159
|
+
|
|
160
|
+
- Docs: https://ai-evaluation-platform.com/docs
|
|
161
|
+
- Buy on AWS Marketplace: https://aws.amazon.com/marketplace/pp/prodview-qejr2yng5xgc6
|
|
162
|
+
- Support: hello@ai-evaluation-platform.com
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# ai-eval-platform (Python SDK + CLI)
|
|
2
|
+
|
|
3
|
+
Standard-library-only client for the AI Evaluation Platform API, plus an `ai-eval` command
|
|
4
|
+
that runs an evaluation and fails your CI build when quality drops.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install ai-eval-platform
|
|
8
|
+
export AI_EVAL_API_KEY=... # Settings > API keys in the app
|
|
9
|
+
export AI_EVAL_API_URL=https://api.ai-evaluation-platform.com
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Quality gate in CI
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# 1. Your pipeline runs your app over the dataset's prompts and writes outputs.json:
|
|
16
|
+
# {"case-1": "the app's answer", "case-2": "..."}
|
|
17
|
+
# 2. Evaluate and gate:
|
|
18
|
+
ai-eval run --project <project_id> --dataset <dataset_id> --outputs outputs.json \
|
|
19
|
+
--fail-under pass_rate=0.9 --metric factual_accuracy=0.8 --version-label "$GIT_SHA"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
- `--fail-under NAME=VALUE` (repeatable or comma-separated): `pass_rate` (share of cases
|
|
23
|
+
where every metric meets its pass mark), `good_rate` (share labelled Good), or a run
|
|
24
|
+
average: `overall`, `safety`, `truth`, `quality`.
|
|
25
|
+
- `--metric KEY=VALUE`: the run average of metric `KEY` must be at least `VALUE`; `VALUE`
|
|
26
|
+
is also that metric's pass mark for `pass_rate`. Other metrics use the project's
|
|
27
|
+
thresholds, else 0.70.
|
|
28
|
+
- Instead of a dataset: `--file cases.jsonl` (cases with `prompt`, `llm_output`, ...) or
|
|
29
|
+
`--file results.csv` (uploaded with the same column mapping as the app), or
|
|
30
|
+
`--job <job_id>` to gate a run that already exists.
|
|
31
|
+
- Exit code 0 = passed, 1 = gate failed, 2 = error (bad arguments, API error, timeout).
|
|
32
|
+
`--report-json gate.json` writes the numbers for later steps.
|
|
33
|
+
|
|
34
|
+
The run shows up in the app with its version label, so you can compare it with the
|
|
35
|
+
previous build's run on the same dataset version.
|
|
36
|
+
|
|
37
|
+
### GitHub Actions
|
|
38
|
+
|
|
39
|
+
The [AI Evaluation Platform quality gate](https://github.com/marketplace/actions/ai-evaluation-platform-quality-gate)
|
|
40
|
+
action wraps the CLI:
|
|
41
|
+
|
|
42
|
+
```yaml
|
|
43
|
+
- run: python scripts/generate_outputs.py > outputs.json # your app
|
|
44
|
+
- uses: assertthat/ai-eval-action@v1
|
|
45
|
+
with:
|
|
46
|
+
api-key: ${{ secrets.AI_EVAL_API_KEY }}
|
|
47
|
+
project: ${{ vars.AI_EVAL_PROJECT }}
|
|
48
|
+
dataset: ${{ vars.AI_EVAL_DATASET }}
|
|
49
|
+
outputs: outputs.json
|
|
50
|
+
fail-under: pass_rate=0.9
|
|
51
|
+
metric-thresholds: factual_accuracy=0.8
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Bitbucket Pipelines
|
|
55
|
+
|
|
56
|
+
With the pipe:
|
|
57
|
+
|
|
58
|
+
```yaml
|
|
59
|
+
- step:
|
|
60
|
+
name: LLM quality gate
|
|
61
|
+
script:
|
|
62
|
+
- python scripts/generate_outputs.py > outputs.json # your app
|
|
63
|
+
- pipe: docker://assertthat/ai-eval-pipe:1.0.0
|
|
64
|
+
variables:
|
|
65
|
+
AI_EVAL_API_KEY: $AI_EVAL_API_KEY
|
|
66
|
+
PROJECT: $AI_EVAL_PROJECT
|
|
67
|
+
DATASET: $AI_EVAL_DATASET
|
|
68
|
+
OUTPUTS: outputs.json
|
|
69
|
+
FAIL_UNDER: pass_rate=0.9
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Or with the CLI directly:
|
|
73
|
+
|
|
74
|
+
```yaml
|
|
75
|
+
- step:
|
|
76
|
+
name: LLM quality gate
|
|
77
|
+
image: python:3.12-slim
|
|
78
|
+
script:
|
|
79
|
+
- pip install ai-eval-platform
|
|
80
|
+
- python scripts/generate_outputs.py > outputs.json
|
|
81
|
+
- ai-eval run --project $AI_EVAL_PROJECT --dataset $AI_EVAL_DATASET --outputs outputs.json
|
|
82
|
+
--fail-under pass_rate=0.9 --version-label $BITBUCKET_COMMIT --run-name "$BITBUCKET_BRANCH"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
(Set `AI_EVAL_API_KEY` as a secured repository variable.)
|
|
86
|
+
|
|
87
|
+
## Tracing agents
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from ai_eval import Client
|
|
91
|
+
from ai_eval.tracing import Tracer
|
|
92
|
+
|
|
93
|
+
tracer = Tracer(Client(), project_id="...")
|
|
94
|
+
with tracer.trace("support-agent", session_id=conversation_id, input=question) as t:
|
|
95
|
+
with tracer.span("lookup_order", kind="tool", input={"id": 42}) as s:
|
|
96
|
+
s.output = lookup_order(42)
|
|
97
|
+
t.output = answer
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Or point any OpenTelemetry OTLP/HTTP exporter at `<api>/v1/traces` with the header
|
|
101
|
+
`X-API-Key` - see the [tracing docs](https://ai-evaluation-platform.com/docs#traces).
|
|
102
|
+
|
|
103
|
+
## Production monitoring
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from ai_eval.monitor import Monitor
|
|
107
|
+
|
|
108
|
+
monitor = Monitor(Client(), project_id="...") # sends in the background
|
|
109
|
+
monitor.log(prompt=question, llm_output=answer, id=request_id, latency_ms=812)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Turn monitoring on and set the sample rate per project in the app (Monitoring > Setup); only
|
|
113
|
+
sampled records are evaluated.
|
|
114
|
+
|
|
115
|
+
## Library use
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from ai_eval import Client, evaluate_gate
|
|
119
|
+
|
|
120
|
+
c = Client()
|
|
121
|
+
job = c.evaluate_batch(dataset_id="...", outputs={"case-1": "..."}, project_id="...",
|
|
122
|
+
version={"label": "v2", "model": "claude-sonnet", "prompt": open("system.txt").read()})
|
|
123
|
+
results = c.wait_for_results(job["job_id"])
|
|
124
|
+
gate = evaluate_gate(results, {"pass_rate": 0.9}, {"factual_accuracy": 0.8})
|
|
125
|
+
print(gate.passed, gate.stats["pass_rate"])
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Links
|
|
129
|
+
|
|
130
|
+
- Docs: https://ai-evaluation-platform.com/docs
|
|
131
|
+
- Buy on AWS Marketplace: https://aws.amazon.com/marketplace/pp/prodview-qejr2yng5xgc6
|
|
132
|
+
- Support: hello@ai-evaluation-platform.com
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""Python SDK and CLI for the AI Evaluation Platform."""
|
|
2
|
+
from ai_eval._version import __version__
|
|
3
|
+
from ai_eval.client import ApiError, Client
|
|
4
|
+
from ai_eval.gate import GateResult, evaluate_gate, run_stats
|
|
5
|
+
|
|
6
|
+
__all__ = ["ApiError", "Client", "GateResult", "evaluate_gate", "run_stats", "__version__"]
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""
|
|
2
|
+
`ai-eval` command line. Exit codes: 0 gate passed, 1 gate failed, 2 error.
|
|
3
|
+
|
|
4
|
+
ai-eval run --project P --dataset D --outputs outputs.json \
|
|
5
|
+
--fail-under pass_rate=0.9 --metric factual_accuracy=0.8
|
|
6
|
+
|
|
7
|
+
Credentials: AI_EVAL_API_KEY (or --api-key); API URL: AI_EVAL_API_URL (or --api-url).
|
|
8
|
+
"""
|
|
9
|
+
import argparse
|
|
10
|
+
import csv
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
from typing import Dict, List, Optional
|
|
15
|
+
|
|
16
|
+
from ai_eval._version import __version__
|
|
17
|
+
from ai_eval.client import ApiError, Client
|
|
18
|
+
from ai_eval.gate import GATE_NAMES, evaluate_gate, format_report, parse_conditions
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _load_json_or_jsonl(path: str):
|
|
22
|
+
with open(path, encoding="utf-8") as f:
|
|
23
|
+
text = f.read()
|
|
24
|
+
if path.endswith(".jsonl"):
|
|
25
|
+
return [json.loads(line) for line in text.splitlines() if line.strip()]
|
|
26
|
+
return json.loads(text)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def load_outputs(path: str) -> Dict[str, str]:
|
|
30
|
+
"""{case_id: output}, a JSON list of {case_id, llm_output}, JSONL of the same, or a CSV."""
|
|
31
|
+
if path.endswith(".csv"):
|
|
32
|
+
with open(path, encoding="utf-8-sig", newline="") as f:
|
|
33
|
+
rows = list(csv.DictReader(f))
|
|
34
|
+
else:
|
|
35
|
+
data = _load_json_or_jsonl(path)
|
|
36
|
+
if isinstance(data, dict):
|
|
37
|
+
return {str(k): str(v) for k, v in data.items()}
|
|
38
|
+
rows = data
|
|
39
|
+
out = {}
|
|
40
|
+
for r in rows:
|
|
41
|
+
cid = r.get("case_id") or r.get("id")
|
|
42
|
+
text = r.get("llm_output") or r.get("output") or r.get("response")
|
|
43
|
+
if cid is not None and text is not None:
|
|
44
|
+
out[str(cid)] = str(text)
|
|
45
|
+
return out
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def load_cases(path: str) -> List[dict]:
|
|
49
|
+
data = _load_json_or_jsonl(path)
|
|
50
|
+
cases = data.get("cases", data) if isinstance(data, dict) else data
|
|
51
|
+
for i, c in enumerate(cases, start=1):
|
|
52
|
+
c.setdefault("case_id", str(i))
|
|
53
|
+
c.setdefault("prompt", "")
|
|
54
|
+
return cases
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
58
|
+
p = argparse.ArgumentParser(prog="ai-eval", description="AI Evaluation Platform CLI")
|
|
59
|
+
p.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
60
|
+
p.add_argument("--api-key", default=None, help="Default: $AI_EVAL_API_KEY")
|
|
61
|
+
p.add_argument("--api-url", default=None, help="Default: $AI_EVAL_API_URL or the public API")
|
|
62
|
+
sub = p.add_subparsers(dest="command", required=True)
|
|
63
|
+
|
|
64
|
+
r = sub.add_parser("run", help="Evaluate a run and apply a quality gate")
|
|
65
|
+
src = r.add_mutually_exclusive_group(required=True)
|
|
66
|
+
src.add_argument("--dataset", help="Dataset id to evaluate")
|
|
67
|
+
src.add_argument("--file", help="Cases as .json/.jsonl (list of cases) or .csv/.xlsx (uploaded as-is)")
|
|
68
|
+
src.add_argument("--job", help="Skip submitting: gate an existing run by job id")
|
|
69
|
+
r.add_argument("--dataset-version", type=int, help="Default: the latest version")
|
|
70
|
+
r.add_argument("--outputs", help="Outputs for dataset rows: JSON {case_id: output}, JSONL or CSV")
|
|
71
|
+
r.add_argument("--project", help="Project id (its metrics and thresholds apply)")
|
|
72
|
+
r.add_argument("--metrics", help="Comma-separated metric keys (default: the project's metrics)")
|
|
73
|
+
r.add_argument("--run-name", default=os.environ.get("AI_EVAL_RUN_NAME"))
|
|
74
|
+
r.add_argument("--version-label", help="Version label recorded on the run, e.g. a git SHA")
|
|
75
|
+
r.add_argument("--version-model", help="Model behind this version")
|
|
76
|
+
r.add_argument("--version-prompt-file", help="File with the system prompt (hashed into the version)")
|
|
77
|
+
r.add_argument("--fail-under", action="append", default=[],
|
|
78
|
+
help=f"NAME=VALUE gate, NAME in {', '.join(GATE_NAMES)} (repeatable)")
|
|
79
|
+
r.add_argument("--metric", action="append", default=[],
|
|
80
|
+
help="KEY=VALUE: metric KEY must average >= VALUE (also its pass mark) (repeatable)")
|
|
81
|
+
r.add_argument("--timeout", type=float, default=1800, help="Seconds to wait for the run (default 1800)")
|
|
82
|
+
r.add_argument("--report-json", help="Write the gate result as JSON to this path")
|
|
83
|
+
return p
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def cmd_run(args, client: Client) -> int:
|
|
87
|
+
fail_under = parse_conditions(args.fail_under, GATE_NAMES)
|
|
88
|
+
metric_marks = parse_conditions(args.metric)
|
|
89
|
+
metrics = [m.strip() for m in args.metrics.split(",")] if args.metrics else None
|
|
90
|
+
if metrics is None and args.project:
|
|
91
|
+
metrics = client.get_project(args.project).get("metrics") or None
|
|
92
|
+
version = None
|
|
93
|
+
if args.version_label:
|
|
94
|
+
version = {"label": args.version_label, "model": args.version_model}
|
|
95
|
+
if args.version_prompt_file:
|
|
96
|
+
with open(args.version_prompt_file, encoding="utf-8") as f:
|
|
97
|
+
version["prompt"] = f.read()
|
|
98
|
+
version = {k: v for k, v in version.items() if v}
|
|
99
|
+
|
|
100
|
+
if args.job:
|
|
101
|
+
job_id = args.job
|
|
102
|
+
elif args.dataset:
|
|
103
|
+
outputs = load_outputs(args.outputs) if args.outputs else None
|
|
104
|
+
job_id = client.evaluate_batch(dataset_id=args.dataset, dataset_version=args.dataset_version,
|
|
105
|
+
outputs=outputs, metrics=metrics, project_id=args.project,
|
|
106
|
+
run_name=args.run_name, version=version)["job_id"]
|
|
107
|
+
elif args.file.endswith((".csv", ".xlsx", ".xls")):
|
|
108
|
+
job_id = client.evaluate_file(args.file, metrics=metrics, project_id=args.project,
|
|
109
|
+
run_name=args.run_name, version=version)["job_id"]
|
|
110
|
+
else:
|
|
111
|
+
job_id = client.evaluate_batch(load_cases(args.file), metrics=metrics, project_id=args.project,
|
|
112
|
+
run_name=args.run_name, version=version)["job_id"]
|
|
113
|
+
print(f"Run {job_id} submitted, waiting for results...", file=sys.stderr)
|
|
114
|
+
|
|
115
|
+
results = client.wait_for_results(job_id, timeout=args.timeout)
|
|
116
|
+
gate = evaluate_gate(results, fail_under, metric_marks)
|
|
117
|
+
print(format_report(gate, results.get("run")))
|
|
118
|
+
if args.report_json:
|
|
119
|
+
with open(args.report_json, "w", encoding="utf-8") as f:
|
|
120
|
+
json.dump({"job_id": job_id, "passed": gate.passed, "stats": gate.stats,
|
|
121
|
+
"checks": [{"name": c.name, "actual": c.actual, "required": c.required, "ok": c.ok}
|
|
122
|
+
for c in gate.checks]}, f, indent=2)
|
|
123
|
+
return 0 if gate.passed else 1
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def main(argv: Optional[List[str]] = None, client: Optional[Client] = None) -> int:
|
|
127
|
+
args = build_parser().parse_args(argv)
|
|
128
|
+
try:
|
|
129
|
+
client = client or Client(api_key=args.api_key, base_url=args.api_url)
|
|
130
|
+
if args.command == "run":
|
|
131
|
+
return cmd_run(args, client)
|
|
132
|
+
except (ValueError, ApiError, RuntimeError, TimeoutError, OSError) as e:
|
|
133
|
+
print(f"ai-eval: error: {e}", file=sys.stderr)
|
|
134
|
+
return 2
|
|
135
|
+
return 2
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
if __name__ == "__main__":
|
|
139
|
+
sys.exit(main())
|