diff --git a/lang_agent/front_api/build_server_utils.py b/lang_agent/front_api/build_server_utils.py index 05314f3..0897c9a 100644 --- a/lang_agent/front_api/build_server_utils.py +++ b/lang_agent/front_api/build_server_utils.py @@ -11,6 +11,16 @@ def opt_to_config(save_path:str, *nargs): subprocess.run(["python", "--save-path", save_path, *nargs]) +def _build_and_load_pipeline_config(pipeline_id: str, + pipeline_config_dir: str, + cmd: List[str]): + save_config_f = osp.join(pipeline_config_dir, f"{pipeline_id}.yml") + opt_to_config(save_config_f, *cmd) + + # TODO: think if returning the built pipeline is better or just the config obj for front_api + return load_tyro_conf(save_config_f) + + def update_pipeline_registry(pipeline_id:str, prompt_set:str, registry_f:str="configs/pipeline_registry.json"): @@ -30,40 +40,6 @@ def update_pipeline_registry(pipeline_id:str, json.dump(registry, f, indent=4) - -# def build_route(pipeline_id:str, -# prompt_set:str, -# tool_keys:List[str], -# port:str, -# api_key: str, -# fast_auth_keys: Optional[str] = None, -# entry_pnt:str="fastapi_server/server_dashscope.py", -# llm_name:str="qwen-plus"): -# cmd = [ -# "python", entry_pnt, -# "--port", str(port), -# "route", # ------------ -# "--llm-name", llm_name, -# "--api-key", api_key, -# "--pipeline-id", pipeline_id, -# "--prompt-set-id", prompt_set, -# "tool_node", # ------------ -# "--llm-name", llm_name, -# "--api-key", api_key, -# "--pipeline-id", pipeline_id, -# "--prompt-set-id", prompt_set, -# ] -# if tool_keys: -# cmd.extend( -# ["--tool-manager-config.client-tool-manager.tool-keys", *tool_keys] -# ) -# env: Dict[str, str] = os.environ.copy() -# if fast_auth_keys: -# env["FAST_AUTH_KEYS"] = fast_auth_keys -# sv_prc = subprocess.Popen(cmd, env=env) - -# return sv_prc, f"http://127.0.0.1:{port}/api/" - def build_route(pipeline_id:str, prompt_set:str, tool_keys:List[str], @@ -90,26 +66,18 @@ def build_route(pipeline_id:str, ["--tool-manager-config.client-tool-manager.tool-keys", *tool_keys] ) - save_config_f = osp.join(pipeline_config_dir, f"{pipeline_id}.yml") - opt_to_config(save_config_f, *cmd) - - # TODO: think if returning the built pipeline is better or just the config obj for front_api - return load_tyro_conf(save_config_f) - - + return _build_and_load_pipeline_config(pipeline_id, pipeline_config_dir, cmd) def build_react(pipeline_id:str, prompt_set:str, tool_keys:List[str], - port:str, api_key: str, - fast_auth_keys: Optional[str] = None, entry_pnt:str="fastapi_server/server_dashscope.py", - llm_name:str="qwen-plus"): + llm_name:str="qwen-plus", + pipeline_config_dir="configs/pipelines"): cmd = [ "python", entry_pnt, - "--port", str(port), "react", # ------------ "--llm-name", llm_name, "--api-key", api_key, @@ -120,12 +88,9 @@ def build_react(pipeline_id:str, cmd.extend( ["--tool-manager-config.client-tool-manager.tool-keys", *tool_keys] ) - env: Dict[str, str] = os.environ.copy() - if fast_auth_keys: - env["FAST_AUTH_KEYS"] = fast_auth_keys - sv_prc = subprocess.Popen(cmd, env=env) - return sv_prc, f"http://127.0.0.1:{port}/api/" + return _build_and_load_pipeline_config(pipeline_id, pipeline_config_dir, cmd) + # {pipeline_id: build_function} GRAPH_BUILD_FNCS = {