Skip to content

Instantly share code, notes, and snippets.

@p-karanthaker
Last active February 9, 2024 15:43
Show Gist options
  • Save p-karanthaker/9722f45555e20b9cc167aa36e9096dc0 to your computer and use it in GitHub Desktop.
Save p-karanthaker/9722f45555e20b9cc167aa36e9096dc0 to your computer and use it in GitHub Desktop.
csv to jsonl example for chatgpt openai api
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