mini-code-cli 0.0.6__tar.gz → 0.0.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/PKG-INFO +1 -1
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/mini_code_cli/agent_loop.py +64 -44
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/mini_code_cli/prompts.py +15 -7
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/mini_code_cli/tools.py +1 -1
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/mini_code_cli/utils.py +2 -2
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/mini_code_cli.egg-info/PKG-INFO +1 -1
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/pyproject.toml +1 -1
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/LICENSE +0 -0
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/README.md +0 -0
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/mini_code_cli/__init__.py +0 -0
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/mini_code_cli.egg-info/SOURCES.txt +0 -0
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/mini_code_cli.egg-info/dependency_links.txt +0 -0
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/mini_code_cli.egg-info/entry_points.txt +0 -0
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/mini_code_cli.egg-info/top_level.txt +0 -0
- {mini_code_cli-0.0.6 → mini_code_cli-0.0.7}/setup.cfg +0 -0
|
@@ -23,17 +23,40 @@ def save_history(messages):
|
|
|
23
23
|
with open("history.json", "w") as f:
|
|
24
24
|
json.dump(messages, f, indent=2)
|
|
25
25
|
|
|
26
|
+
|
|
26
27
|
def parse_args():
|
|
27
28
|
parser = argparse.ArgumentParser(description="Agent loop for interacting with a language model")
|
|
28
29
|
parser.add_argument("--url", type=str, default="http://0.0.0.0:30000", help="API host")
|
|
30
|
+
parser.add_argument("--system_prompt", type=str, help="API host")
|
|
29
31
|
parser.add_argument("--api-key", type=str, default=None, help="API key for authentication")
|
|
30
32
|
parser.add_argument("--allowed-dir", type=str, default=".", help="Allowed directory for file operations")
|
|
31
|
-
parser.add_argument("--max-tokens", type=int,
|
|
33
|
+
parser.add_argument("--max-tokens", type=int, help="Maximum tokens for LLM response")
|
|
32
34
|
parser.add_argument("--temperature", type=float, default=0.0, help="Temperature for LLM")
|
|
33
35
|
parser.add_argument("--model", type=str, default="default", help="Model name")
|
|
34
36
|
args = parser.parse_args()
|
|
35
37
|
return args
|
|
36
38
|
|
|
39
|
+
def print_welcome(allowed_dir, server_url):
|
|
40
|
+
# Calculate the length of the longest line inside the box
|
|
41
|
+
lines = [
|
|
42
|
+
" Coding Agent Loop Started",
|
|
43
|
+
" Type 'quit' or 'exit' to exit the loop.",
|
|
44
|
+
f" Allowed dir: {allowed_dir}",
|
|
45
|
+
f" Server URL: {server_url}"
|
|
46
|
+
]
|
|
47
|
+
max_len = max(len(line) for line in lines)
|
|
48
|
+
margin = 2 # Space on each side inside the box
|
|
49
|
+
inner_width = max_len + 2 * margin
|
|
50
|
+
# Build the box
|
|
51
|
+
top_bottom = "╔" + "═" * inner_width + "╗"
|
|
52
|
+
print(top_bottom)
|
|
53
|
+
for line in lines:
|
|
54
|
+
# Pad the line to inner_width characters
|
|
55
|
+
padded = line.ljust(inner_width)
|
|
56
|
+
print(f"║{padded}║")
|
|
57
|
+
bottom = "╚" + "═" * inner_width + "╝"
|
|
58
|
+
print(bottom)
|
|
59
|
+
|
|
37
60
|
def main():
|
|
38
61
|
args = parse_args()
|
|
39
62
|
|
|
@@ -43,17 +66,14 @@ def main():
|
|
|
43
66
|
tools_dict = tools.util_get_tools_dict()
|
|
44
67
|
llm_tools_dict = tools.util_get_tools()
|
|
45
68
|
|
|
46
|
-
|
|
69
|
+
if args.system_prompt:
|
|
70
|
+
system_prompt = args.system_prompt
|
|
71
|
+
else:
|
|
72
|
+
system_prompt = prompts.system_prompt(tools_dict=tools_dict, allowed_dir=allowed_dir)
|
|
47
73
|
|
|
48
74
|
messages = [{"role": "system", "content": system_prompt}]
|
|
49
75
|
|
|
50
|
-
|
|
51
|
-
╔═══════════════════════════════════════════════════════════════════╗
|
|
52
|
-
║ Coding Agent Loop Started\t\t\t\t\t║
|
|
53
|
-
║ Type 'quit' or 'exit' to exit the loop.\t\t\t\t║
|
|
54
|
-
║ Allowed dir: {allowed_dir}\t║
|
|
55
|
-
╚═══════════════════════════════════════════════════════════════════╝
|
|
56
|
-
""")
|
|
76
|
+
print_welcome(allowed_dir, server_url)
|
|
57
77
|
|
|
58
78
|
while True:
|
|
59
79
|
llm_response_flag = False
|
|
@@ -90,42 +110,42 @@ def main():
|
|
|
90
110
|
if tool_calls:
|
|
91
111
|
# Tool call parsing and execution
|
|
92
112
|
print(f"{BOLD}{YELLOW}Tool Call:{RESET} LLM is trying to call {len(tool_calls)} tools.")
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
|
|
114
|
+
for call in tool_calls:
|
|
115
|
+
call_id = call.get("id", "")
|
|
116
|
+
name = call.get("function", {}).get("name", "")
|
|
117
|
+
params_str = call.get("function", {}).get("arguments", "{}")
|
|
118
|
+
try:
|
|
119
|
+
tool_params = json.loads(params_str)
|
|
120
|
+
except json.JSONDecodeError:
|
|
121
|
+
print(f"{BOLD}{RED}Warning:{RESET} Error parsing arguments for tool {name}")
|
|
122
|
+
continue
|
|
123
|
+
|
|
124
|
+
if name in tools_dict:
|
|
125
|
+
# Check allowed directory for file operations
|
|
126
|
+
if name in ["read_file", "write_file", "grep", "glob"]:
|
|
127
|
+
filepath = tool_params.get("filepath", "")
|
|
128
|
+
if name == "write_file":
|
|
107
129
|
filepath = tool_params.get("filepath", "")
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
result_str =
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
else:
|
|
128
|
-
print(f"{BOLD}{RED}Warning:{RESET} Unknown tool: {name}")
|
|
130
|
+
if filepath and not os.path.abspath(filepath).startswith(allowed_dir):
|
|
131
|
+
print(f"{BOLD}{RED}Warning:{RESET} File operation not allowed outside allowed directory: {allowed_dir}")
|
|
132
|
+
continue
|
|
133
|
+
|
|
134
|
+
func = tools_dict[name]["function"]
|
|
135
|
+
result = func(**tool_params)
|
|
136
|
+
# Limiting output to 300 characters for readability
|
|
137
|
+
result_str = str(result)
|
|
138
|
+
if len(result_str) > 300:
|
|
139
|
+
result_str = result_str[:300] + "... (truncated to 300 chars)"
|
|
140
|
+
print(f"{BOLD}{MAGENTA}Tool '{name}' returned:{RESET} {result_str}")
|
|
141
|
+
|
|
142
|
+
messages.append({
|
|
143
|
+
"role": "tool",
|
|
144
|
+
"tool_call_id": call_id,
|
|
145
|
+
"content": str(result)
|
|
146
|
+
})
|
|
147
|
+
else:
|
|
148
|
+
print(f"{BOLD}{RED}Warning:{RESET} Unknown tool: {name}")
|
|
129
149
|
else:
|
|
130
150
|
llm_tool_response_flag = True
|
|
131
151
|
|
|
@@ -3,22 +3,30 @@ def system_prompt(tools_dict=None, allowed_dir=None):
|
|
|
3
3
|
"""
|
|
4
4
|
Takes a list of tool names and returns a system prompt string.
|
|
5
5
|
"""
|
|
6
|
-
|
|
7
|
-
if allowed_dir:
|
|
8
|
-
allowed_dir_prompt = f"\nThe path you are allowed to operate in is called: {allowed_dir}"
|
|
6
|
+
|
|
9
7
|
if tools_dict:
|
|
10
8
|
tool_descriptions = "\n".join([f"{name} : {data['description']}" for name, data in tools_dict.items()])
|
|
11
|
-
base_prompt = "You are a helpful AI
|
|
12
|
-
end_prompt =
|
|
9
|
+
base_prompt = "You are a helpful AI assistant with access to the following tools:\n"
|
|
10
|
+
end_prompt = (
|
|
11
|
+
"Choose the most appropriate tool for the task at hand. "
|
|
12
|
+
"If a tool fails or you hit a limit, analyze the error and try a different approach. "
|
|
13
|
+
"Be concise and efficient in your tool usage."
|
|
14
|
+
)
|
|
13
15
|
else:
|
|
14
16
|
tool_descriptions = ""
|
|
15
|
-
base_prompt = "You are a helpful AI
|
|
17
|
+
base_prompt = "You are a helpful AI assistant without any tools."
|
|
16
18
|
end_prompt = ""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
allowed_dir_prompt = ""
|
|
22
|
+
if allowed_dir:
|
|
23
|
+
allowed_dir_prompt = f"\nThe path you are allowed to operate in is called: {allowed_dir}"
|
|
24
|
+
|
|
17
25
|
|
|
18
26
|
prompt = f"""
|
|
19
27
|
{base_prompt}
|
|
20
28
|
{tool_descriptions}{end_prompt}{allowed_dir_prompt}
|
|
21
|
-
|
|
29
|
+
Important: Only follow the user instruction. Do not create additional .md files (unless asked to do so). Do not create unit tests (unless asked to do so), etc.
|
|
22
30
|
"""
|
|
23
31
|
return prompt.strip()
|
|
24
32
|
|
|
@@ -19,9 +19,9 @@ def call_openai_server(messages, max_tokens=2048, temperature=0.0, top_p=0.95, m
|
|
|
19
19
|
payload = {
|
|
20
20
|
"model": model,
|
|
21
21
|
"messages": messages,
|
|
22
|
-
"max_tokens": max_tokens,
|
|
23
22
|
"temperature": temperature,
|
|
24
|
-
"
|
|
23
|
+
# "max_tokens": max_tokens,
|
|
24
|
+
# "top_p": top_p
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
if tools:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|