mirror of
https://github.com/hiyouga/LLaMA-Factory.git
synced 2025-10-16 00:28:10 +08:00
[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: 3a31af6e920683ec074da93b1719e29f5d4cffd6
This commit is contained in:
parent
c2022431aa
commit
9feb78e7b4
@ -99,6 +99,11 @@ class FunctionFormatter(Formatter):
|
|||||||
@override
|
@override
|
||||||
def apply(self, **kwargs) -> SLOTS:
|
def apply(self, **kwargs) -> SLOTS:
|
||||||
content = kwargs.pop("content")
|
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"] = []
|
functions: List["FunctionCall"] = []
|
||||||
try:
|
try:
|
||||||
tool_calls = json.loads(content)
|
tool_calls = json.loads(content)
|
||||||
@ -116,6 +121,9 @@ class FunctionFormatter(Formatter):
|
|||||||
elements = []
|
elements = []
|
||||||
for slot in self.slots:
|
for slot in self.slots:
|
||||||
if slot == "{{content}}":
|
if slot == "{{content}}":
|
||||||
|
if thought:
|
||||||
|
elements.append(thought.group(1))
|
||||||
|
|
||||||
elements += self.tool_utils.function_formatter(functions)
|
elements += self.tool_utils.function_formatter(functions)
|
||||||
else:
|
else:
|
||||||
elements.append(slot)
|
elements.append(slot)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user