初始化项目,由ModelHub XC社区提供模型
Model: karthik-2905/AL1-model-B Source: Original Platform
This commit is contained in:
47
mlb/tools_common.py
Normal file
47
mlb/tools_common.py
Normal file
@@ -0,0 +1,47 @@
|
||||
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
|
||||
Reference in New Issue
Block a user