-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscover_tools.py
More file actions
68 lines (56 loc) · 2.66 KB
/
Copy pathdiscover_tools.py
File metadata and controls
68 lines (56 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
import json
from pathlib import Path
import sys
from utils.config_loader import load_config
from utils.conversation_parser import find_log_files
def discover_tools(log_files):
"""Scans log files to discover all unique tool names used."""
unique_tool_names = set()
total_files = len(log_files)
print(f"Found {total_files} log files to scan.")
for i, log_file in enumerate(log_files):
if (i + 1) % 10 == 0 or i == total_files - 1:
print(f"Scanning file {i + 1}/{total_files}...")
with open(log_file, 'r', encoding='utf-8', errors='ignore') as f:
for line in f:
try:
turn = json.loads(line)
if turn.get('type') == 'assistant':
content_list = turn.get('message', {}).get('content', [])
if isinstance(content_list, list):
for item in content_list:
if item.get('type') == 'tool_use':
tool_name = item.get('name')
if tool_name:
unique_tool_names.add(tool_name)
except (json.JSONDecodeError, AttributeError):
# Ignore lines that are not valid JSON or don't have the expected structure
continue
return unique_tool_names
def main():
"""Main function to run the discovery process."""
config = load_config()
io_settings = config.get('io_settings', {})
input_dirs_conf = io_settings.get('input_log_directories')
if not input_dirs_conf:
print("Error: 'input_log_directories' not specified in config.yml.")
sys.exit(1)
input_dirs = [input_dirs_conf] if isinstance(input_dirs_conf, str) else input_dirs_conf
exclude_patterns = io_settings.get('exclude_patterns', [])
exclude_files = io_settings.get('exclude_files', [])
print(f"Searching for .jsonl log files in {len(input_dirs)} directory(ies)...")
log_files = find_log_files(input_dirs, exclude_patterns, exclude_files)
if not log_files:
print("No log files found in the specified directory.")
return
discovered_tools = sorted(list(discover_tools(log_files)))
print("\n--- Discovery Complete ---")
print(f"Total .jsonl files found: {len(log_files)}")
print("Unique tool names discovered across all logs:")
for tool in discovered_tools:
print(f"- {tool}")
print("--------------------------\n")
print("Please review this list and update 'tool_mapping.yml' to ensure all tools are accounted for.")
if __name__ == "__main__":
main()