Files
AL1-model-B/mlb/tools_common.py

47 lines
1.9 KiB
Python
Raw Permalink Normal View History

import re, json
TOOLS = [
{"type": "function", "function": {
"name": "read_file",
"description": "Read and return the contents of a file.",
"parameters": {"type": "object",
"properties": {"path": {"type": "string", "description": "File path to read."}},
"required": ["path"]}}},
{"type": "function", "function": {
"name": "write_file",
"description": "Create or overwrite a file with the given content.",
"parameters": {"type": "object",
"properties": {"path": {"type": "string"}, "content": {"type": "string"}},
"required": ["path", "content"]}}},
{"type": "function", "function": {
"name": "edit_file",
"description": "Replace an exact substring in a file with new text.",
"parameters": {"type": "object",
"properties": {"path": {"type": "string"},
"old_string": {"type": "string"},
"new_string": {"type": "string"}},
"required": ["path", "old_string", "new_string"]}}},
{"type": "function", "function": {
"name": "list_dir",
"description": "List the entries in a directory.",
"parameters": {"type": "object",
"properties": {"path": {"type": "string"}},
"required": ["path"]}}},
{"type": "function", "function": {
"name": "run_bash",
"description": "Run a shell command and return its output.",
"parameters": {"type": "object",
"properties": {"command": {"type": "string"}},
"required": ["command"]}}},
]
_TOOLCALL_RE = re.compile(r"<tool_call>\s*(\{.*?\})\s*</tool_call>", re.DOTALL)
def parse_tool_calls(text):
calls = []
for m in _TOOLCALL_RE.findall(text):
try:
calls.append(json.loads(m))
except json.JSONDecodeError:
pass
return calls