Skip to content

Commit ab4d9e1

Browse files
committed
Chat example Granite3 template
1 parent ebfefc4 commit ab4d9e1

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

examples/chat_prompts.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,42 @@ def print_extra_newline(self):
547547
return True
548548

549549

550+
class PromptFormat_granite3(PromptFormat):
551+
description = "Granite 3"
552+
553+
def __init__(self):
554+
super().__init__()
555+
pass
556+
557+
def default_system_prompt(self):
558+
return "You are Granite, developed by IBM. You are a helpful AI assistant."
559+
560+
def first_prompt(self, sysprompt):
561+
r = ""
562+
if sysprompt:
563+
r += """<|start_of_role|>system<|end_of_role|>|system_prompt|><|end_of_text|>"""
564+
r += """<|start_of_role|>user<|end_of_role|><|user_prompt|><|end_of_text|>"""
565+
r += """<|start_of_role|>assistant<|end_of_role|>"""
566+
return r
567+
568+
def subs_prompt(self):
569+
r = ""
570+
r += """<|start_of_role|>user<|end_of_role|><|user_prompt|><|end_of_text|>"""
571+
r += """<|start_of_role|>assistant<|end_of_role|>"""
572+
return r
573+
574+
def stop_conditions(self, tokenizer):
575+
return [
576+
tokenizer.eos_token_id,
577+
]
578+
579+
def encoding_options(self):
580+
return True, False, True
581+
582+
def print_extra_newline(self):
583+
return True
584+
585+
550586
class PromptFormat_cohere(PromptFormat):
551587
description = "Cohere"
552588

@@ -610,4 +646,5 @@ def print_extra_newline(self):
610646
"cohere": PromptFormat_cohere,
611647
"phi3": PromptFormat_phi3,
612648
"granite": PromptFormat_granite,
649+
"granite3": PromptFormat_granite3,
613650
}

0 commit comments

Comments
 (0)