Last active
October 17, 2023 03:01
-
-
Save wesslen/0ce2c586a156df17f9e4ac7c07f45f49 to your computer and use it in GitHub Desktop.
GPT3.5 fine tuning dummy example
This file contains 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 os | |
import json | |
import typer | |
app = typer.Typer() | |
def process_scripts(input_prompts_file: str, scripts_folder: str, output_file: str): | |
output_data = [] | |
# Read input prompts from the .jsonl file | |
with open(input_prompts_file, 'r') as prompts_file: | |
for line in prompts_file: | |
prompt_data = json.loads(line) | |
prompt_text = prompt_data['text'].strip() | |
script_filename = prompt_data['meta']['script'] | |
script_path = os.path.join(scripts_folder, script_filename) | |
if os.path.exists(script_path): | |
with open(script_path, 'r') as script_file: | |
script_content = script_file.read().strip() | |
message = { | |
"role": "system", | |
"content": "You are a system that generates Python scripts when given a prompt." | |
} | |
user_message = { | |
"role": "user", | |
"content": prompt_text | |
} | |
assistant_message = { | |
"role": "assistant", | |
"content": script_content | |
} | |
output_data.append({"messages": [message, user_message, assistant_message]}) | |
# Write the output data to the output file | |
with open(output_file, 'w') as output: | |
for entry in output_data: | |
json.dump(entry, output) | |
output.write('\n') | |
@app.command() | |
def main( | |
input_prompts_file: str = typer.Argument(..., help="Path to the input prompts .jsonl file"), | |
scripts_folder: str = typer.Argument(..., help="Path to the folder containing Python scripts"), | |
output_file: str = typer.Argument(..., help="Path to the output .jsonl file") | |
): | |
""" | |
Convert input prompts and scripts into output JSONL file. | |
""" | |
process_scripts(input_prompts_file, scripts_folder, output_file) | |
typer.echo("Conversion completed!") | |
if __name__ == "__main__": | |
app() | |
This file contains 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
print("hello world!") |
This file contains 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
{"text": "Write a Python script that runs hello world.", "meta": {"script": "hello_world.py"}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment