Skip to content

Commit d339922

Browse files
author
xusenlin
committed
Fix internlm2 template
1 parent 8e7db29 commit d339922

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

api/adapter/template.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ class InternLM2Template(BaseTemplate):
757757
"- InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文."
758758
)
759759
stop = {
760-
"strings": ["</s>", "[UNUSED_TOKEN_145]"],
760+
"strings": ["</s>", "<|im_end|>"],
761761
}
762762

763763
def match(self, name) -> bool:
@@ -767,17 +767,17 @@ def match(self, name) -> bool:
767767
def template(self) -> str:
768768
return (
769769
"{% if messages[0]['role'] == 'system' %}"
770-
"{{ '<s>[UNUSED_TOKEN_146]' + 'system\\n' + messages[0]['content'] + '[UNUSED_TOKEN_145]' + '\\n' }}"
770+
"{{ '<s><|im_start|>' + 'system\\n' + messages[0]['content'] + '<|im_end|>' + '\\n' }}"
771771
"{% else %}"
772-
"{{ '<s>[UNUSED_TOKEN_146]' + 'system\\n' + system_prompt + '[UNUSED_TOKEN_145]' + '\\n' }}"
772+
"{{ '<s><|im_start|>' + 'system\\n' + system_prompt + '<|im_end|>' + '\\n' }}"
773773
"{% endif %}"
774774
"{% for message in messages %}"
775775
"{% if messages[0]['role'] != 'system' %}"
776-
"{{ '[UNUSED_TOKEN_146]' + message['role'] + '\\n' + message['content'] + '[UNUSED_TOKEN_145]' + '\\n' }}"
776+
"{{ '<|im_start|>' + message['role'] + '\\n' + message['content'] + '<|im_end|>' + '\\n' }}"
777777
"{% endif %}"
778778
"{% endfor %}"
779779
"{% if add_generation_prompt %}"
780-
"{{ '[UNUSED_TOKEN_146]assistant\\n' }}"
780+
"{{ '<|im_start|>assistant\\n' }}"
781781
"{% endif %}"
782782
)
783783

libs/langchain_llm/langchain_llm/adapters/template.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ class InternLM2Template(BaseTemplate):
757757
"- InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文."
758758
)
759759
stop = {
760-
"strings": ["</s>", "[UNUSED_TOKEN_145]"],
760+
"strings": ["</s>", "<|im_end|>"],
761761
}
762762

763763
def match(self, name) -> bool:
@@ -767,17 +767,17 @@ def match(self, name) -> bool:
767767
def template(self) -> str:
768768
return (
769769
"{% if messages[0]['role'] == 'system' %}"
770-
"{{ '<s>[UNUSED_TOKEN_146]' + 'system\\n' + messages[0]['content'] + '[UNUSED_TOKEN_145]' + '\\n' }}"
770+
"{{ '<s><|im_start|>' + 'system\\n' + messages[0]['content'] + '<|im_end|>' + '\\n' }}"
771771
"{% else %}"
772-
"{{ '<s>[UNUSED_TOKEN_146]' + 'system\\n' + system_prompt + '[UNUSED_TOKEN_145]' + '\\n' }}"
772+
"{{ '<s><|im_start|>' + 'system\\n' + system_prompt + '<|im_end|>' + '\\n' }}"
773773
"{% endif %}"
774774
"{% for message in messages %}"
775775
"{% if messages[0]['role'] != 'system' %}"
776-
"{{ '[UNUSED_TOKEN_146]' + message['role'] + '\\n' + message['content'] + '[UNUSED_TOKEN_145]' + '\\n' }}"
776+
"{{ '<|im_start|>' + message['role'] + '\\n' + message['content'] + '<|im_end|>' + '\\n' }}"
777777
"{% endif %}"
778778
"{% endfor %}"
779779
"{% if add_generation_prompt %}"
780-
"{{ '[UNUSED_TOKEN_146]assistant\\n' }}"
780+
"{{ '<|im_start|>assistant\\n' }}"
781781
"{% endif %}"
782782
)
783783

0 commit comments

Comments
 (0)