Skip to content

Commit

Permalink
Merge pull request #418 from devchat-ai/feat/toggle-public-workflow-u…
Browse files Browse the repository at this point in the history
…pdate

feat: Add toggle for public workflow updates
  • Loading branch information
kagami-l authored Oct 23, 2024
2 parents 37d6f09 + 94b62e1 commit 4037c03
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions devchat/_service/route/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,43 @@ def get_config():

@router.post("/update", response_model=response.UpdateWorkflows)
def update_workflows():
base_path = Path(WORKFLOWS_BASE)
chat_config_path = Path(CHAT_DIR) / CHAT_CONFIG_FILENAME

if HAS_GIT:
updated, message = update_by_git(base_path)
else:
updated, message = update_by_zip(base_path)
if chat_config_path.exists():
with open(chat_config_path, "r", encoding="utf-8") as file:
chat_config = yaml.safe_load(file)

providers = chat_config.get("providers", {})
devchat_api_key = providers.get("devchat", {}).get("api_key", "")
openai_api_key = providers.get("openai", {}).get("api_key", "")

if devchat_api_key or openai_api_key:
update_public_workflow = chat_config.get("update_public_workflow", True)

copy_workflows_usr()
if update_public_workflow:
base_path = Path(WORKFLOWS_BASE)

return response.UpdateWorkflows(updated=updated, message=message)
if HAS_GIT:
updated, message = update_by_git(base_path)
else:
updated, message = update_by_zip(base_path)

copy_workflows_usr()

return response.UpdateWorkflows(updated=updated, message=message)
else:
return response.UpdateWorkflows(
updated=False,
message="Workflow update has been ignored due to configuration settings.",
)
else:
return response.UpdateWorkflows(
updated=False, message="No valid API key found, workflow update ignored."
)
else:
return response.UpdateWorkflows(
updated=False, message="Configuration file not found, workflow update ignored."
)


@router.post("/custom_update", response_model=response.UpdateWorkflows)
Expand Down

0 comments on commit 4037c03

Please sign in to comment.