mini-code-cli 0.0.8.1__tar.gz → 0.0.8.2__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.8.1 → mini_code_cli-0.0.8.2}/PKG-INFO +1 -1
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/mini_code_cli/agent_loop.py +141 -129
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/mini_code_cli.egg-info/PKG-INFO +1 -1
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/pyproject.toml +1 -1
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/LICENSE +0 -0
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/README.md +0 -0
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/mini_code_cli/__init__.py +0 -0
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/mini_code_cli/prompts.py +0 -0
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/mini_code_cli/tools.py +0 -0
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/mini_code_cli/utils.py +0 -0
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/mini_code_cli.egg-info/SOURCES.txt +0 -0
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/mini_code_cli.egg-info/dependency_links.txt +0 -0
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/mini_code_cli.egg-info/entry_points.txt +0 -0
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/mini_code_cli.egg-info/top_level.txt +0 -0
- {mini_code_cli-0.0.8.1 → mini_code_cli-0.0.8.2}/setup.cfg +0 -0
|
@@ -61,7 +61,6 @@ def parse_args():
|
|
|
61
61
|
# Other settings:
|
|
62
62
|
parser.add_argument("--cache-dir", type=str, help="The cache dir for the session histories.")
|
|
63
63
|
|
|
64
|
-
|
|
65
64
|
# Agent behaviour related
|
|
66
65
|
parser.add_argument("--system-prompt", type=str, help="Replace system prompt, with a custom system prompt.")
|
|
67
66
|
parser.add_argument("--auto-mode", action="store_true", help="Whether to run the agent in `auto-mode'. Or default: `manual-mode'.")
|
|
@@ -208,141 +207,154 @@ def main():
|
|
|
208
207
|
user_input = args.prompt
|
|
209
208
|
|
|
210
209
|
while True:
|
|
210
|
+
try:
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
212
|
+
if llm_tool_response_flag and args.auto_mode: #skip user input and try to call the model again until there no more tool calls.
|
|
213
|
+
print(f"{BOLD}{YELLOW}System:{RESET} Skipping user input. Continuing with LLM calls until no more tool calls. [Tool count={tool_count}]")
|
|
214
|
+
llm_repeat_flag = True
|
|
215
|
+
else:
|
|
216
|
+
# get user input
|
|
217
|
+
if llm_repeat_flag:
|
|
218
|
+
print(f"{BOLD}{YELLOW}System:{RESET} Called {tool_count} tools in total. Exiting tool loop.")
|
|
219
|
+
|
|
220
|
+
tool_count = 0
|
|
221
|
+
if not user_input:
|
|
222
|
+
try:
|
|
223
|
+
print("-"*30)
|
|
224
|
+
user_input = input(f"{BOLD}{CYAN}You:{RESET} ")
|
|
225
|
+
if user_input.lower() in ["quit", "exit", "/quit", "/exit"]:
|
|
226
|
+
print("\nThank you. Goodbye!")
|
|
227
|
+
print(f"Saving history to: {cache_dir}/{unique_id}")
|
|
228
|
+
save_history(messages, args, unique_id)
|
|
229
|
+
break
|
|
230
|
+
except KeyboardInterrupt:
|
|
231
|
+
print("\nThank you. Goodbye!")
|
|
232
|
+
print(f"Saving history to: {cache_dir}/{unique_id}")
|
|
227
233
|
save_history(messages, args, unique_id)
|
|
228
234
|
break
|
|
229
|
-
|
|
230
|
-
print("
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if user_input == "/help":
|
|
238
|
-
print_help(allowed_dir, server_url, args, unique_id, cache_dir)
|
|
239
|
-
user_input = ""
|
|
240
|
-
continue
|
|
241
|
-
|
|
242
|
-
messages.append({"role": "user", "content": user_input})
|
|
243
|
-
user_input = ""
|
|
244
|
-
|
|
245
|
-
llm_response_flag = False
|
|
246
|
-
llm_tool_response_flag = False
|
|
247
|
-
|
|
248
|
-
response_text, tool_calls = utils.call_openai_server(
|
|
249
|
-
messages,
|
|
250
|
-
max_tokens=args.max_tokens,
|
|
251
|
-
temperature=args.temperature,
|
|
252
|
-
model=args.model,
|
|
253
|
-
server_url=server_url,
|
|
254
|
-
tools=llm_tools_dict,
|
|
255
|
-
api_key=api_key,
|
|
256
|
-
)
|
|
257
|
-
|
|
258
|
-
if response_text:
|
|
259
|
-
llm_response_flag = True
|
|
260
|
-
print(f"{BOLD}{GREEN}Assistant:{RESET} {response_text}")
|
|
261
|
-
|
|
262
|
-
if tool_calls:
|
|
263
|
-
llm_tool_response_flag = True
|
|
264
|
-
|
|
265
|
-
messages.append({
|
|
266
|
-
"role": "assistant",
|
|
267
|
-
"content": response_text,
|
|
268
|
-
"tool_calls": tool_calls
|
|
269
|
-
})
|
|
270
|
-
# Tool call parsing and execution
|
|
271
|
-
print(f"{BOLD}{YELLOW}Tool Call:{RESET} LLM is trying to call {len(tool_calls)} tools.")
|
|
272
|
-
|
|
273
|
-
for call in tool_calls:
|
|
274
|
-
tool_count += 1
|
|
275
|
-
|
|
276
|
-
call_id = call.get("id", "")
|
|
277
|
-
name = call.get("function", {}).get("name", "")
|
|
278
|
-
params_str = call.get("function", {}).get("arguments", "{}")
|
|
279
|
-
try:
|
|
280
|
-
tool_params = json.loads(params_str)
|
|
281
|
-
except json.JSONDecodeError:
|
|
282
|
-
print(f"{BOLD}{RED}Warning:{RESET} Error parsing arguments for tool {name}")
|
|
235
|
+
else:
|
|
236
|
+
print("-"*30)
|
|
237
|
+
print(f"{BOLD}{CYAN}You (preset): {RESET}{user_input}")
|
|
238
|
+
|
|
239
|
+
if user_input == "/help":
|
|
240
|
+
print_help(allowed_dir, server_url, args, unique_id, cache_dir)
|
|
241
|
+
user_input = ""
|
|
283
242
|
continue
|
|
284
243
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
244
|
+
messages.append({"role": "user", "content": user_input})
|
|
245
|
+
user_input = ""
|
|
246
|
+
|
|
247
|
+
llm_response_flag = False
|
|
248
|
+
llm_tool_response_flag = False
|
|
249
|
+
|
|
250
|
+
response_text, tool_calls = utils.call_openai_server(
|
|
251
|
+
messages,
|
|
252
|
+
max_tokens=args.max_tokens,
|
|
253
|
+
temperature=args.temperature,
|
|
254
|
+
model=args.model,
|
|
255
|
+
server_url=server_url,
|
|
256
|
+
tools=llm_tools_dict,
|
|
257
|
+
api_key=api_key,
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
if response_text:
|
|
261
|
+
llm_response_flag = True
|
|
262
|
+
print(f"{BOLD}{GREEN}Assistant:{RESET} {response_text}")
|
|
263
|
+
|
|
264
|
+
if tool_calls:
|
|
265
|
+
llm_tool_response_flag = True
|
|
266
|
+
|
|
267
|
+
messages.append({
|
|
268
|
+
"role": "assistant",
|
|
269
|
+
"content": response_text,
|
|
270
|
+
"tool_calls": tool_calls
|
|
271
|
+
})
|
|
272
|
+
# Tool call parsing and execution
|
|
273
|
+
print(f"{BOLD}{YELLOW}Tool Call:{RESET} LLM is trying to call {len(tool_calls)} tools.")
|
|
274
|
+
|
|
275
|
+
for call in tool_calls:
|
|
276
|
+
tool_count += 1
|
|
277
|
+
|
|
278
|
+
call_id = call.get("id", "")
|
|
279
|
+
name = call.get("function", {}).get("name", "")
|
|
280
|
+
params_str = call.get("function", {}).get("arguments", "{}")
|
|
281
|
+
try:
|
|
282
|
+
tool_params = json.loads(params_str)
|
|
283
|
+
except json.JSONDecodeError:
|
|
284
|
+
print(f"{BOLD}{RED}Warning:{RESET} Error parsing arguments for tool {name}")
|
|
285
|
+
continue
|
|
286
|
+
|
|
287
|
+
if name in tools_dict:
|
|
288
|
+
# Check allowed directory for file operations
|
|
289
|
+
if name in ["read_file", "write_file", "grep", "glob"]:
|
|
290
290
|
filepath = tool_params.get("filepath", "")
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
"
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
result_str =
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
"
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
291
|
+
if name == "write_file":
|
|
292
|
+
filepath = tool_params.get("filepath", "")
|
|
293
|
+
if filepath and not os.path.abspath(filepath).startswith(allowed_dir):
|
|
294
|
+
print(f"{BOLD}{RED}Warning:{RESET} File operation not allowed outside allowed directory: {allowed_dir}")
|
|
295
|
+
continue
|
|
296
|
+
|
|
297
|
+
func = tools_dict[name]["function"]
|
|
298
|
+
# asking permissions
|
|
299
|
+
if args.ask_permission:
|
|
300
|
+
print(f"{BOLD}{YELLOW}Tool permission:{RESET} Are you sure you want to call the tool?")
|
|
301
|
+
print(f"name: {name}, parameters: {params_str}")
|
|
302
|
+
try:
|
|
303
|
+
permission_input = input("Type: 'y' or 'yes'\n")
|
|
304
|
+
except KeyboardInterrupt:
|
|
305
|
+
print("\nThank you. Goodbye! Saving history...")
|
|
306
|
+
save_history(messages, args, unique_id)
|
|
307
|
+
sys.exit(0)
|
|
308
|
+
|
|
309
|
+
if not permission_input in ['y', 'yes']:
|
|
310
|
+
print(f"{BOLD}{YELLOW}Tool permission denied:{RESET}.")
|
|
311
|
+
messages.append({
|
|
312
|
+
"role": "user",
|
|
313
|
+
"content": f"User denied permission for tool {name} and params {params_str}."
|
|
314
|
+
})
|
|
315
|
+
continue
|
|
316
|
+
|
|
317
|
+
print(f"{BOLD}{YELLOW}Tool Call:{RESET} LLM is trying to call: {name} with {tool_params}.")
|
|
318
|
+
result = call_function_with_timeout(func, tool_params, name)
|
|
319
|
+
# Limiting output to 300 characters for readability
|
|
320
|
+
result_str = str(result)
|
|
321
|
+
if len(result_str) > 300:
|
|
322
|
+
result_str = result_str[:300] + "... (truncated to 300 chars)"
|
|
323
|
+
print(f"{BOLD}{MAGENTA}Tool '{name}' returned:{RESET} {result_str}")
|
|
324
|
+
|
|
325
|
+
messages.append({
|
|
326
|
+
"role": "tool",
|
|
327
|
+
"tool_call_id": call_id,
|
|
328
|
+
"content": str(result)
|
|
329
|
+
})
|
|
330
|
+
else:
|
|
331
|
+
print(f"{BOLD}{RED}Error:{RESET} Unknown tool: {name}, params {params_str}")
|
|
332
|
+
messages.append({
|
|
333
|
+
"role": "tool",
|
|
334
|
+
"tool_call_id": call_id,
|
|
335
|
+
"content": f"Error: Unknown tool: {name}, params {params_str}"
|
|
336
|
+
})
|
|
337
|
+
else:
|
|
338
|
+
messages.append({
|
|
339
|
+
"role": "assistant",
|
|
340
|
+
"content": response_text,
|
|
341
|
+
# "tool_calls": tool_calls
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
if not llm_response_flag and not llm_tool_response_flag:
|
|
345
|
+
print(f"{BOLD}{RED}Warning:{RESET} No response was given by the LLM.")
|
|
346
|
+
|
|
347
|
+
save_history(messages, args, unique_id)
|
|
344
348
|
|
|
345
|
-
|
|
349
|
+
except KeyboardInterrupt:
|
|
350
|
+
print(f"{BOLD}{RED}INTERRUPTING:{RESET} Mini Code Exiting...")
|
|
351
|
+
|
|
352
|
+
except Exception as e:
|
|
353
|
+
print(f"{BOLD}{RED}FATAL ERROR:{RESET} Mini Code Crashed...:\n{e}")
|
|
354
|
+
|
|
355
|
+
finally:
|
|
356
|
+
print(f"Saving history to: {cache_dir}/{unique_id}")
|
|
357
|
+
save_history(messages, args, unique_id)
|
|
346
358
|
|
|
347
359
|
if __name__ == "__main__":
|
|
348
360
|
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|