format spaces in build_server_utils.py
This commit is contained in:
@@ -18,9 +18,10 @@ def opt_to_config(save_path: str, *nargs):
|
|||||||
cwd=_PROJECT_ROOT,
|
cwd=_PROJECT_ROOT,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _build_and_load_pipeline_config(pipeline_id: str,
|
|
||||||
pipeline_config_dir: str,
|
def _build_and_load_pipeline_config(
|
||||||
cmd: List[str]):
|
pipeline_id: str, pipeline_config_dir: str, cmd: List[str]
|
||||||
|
):
|
||||||
save_config_f = osp.join(pipeline_config_dir, f"{pipeline_id}.yml")
|
save_config_f = osp.join(pipeline_config_dir, f"{pipeline_id}.yml")
|
||||||
opt_to_config(save_config_f, *cmd)
|
opt_to_config(save_config_f, *cmd)
|
||||||
|
|
||||||
@@ -28,53 +29,55 @@ def _build_and_load_pipeline_config(pipeline_id: str,
|
|||||||
return load_tyro_conf(save_config_f)
|
return load_tyro_conf(save_config_f)
|
||||||
|
|
||||||
|
|
||||||
def update_pipeline_registry(pipeline_id:str, # the agent name -- xiaozhan, blueberry
|
def update_pipeline_registry(
|
||||||
prompt_set:str, # the version of the prompt for xiaozhan/blueberry
|
pipeline_id: str,
|
||||||
graph_id: str, # what type of graph is this pipeline.
|
graph_id: str,
|
||||||
config_file: str,
|
config_file: str,
|
||||||
llm_name: str,
|
llm_name: str,
|
||||||
enabled: bool = True,
|
enabled: bool = True,
|
||||||
registry_f:str="configs/pipeline_registry.json"):
|
registry_f: str = "configs/pipeline_registry.json",
|
||||||
|
):
|
||||||
if not osp.isabs(registry_f):
|
if not osp.isabs(registry_f):
|
||||||
registry_f = osp.join(_PROJECT_ROOT, registry_f)
|
registry_f = osp.join(_PROJECT_ROOT, registry_f)
|
||||||
os.makedirs(osp.dirname(registry_f), exist_ok=True)
|
os.makedirs(osp.dirname(registry_f), exist_ok=True)
|
||||||
if not osp.exists(registry_f):
|
if not osp.exists(registry_f):
|
||||||
with open(registry_f, "w", encoding="utf-8") as f:
|
with open(registry_f, "w", encoding="utf-8") as f:
|
||||||
json.dump({"routes": {}, "api_keys": {}}, f, indent=4)
|
json.dump({"pipelines": {}, "api_keys": {}}, f, indent=4)
|
||||||
|
|
||||||
with open(registry_f, "r") as f:
|
with open(registry_f, "r") as f:
|
||||||
registry = json.load(f)
|
registry = json.load(f)
|
||||||
|
|
||||||
routes: Dict[str, Dict[str, Any]] = registry.setdefault("routes", {})
|
pipelines: Dict[str, Dict[str, Any]] = registry.setdefault("pipelines", {})
|
||||||
route = routes.setdefault(pipeline_id, {})
|
pipeline = pipelines.setdefault(pipeline_id, {})
|
||||||
route["enabled"] = bool(enabled)
|
pipeline["enabled"] = bool(enabled)
|
||||||
route["config_file"] = config_file
|
pipeline["config_file"] = config_file
|
||||||
route["prompt_pipeline_id"] = prompt_set
|
pipeline["graph_id"] = graph_id
|
||||||
route["graph_id"] = graph_id
|
pipeline["overrides"] = {"llm_name": llm_name}
|
||||||
route["overrides"] = {"llm_name": llm_name}
|
|
||||||
|
|
||||||
with open(registry_f, "w", encoding="utf-8") as f:
|
with open(registry_f, "w", encoding="utf-8") as f:
|
||||||
json.dump(registry, f, indent=4)
|
json.dump(registry, f, indent=4)
|
||||||
|
|
||||||
|
|
||||||
def build_route(pipeline_id:str,
|
def build_route(
|
||||||
prompt_set:str,
|
pipeline_id: str,
|
||||||
tool_keys:List[str],
|
prompt_set: str,
|
||||||
api_key: str,
|
tool_keys: List[str],
|
||||||
llm_name:str="qwen-plus",
|
api_key: str,
|
||||||
pipeline_config_dir="configs/pipelines"):
|
llm_name: str = "qwen-plus",
|
||||||
|
pipeline_config_dir="configs/pipelines",
|
||||||
|
):
|
||||||
cmd_opt = [
|
cmd_opt = [
|
||||||
"route", # ------------
|
"route", # ------------
|
||||||
"--llm-name", llm_name,
|
"--llm-name", llm_name,
|
||||||
"--api-key", api_key,
|
"--api-key", api_key,
|
||||||
"--pipeline-id", pipeline_id,
|
"--pipeline-id", pipeline_id,
|
||||||
"--prompt-set-id", prompt_set,
|
"--prompt-set-id", prompt_set,
|
||||||
"tool_node", # ------------
|
"tool_node", # ------------
|
||||||
"--llm-name", llm_name,
|
"--llm-name", llm_name,
|
||||||
"--api-key", api_key,
|
"--api-key", api_key,
|
||||||
"--pipeline-id", pipeline_id,
|
"--pipeline-id", pipeline_id,
|
||||||
"--prompt-set-id", prompt_set,
|
"--prompt-set-id", prompt_set,
|
||||||
]
|
]
|
||||||
|
|
||||||
if tool_keys:
|
if tool_keys:
|
||||||
cmd_opt.extend(
|
cmd_opt.extend(
|
||||||
@@ -84,14 +87,16 @@ def build_route(pipeline_id:str,
|
|||||||
return _build_and_load_pipeline_config(pipeline_id, pipeline_config_dir, cmd_opt)
|
return _build_and_load_pipeline_config(pipeline_id, pipeline_config_dir, cmd_opt)
|
||||||
|
|
||||||
|
|
||||||
def build_react(pipeline_id:str,
|
def build_react(
|
||||||
prompt_set:str,
|
pipeline_id: str,
|
||||||
tool_keys:List[str],
|
prompt_set: str,
|
||||||
api_key: str,
|
tool_keys: List[str],
|
||||||
llm_name:str="qwen-plus",
|
api_key: str,
|
||||||
pipeline_config_dir="configs/pipelines"):
|
llm_name: str = "qwen-plus",
|
||||||
|
pipeline_config_dir="configs/pipelines",
|
||||||
|
):
|
||||||
cmd_opt = [
|
cmd_opt = [
|
||||||
"react", # ------------
|
"react", # ------------
|
||||||
"--llm-name", llm_name,
|
"--llm-name", llm_name,
|
||||||
"--api-key", api_key,
|
"--api-key", api_key,
|
||||||
"--pipeline-id", pipeline_id,
|
"--pipeline-id", pipeline_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user