35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
"""general_fc: simple function-calling demo set (native to evalscope, its official home)."""
|
|
|
|
import json
|
|
|
|
from ..sample import ChatMessage, Sample, ToolInfo
|
|
from ..registry import register_dataset
|
|
from ..spec import DatasetSpec
|
|
|
|
|
|
@register_dataset(
|
|
DatasetSpec(
|
|
name='general_fc',
|
|
source='evalscope/GeneralFunctionCall-Test', # evalscope-native release (ModelScope)
|
|
split='test',
|
|
task_type='fc',
|
|
tags=['function_calling'],
|
|
description='Minimal function-calling test set (evalscope-native).',
|
|
params={'hub': 'modelscope'},
|
|
)
|
|
)
|
|
def general_fc():
|
|
def to_sample(record: dict) -> Sample:
|
|
messages = json.loads(record['messages']) if isinstance(record['messages'], str) else record['messages']
|
|
tools = json.loads(record['tools']) if isinstance(record['tools'], str) else record.get('tools')
|
|
chat = [ChatMessage(role=m.get('role', 'user'), content=m['content'] if isinstance(m.get('content'), str)
|
|
else json.dumps(m['content'], ensure_ascii=False)) for m in messages]
|
|
return Sample(
|
|
input=chat,
|
|
target=str(record.get('should_call_tool', '')),
|
|
tools=[ToolInfo(**t['function']) if isinstance(t, dict) and 'function' in t else ToolInfo(name=str(t))
|
|
for t in (tools or [])] or None,
|
|
)
|
|
|
|
return to_sample
|