Last active
February 9, 2024 15:43
-
-
Save p-karanthaker/9722f45555e20b9cc167aa36e9096dc0 to your computer and use it in GitHub Desktop.
csv to jsonl example for chatgpt openai api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import json | |
with open('source.csv') as csvfile, open("target.jsonl", "a") as jsonfile: | |
r = csv.reader(csvfile) | |
next(r, None) | |
for row in r: | |
model = { | |
"messages": [ | |
{ | |
"role": "system", | |
"content": "Woodhurst has a cool chat assitant?" | |
}, | |
{ | |
"role": "user", | |
"content": row[0] # Context row | |
}, | |
{ | |
"role": "assistant", | |
"content": row[1] # Response row | |
} | |
] | |
} | |
jsonl = json.dumps(model) | |
jsonfile.write(f"{jsonl}\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment