77from typing import Any , Dict
88
99import requests
10+ from hayhooks import BasePipelineWrapper
1011from phoenix .client import Client
1112from phoenix .client .experiments import run_experiment
1213from phoenix .client .resources .datasets import Dataset
1314from phoenix .client .resources .experiments .types import TaskOutput
1415
1516from 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
1821logger = 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