diff --git a/src/genai/prompt_pattern.py b/src/genai/prompt_pattern.py index cdb4d919..07d2618d 100644 --- a/src/genai/prompt_pattern.py +++ b/src/genai/prompt_pattern.py @@ -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 @@ -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)