File size: 1,140 Bytes
739e67a
 
 
 
 
 
 
 
 
391b2d9
 
739e67a
391b2d9
 
739e67a
 
 
 
 
 
 
 
391b2d9
 
 
 
feda34f
391b2d9
739e67a
 
 
 
feda34f
 
739e67a
 
feda34f
 
 
 
 
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
import json
import re
from typing import Dict, List

from ai import llm
from utils.io import print_system


PROMPT = """
Your goal is to create an ad with the following dimensions: {dimensions}.
You will rely on an AI image generator to create an image for you.

Create a prompt to be used by the AI image generator.
Pick a dimension to map to from this list: 256x256, 512x512, 1024x1024. The AI image will have these dimensions.
Create a headline.
Consider that the headlines will be edited on top of the generated images.

Here is the summary of the website:
{summary}

Generate a JSON in the following format:
```
{{
    "ad_dimension":
    "dimension_to_map":
    "headline":
    "ai_prompt":
}}
```
"""


def generate_headline_and_prompt(summary: str, dimensions: str) -> str:
    return _generate_headline_and_prompt(PROMPT, summary=summary, dimensions=dimensions)


def _generate_headline_and_prompt(prompt: str, **kwargs) -> str:
    print_system("Generating headline for website...")
    instructions = prompt.format(**kwargs)
    messages = [{"role": "user", "content": instructions}]
    return llm.next(messages, temperature=0)