Skip to content

Commit

Permalink
add dataset output
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwei37 committed Jul 28, 2023
1 parent ae88889 commit 1394162
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tools/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import openai
import os
import json
import glob
import time
openai.api_key = os.getenv("OPENAI_API_KEY")


def get_bpf_summary(bpf_code):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content":
f"""
Given this BPF code:
{bpf_code}
Provide a concise and clear summary in one or two sentences.
Frame the explanation as a user's request to a developer to write a BPF code.
Avoid beginning with phrases like 'This BPF code is...' Instead,
start with action-oriented phrases such as 'Write a BPF code that...'
"""


}
],
max_tokens=1500
)

output = response.choices[0].message['content']
return output


def get_all_bpf_in_dir(directory):
all_files = glob.glob(directory + '/*.bt')
all_bpf = []
for file in all_files:
print("opening file: " + file)
# sleep for a short time to avoid hitting the rate limit
# Sleep for 5 seconds
time.sleep(3)
with open(file, 'r') as f:
bpf_code = f.read()
summary = get_bpf_summary(bpf_code)
all_bpf.append({
"request": summary,
"bpf": bpf_code
})
print(bpf_code)
print(summary)

return all_bpf


directory = './'
all_bpf = get_all_bpf_in_dir(directory)
with open('output.json', 'w') as outfile:
json.dump(all_bpf, outfile)
Loading

0 comments on commit 1394162

Please sign in to comment.