Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve examples from vectordb to construct a few-shot prompt. #13

Merged
merged 1 commit into from
Jul 31, 2023

Conversation

try-agaaain
Copy link
Member

Build a vector database based on the examples in the tools folder, and then retrieve examples relevant to user requests from the database and add them to the prompt.

As an example, the prompt constructed for the request "Trace allocations and display each individual allocator function call" is as follows:

Prompt: 
    As a supportive assistant to a Linux system administrator,
    your role involves leveraging bpftrace to generate eBPF code that aids
    in problem-solving, as well as responding to queries.
    Note that you may not always need to call the bpftrace tool function.
    Here are some pertinent examples that align with the user's requests:

    example: Write a BPF code that traces the kernel OOM killer and prints basic details, including the system load averages, providing context on the system state at the time of the OOM.

\```
#!/usr/bin/env bpftrace


#ifndef BPFTRACE_HAVE_BTF
#include <linux/oom.h>
#endif

BEGIN
{
        printf("Tracing oom_kill_process()... Hit Ctrl-C to end.\n");
}

kprobe:oom_kill_process
{
        $oc = (struct oom_control *)arg0;
        time("%H:%M:%S ");
        printf("Triggered by PID %d (\"%s\"), ", pid, comm);
        printf("OOM kill of PID %d (\"%s\"), %d pages, loadavg: ",
            $oc->chosen->pid, $oc->chosen->comm, $oc->totalpages);
        cat("/proc/loadavg");
}

\```
    ...
    Now, you have received the following request from a user: Trace allocations and display each individual allocator function call
    Please utilize your capabilities to the fullest extent to accomplish this task.

However, GPT will imitate these examples to generate multi-line code for BPFtrace programs, similar to:

sudo bpftrace -e #!/usr/bin/env bpftrace

BEGIN
{
  printf("Tracing allocator functions... Hit Ctrl-C to end.\n");
}

uprobe:/usr/lib/libc.so.6:malloc
{
  printf("%s allocated %lu bytes\n", comm, arg1);
}

uprobe:/usr/lib/libc.so.6:calloc
{
  printf("%s allocated %lu bytes\n", comm, (arg1 * arg2));
}

uprobe:/usr/lib/libc.so.6:realloc
{
  printf("%s reallocated %lu bytes\n", comm, arg2);
}

uprobe:/usr/lib/libc.so.6:free
{
  printf("%s freed memory\n", comm);
}

These multiple lines of code should be saved into a file (e.g., trace.bt) and then executed using sudo bpftrace trace.bt.

Alternatively, we can have bpftrace read the bpftrace program from standard input:

cat <<EOF | sudo bpftrace -
program generated by gpt
EOF

@yunwei37 yunwei37 merged commit db698c8 into eunomia-bpf:main Jul 31, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants