r"""Construct tool descriptions from function definitions and descriptions.
(dataset_name: str)
| 362 | |
| 363 | # Utility functions |
| 364 | def construct_tool_descriptions(dataset_name: str) -> str: |
| 365 | r"""Construct tool descriptions from function definitions and |
| 366 | descriptions.""" |
| 367 | tool_dataset_mapping = { |
| 368 | "NVDLibrary": "CVECPE", |
| 369 | "VirusTotal": "VirusTotal", |
| 370 | "PlacesAPI": "Places", |
| 371 | "ClimateAPI": "Climate", |
| 372 | "OTX": "OTX", |
| 373 | "VirusTotal-NestedCalls": "VT_Multi (Nested)", |
| 374 | "VirusTotal-ParallelCalls": "VT_Multi (Parallel)", |
| 375 | "NVDLibrary-NestedCalls": "CVECPE_Multi (Nested)", |
| 376 | } |
| 377 | |
| 378 | if dataset_name not in tool_dataset_mapping: |
| 379 | raise ValueError( |
| 380 | f"Dataset '{dataset_name}' is not recognized. " |
| 381 | f"Available datasets: {list(dataset_mapping.keys())}" |
| 382 | ) |
| 383 | |
| 384 | # Load the dataset based on the dataset name |
| 385 | dataset = load_dataset( |
| 386 | "Nexusflow/Function_Call_Definitions", |
| 387 | name=tool_dataset_mapping[dataset_name], |
| 388 | )["train"] |
| 389 | |
| 390 | # Construct tool descriptions |
| 391 | tools = [ |
| 392 | NexusTool(tool["function_calls"], tool["descriptions"]) |
| 393 | for tool in dataset |
| 394 | ] |
| 395 | |
| 396 | # Generate the tool prompt |
| 397 | tool_prompt = "".join( |
| 398 | f"Function:\ndef {tool.function_calls}:\n" |
| 399 | + "\"\"\"\n" |
| 400 | + f"{tool.descriptions}\n" |
| 401 | + "\"\"\"\n" |
| 402 | for tool in tools |
| 403 | ) |
| 404 | |
| 405 | return tool_prompt |
| 406 | |
| 407 | |
| 408 | def construct_prompt(input: str, tools: str) -> str: |