Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit 2fcbf91

Browse files
authored
fix: prevent duplicating template with same name (#245)
1 parent 6c9a488 commit 2fcbf91

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/genai/prompt_pattern.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def from_watsonx(
8888
name: str = None,
8989
template: str = None,
9090
id: str = None,
91+
*,
92+
allow_duplicate: bool = False,
9193
):
9294
# Cases :
9395
# fetching an existing template : name OR id
@@ -105,7 +107,10 @@ def from_watsonx(
105107
id = saved_template.id
106108
name = name if name else saved_template.name
107109
wx = PromptTemplateManager.update_template(credentials=credentials, id=id, name=name, template=template)
108-
except Exception:
110+
except Exception as e:
111+
if "More than one template found" in str(e) and not allow_duplicate:
112+
raise e
113+
109114
# Template with name doesn't exist. Save template
110115
wx = PromptTemplateManager.save_template(template=template, name=name, credentials=credentials)
111116

0 commit comments

Comments
 (0)