Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python support #36

Merged
merged 7 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/eval-py.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Run Python evals

on:
push:
# files:
# - 'test-eval/**'

permissions:
pull-requests: write
contents: read

jobs:
eval:
name: Run Python evals
runs-on: ubuntu-latest

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: "recursive"

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12" # TODO: Matrix test different versions

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r test-eval-py/requirements.txt

- name: Run Evals
uses: ./
with:
api_key: ${{ secrets.BRAINTRUST_API_KEY }}
root: test-eval-py
runtime: python # Assuming the action supports a 'python' runtime


# - name: Start terminal session
# uses: mxschmitt/action-tmate@v3
# with:
# limit-access-to-actor: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ __tests__/runner/*
*.code-workspace

.turbo
__pycache__
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ jobs:
root: my_eval_dir
```

> [!IMPORTANT]
> You must specify `permissions` for the action to leave comments on your PR.
> Without these permissions, you'll see Github API errors.
> [!IMPORTANT] You must specify `permissions` for the action to leave comments
> on your PR. Without these permissions, you'll see Github API errors.

To see examples of fully configured templates, see the `examples` directory:

- [`node with npm`](examples/npm.yml)
- [`node with pnpm`](examples/pnpm.yml)
- [`python`](examples/python.yml)

## How it works

Expand Down
4 changes: 2 additions & 2 deletions eval/dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions eval/dist/index.js.map

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion eval/src/braintrust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ export async function runEval(args: Params, onSummary: OnSummaryFn) {
// Change working directory
process.chdir(path.resolve(root));

const command = `npx braintrust eval --jsonl ${paths}`;
let command: string;
switch (args.runtime) {
case "node":
command = `npx braintrust eval --jsonl ${paths}`;
break;
case "python":
command = `braintrust eval --jsonl ${paths}`;
break;
default:
throw new Error(`Unsupported runtime: ${args.runtime}`);
}
await runCommand(command, onSummary);
}
3 changes: 0 additions & 3 deletions eval/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ async function main(): Promise<void> {
`Invalid arguments: ${args.error.errors.map(e => e.message).join("\n")}`,
);
}
if (args.data.runtime !== "node") {
throw new Error("Only Node.js runtime is supported");
}

await upsertComment(`${TITLE}Evals in progress... ⌛`);

Expand Down
41 changes: 41 additions & 0 deletions examples/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Run Python evals

on:
push:
# Uncomment to run only when files in the 'evals' directory change
# - paths:
# - "evals/**"

permissions:
pull-requests: write
contents: read

jobs:
eval:
name: Run evals
runs-on: ubuntu-latest

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12" # Replace with your Python version

# Tweak this to a dependency manager of your choice
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r test-eval-py/requirements.txt

- name: Run Evals
uses: ./
with:
api_key: ${{ secrets.BRAINTRUST_API_KEY }}
runtime: python
root: my_eval_dir
1 change: 1 addition & 0 deletions test-eval-py/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
1 change: 0 additions & 1 deletion test-eval-py/eval_trivial.py

This file was deleted.

19 changes: 19 additions & 0 deletions test-eval-py/eval_tutorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from braintrust import Eval

from autoevals import Levenshtein

Eval(
"Say Hi Bot Python", # Replace with your project name
data=lambda: [
{
"input": "Foo",
"expected": "Hi Foo",
},
{
"input": "Bar",
"expected": "Hello Bar",
},
], # Replace with your eval dataset
task=lambda input: "Hi " + input, # Replace with your LLM call
scores=[Levenshtein],
)
10 changes: 10 additions & 0 deletions test-eval-py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
name = "test-eval-py"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"autoevals>=0.0.92",
"braintrust>=0.0.160",
]
24 changes: 24 additions & 0 deletions test-eval-py/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
attrs==24.2.0
autoevals==0.0.92
braintrust==0.0.160
braintrust-core==0.0.54
certifi==2024.8.30
charset-normalizer==3.3.2
chevron==0.14.0
exceptiongroup==1.2.0
gitdb==4.0.11
gitpython==3.1.43
idna==3.10
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
levenshtein==0.26.0
python-dotenv==1.0.1
pyyaml==6.0.2
rapidfuzz==3.10.0
referencing==0.35.1
requests==2.32.3
rpds-py==0.20.0
smmap==5.0.1
sseclient-py==1.8.0
tqdm==4.66.5
urllib3==2.2.3
Loading
Loading