[data] allow thought in function call (#6797)

* Update template.py

* Update template.py

* use formatter

* fix regex

---------

Co-authored-by: hiyouga <hiyouga@buaa.edu.cn>
Former-commit-id: a5e943f7bcea6e5840da8570055bf3079a49ae8c
This commit is contained in:
Yueqi Song 2025-02-05 02:26:23 +08:00 committed by GitHub
parent 1fee69f874
commit e665e1fed5

View File

@ -99,6 +99,11 @@ class FunctionFormatter(Formatter):
@override
def apply(self, **kwargs) -> SLOTS:
content = kwargs.pop("content")
regex = re.compile(r"<think>(.*)</think>", re.DOTALL)
thought = re.search(regex, content)
if thought:
content = content.replace(thought.group(0), "")
functions: List["FunctionCall"] = []
try:
tool_calls = json.loads(content)
@ -116,6 +121,9 @@ class FunctionFormatter(Formatter):
elements = []
for slot in self.slots:
if slot == "{{content}}":
if thought:
elements.append(thought.group(1))
elements += self.tool_utils.function_formatter(functions)
else:
elements.append(slot)