Skip to content

Commit

Permalink
fix: prevent duplicating template with same name (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas2D committed Dec 20, 2023
1 parent 6c9a488 commit 2fcbf91
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/genai/prompt_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def from_watsonx(
name: str = None,
template: str = None,
id: str = None,
*,
allow_duplicate: bool = False,
):
# Cases :
# fetching an existing template : name OR id
Expand All @@ -105,7 +107,10 @@ def from_watsonx(
id = saved_template.id
name = name if name else saved_template.name
wx = PromptTemplateManager.update_template(credentials=credentials, id=id, name=name, template=template)
except Exception:
except Exception as e:
if "More than one template found" in str(e) and not allow_duplicate:
raise e

# Template with name doesn't exist. Save template
wx = PromptTemplateManager.save_template(template=template, name=name, credentials=credentials)

Expand Down

0 comments on commit 2fcbf91

Please sign in to comment.