Skip to content

Instantly share code, notes, and snippets.

@rosslazer
Last active March 12, 2024 17:56
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosslazer/9fc358f37f8a552fa49d47968d70a98b to your computer and use it in GitHub Desktop.
Save rosslazer/9fc358f37f8a552fa49d47968d70a98b to your computer and use it in GitHub Desktop.
import json
import os
from collections import deque
root_dir = '~/slack_messages'
target_user = "UMQN69N8M"
res = []
for dirpath, dirnames, filenames in os.walk(root_dir):
for file_name in filenames:
if file_name.endswith('.json'):
file_path = os.path.join(dirpath, file_name)
with open(file_path, 'r') as f:
data = json.load(f)
buffer = deque()
last_question = ""
for elem in data:
try:
if elem['user'] != target_user and last_question and buffer:
combined_message = '\n'.join(buffer)
res.append({"messages": [{"role": "system", "content": "You are Ross. He is a product manager at Observe inc. He responds to messages from his coworkers on slack and is helpful."}, {"role": "user", "content": last_question}, {"role": "assistant", "content": combined_message}]}
)
buffer.clear()
if elem['user'] != target_user:
last_question = elem['blocks'][0]['elements'][0]['elements'][0]['text']
elif elem['user'] == target_user:
buffer.append(elem['blocks'][0]['elements'][0]['elements'][0]['text'])
# Add final conversation if exists
if buffer and last_question:
combined_message = '\n'.join(buffer)
res.append({"messages": [{"role": "system", "content": "You are Ross is a product manager at Observe inc. He responds to messages from his coworkers on slack and is helpful."}, {"role": "user", "content": last_question}, {"role": "assistant", "content": combined_message}]}
)
except Exception as e:
continue
with open('all_messages.jsonl', 'w') as outfile:
for entry in res:
json.dump(entry, outfile)
outfile.write('\n')
```
[
{
"client_msg_id": "e59a1118-8164-4eb9-9623-e4114502ba30",
"type": "message",
"text": "\u003c@UMQN69N8M\u003e - How are you doing?
"user": "U01AFPBSPCKX",
"ts": "1644956438.392969",
"blocks": [
{
"type": "rich_text",
"block_id": "euXh",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "user",
"user_id": "UMQN78NMB"
},
{
"type": "text",
"text": " - How are you doing?"
},
{
"type": "link",
"url": "https://foobar.com
}
]
}
]
}
],
"team": "T7B732R0S"
},
{
"client_msg_id": "6590516f-ff2b-4268-aef2-f7bfadd0a250",
"type": "message",
"text": "I'm fine and you?",
"user": "UMQN78NMB",
"ts": "1644957762.921829",
"blocks": [
{
"type": "rich_text",
"block_id": "1Xntl",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "I'm fine and you?"
}
]
}
]
}
],
....
]
new file openai.FineTuningJob.create(training_file="file-jo5xMgDc8pyuP3S6IC24440T", model="gpt-3.5-turbo")
openai.FineTuningJob.create(training_file="file-jo5xMgDc8pyuP3S6IC24440T", model="gpt-3.5-turbo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment