diff --git a/doc/result.png b/doc/result.png index 2cd2b77..91127a6 100644 Binary files a/doc/result.png and b/doc/result.png differ diff --git a/main.py b/main.py index fd2c603..594fad7 100755 --- a/main.py +++ b/main.py @@ -45,21 +45,43 @@ def main(): desc: str = args.run ret_val = generate_result(chatbot, desc, conv_uuid, True) # print(ret_val) - parsed = extract_code_blocks(ret_val) - print(f"Command to run: {parsed[0]}") - os.system(parsed[0]) + parsed = make_executable_command(ret_val) + print(f"Command to run: {parsed}") + os.system("sudo " + parsed) + +def construct_prompt(text: str) -> str: + return f'''You are now a translater from human language to {os.uname()[0]} shell bpftrace command. +No explanation required. +respond with only the raw shell bpftrace command. +It should be start with `bpftrace`. +Your response should be able to put into a shell and run directly. +Just output in one line, without any description, or any other text that cannot be run in shell. +What should I type to shell to trace using bpftrace for: {text}, in one line.''' + +def make_executable_command(command: str) -> str: + if command.startswith('\n'): + command = command[1:] + if command.endswith('\n'): + command = command[:-1] + if command.startswith('`'): + command = command[1:] + if command.endswith('`'): + command = command[:-1] + command = command.strip() + command = command.split('User: ')[0] + return command def generate_result(bot: Chatbot, text: str, session: str = None, print_out: bool = False) -> str: from io import StringIO prev_text = "" + query_text = construct_prompt(text) buf = StringIO() for data in bot.ask( - text, conversation_id=session + query_text, conversation_id=session ): message = data["message"][len(prev_text):] if print_out: print(message, end="", flush=True) - buf.write(message) prev_text = data["message"] if print_out: diff --git a/prompts/1.md b/prompts/1.md index 78774d2..b0a6460 100644 --- a/prompts/1.md +++ b/prompts/1.md @@ -1,3 +1,6 @@ +You are now a translater from human language to shell bpftrace command. +Here are some examples of what you can do with bpftrace shell command: + # Files opened by process bpftrace -e 'tracepoint:syscalls:sys_enter_open { printf("%s %s\n", comm, str(args->filename)); }' @@ -26,4 +29,6 @@ bpftrace -e 'hardware:cache-misses:1000000 { @[comm, pid] = count(); }' bpftrace -e 'profile:hz:99 /pid == 189/ { @[ustack] = count(); }' # Files opened, for processes in the root cgroup-v2 -bpftrace -e 'tracepoint:syscalls:sys_enter_openat /cgroup == cgroupid("/sys/fs/cgroup/unified/mycg")/ { printf("%s\n", str(args->filename)); }' \ No newline at end of file +bpftrace -e 'tracepoint:syscalls:sys_enter_openat /cgroup == cgroupid("/sys/fs/cgroup/unified/mycg")/ { printf("%s\n", str(args->filename)); }' + +After you read and learn about bpftrace, I will ask you to write a bpftrace command to do something.