Skip to content

Commit 08060c8

Browse files
authored
feat: Add run-experiment GitHub action (#32)
1 parent e349387 commit 08060c8

3 files changed

Lines changed: 59 additions & 8 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: 'Run experiment'
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
dataset_name:
7+
description: 'Name of the Phoenix dataset to use'
8+
type: string
9+
required: true
10+
pipeline_name:
11+
description: 'Name of the pipeline to run'
12+
type: choice
13+
options:
14+
- 'generate-referrals'
15+
default: 'generate-referrals'
16+
required: true
17+
18+
jobs:
19+
experiment:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Run experiment
25+
shell: bash
26+
env:
27+
DEPLOYED_PHOENIX_URL: ${{ secrets.DEPLOYED_PHOENIX_URL }}
28+
DEPLOYED_PHOENIX_API_KEY: ${{ secrets.DEPLOYED_PHOENIX_API_KEY }}
29+
DEPLOYED_API_URL: ${{ secrets.DEPLOYED_API_URL }}
30+
run: |
31+
make run-experiment DATASET="${{ github.event.inputs.dataset_name }}" PIPELINE="${{ github.event.inputs.pipeline_name }}" ACTION="run_on_deployed"

app/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,4 @@ copy-prompts:
232232
$(PY_RUN_CMD) copy-prompts
233233

234234
run-experiment:
235-
$(PY_RUN_CMD) run-experiment "$(DATASET)" "$(ACTION)"
235+
$(PY_RUN_CMD) run-experiment "$(DATASET)" "$(PIPELINE)" "$(ACTION)"

app/src/experiments.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
from typing import Any, Dict
88

99
import requests
10+
from hayhooks import BasePipelineWrapper
1011
from phoenix.client import Client
1112
from phoenix.client.experiments import run_experiment
1213
from phoenix.client.resources.datasets import Dataset
1314
from phoenix.client.resources.experiments.types import TaskOutput
1415

1516
from src.common import phoenix_utils
16-
from src.pipelines.generate_referrals.pipeline_wrapper import PipelineWrapper
17+
from src.pipelines.generate_referrals.pipeline_wrapper import (
18+
PipelineWrapper as GenerateReferralsPipeline,
19+
)
1720

1821
logger = logging.getLogger(__name__)
1922

@@ -53,10 +56,21 @@ def precision(output: TaskOutput, expected: Dict[str, Any]) -> float:
5356
logger.info("Using deployed API at %s", url_base)
5457

5558

59+
PIPELINES = {
60+
"generate-referrals": {
61+
"pipeline_class": GenerateReferralsPipeline,
62+
"url_path": "generate_referrals/run",
63+
},
64+
}
65+
pipeline_name = "generate-referrals"
66+
67+
5668
@functools.lru_cache
57-
def create_pipeline() -> PipelineWrapper:
58-
logger.info("Creating local Haystack pipeline")
59-
pipeline_wrapper = PipelineWrapper()
69+
def create_pipeline() -> BasePipelineWrapper:
70+
logger.info("Creating local Haystack pipeline %r", pipeline_name)
71+
pipeline_class = PIPELINES[pipeline_name]["pipeline_class"]
72+
assert isinstance(pipeline_class, type), f"Expected a class but got {type(pipeline_class)}"
73+
pipeline_wrapper = pipeline_class()
6074
pipeline_wrapper.setup()
6175
return pipeline_wrapper
6276

@@ -83,7 +97,7 @@ def query_api(example: dict) -> TaskOutput:
8397

8498
assert url_base, "DEPLOYED_API_URL is not set -- add it to override.env"
8599
response = requests.post(
86-
f"{url_base}/generate_referrals/run",
100+
f"{url_base}/{PIPELINES[pipeline_name]['url_path']}",
87101
headers={
88102
"accept": "application/json",
89103
"Content-Type": "application/json",
@@ -160,7 +174,8 @@ def main() -> None:
160174
logging.basicConfig(format="%(levelname)s - %(name)s - %(message)s", level=logging.INFO)
161175

162176
parser = argparse.ArgumentParser()
163-
parser.add_argument("dataset", type=str, default="brandon2")
177+
parser.add_argument("dataset", type=str)
178+
parser.add_argument("pipeline", type=str, default="generate_referrals")
164179
parser.add_argument(
165180
"action",
166181
type=str,
@@ -169,7 +184,12 @@ def main() -> None:
169184
)
170185
args = parser.parse_args()
171186

172-
logger.info("Action=%s Dataset=%r", args.action, args.dataset)
187+
logger.info("Action=%s Pipeline=%r Dataset=%r", args.action, args.pipeline, args.dataset)
188+
assert (
189+
args.pipeline in PIPELINES
190+
), f"Unknown pipeline {args.pipeline}. Available: {list(PIPELINES.keys())}"
191+
global pipeline_name
192+
pipeline_name = args.pipeline
173193

174194
if args.action == "export":
175195
client_to_deployed_phx = phoenix_utils.client_to_deployed_phoenix()

0 commit comments

Comments
 (0)