From 9feb78e7b42ae23ffc02b2a32bf939908ad5b103 Mon Sep 17 00:00:00 2001 From: Yueqi Song <141804823+yueqis@users.noreply.github.com> Date: Wed, 5 Feb 2025 02:26:23 +0800 Subject: [PATCH] [data] allow thought in function call (#6797) * Update template.py * Update template.py * use formatter * fix regex --------- Co-authored-by: hiyouga Former-commit-id: 3a31af6e920683ec074da93b1719e29f5d4cffd6 --- src/llamafactory/data/formatter.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/llamafactory/data/formatter.py b/src/llamafactory/data/formatter.py index ac558770..ed83a2d2 100644 --- a/src/llamafactory/data/formatter.py +++ b/src/llamafactory/data/formatter.py @@ -99,6 +99,11 @@ class FunctionFormatter(Formatter): @override def apply(self, **kwargs) -> SLOTS: content = kwargs.pop("content") + regex = re.compile(r"(.*)", 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)