File size: 2,220 Bytes
b67629f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import sys
import json
import random
from YOUR_API_CALLER_GOES_HERE import LLM_COMPLETION

def get_response(title, poet):
    """
    Creates poem-generation prompt from title and poet, and puts it into
    the expected penchant format
    """

    penchant_prompt = f'Write an artistic poem. The title should be "{title}". Use vivid imagery and creative metaphors throughout your work. Draw inspiration from the works of {poet}. Pay close attention to the sounds that words make when read aloud, and use these sounds to create rhythm and musicality within your piece.'

    penchant_template = f"<|im_start|>system\nYou are Dolphin, a helpful AI assistant.<|im_end|>\n<|im_start|>user\n{penchant_prompt}<|im_end|>\n<|im_start|>assistant\n"

    poem = LLM_COMPLETION(penchant_template)
    return poem


def process_files(titles_file, poets_file, output_file):
    try:
        # Read "titles" and "poets" from input files
        with open(titles_file, 'r') as f:
            titles_data = json.load(f)
            titles = titles_data.get("titles", [])

        with open(poets_file, 'r') as f:
            poets_data = json.load(f)
            poets = poets_data.get("poets", [])

        # Write responses to output JSONL file
        with open(output_file, 'w') as f:
            poems_to_write = 100
            count = 0
            while count < poems_to_write:
                title = random.choice(titles)
                poet = random.choice(poets)
                title = title.strip()
                poet = poet.strip()
                response = get_response(title, poet)
                output_data = {"poet": poet, "title": title, "poem": response}
                f.write(json.dumps(output_data) + "\n")
                count += 1
    except FileNotFoundError as e:
        print(f"Error: {e.filename} not found.")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    if len(sys.argv) != 4:
        print("Usage: python script.py titles_file.json poets_file.json output_file.jsonl")
    else:
        titles_file = sys.argv[1]
        poets_file = sys.argv[2]
        output_file = sys.argv[3]
        process_files(titles_file, poets_file, output_file)