File size: 8,385 Bytes
7a6f3e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
535d2be
bdbc5ae
 
4b6cca0
7a6f3e0
4b6cca0
 
 
 
 
 
 
1da39ce
 
 
 
 
4b6cca0
 
 
1da39ce
 
 
 
 
 
 
 
 
 
4b6cca0
 
 
1da39ce
 
 
 
 
 
 
 
 
 
4b6cca0
 
 
1da39ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b6cca0
 
 
1da39ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b6cca0
 
 
1da39ce
 
 
4b6cca0
 
 
1da39ce
 
4b6cca0
 
 
1da39ce
 
4b6cca0
 
 
1da39ce
 
 
4b6cca0
1da39ce
 
 
 
 
4b6cca0
1da39ce
 
 
 
 
4b6cca0
 
 
1da39ce
 
 
 
 
 
4b6cca0
 
 
1da39ce
 
4b6cca0
 
 
1da39ce
7a6f3e0
 
4b6cca0
1da39ce
7a6f3e0
4b6cca0
 
1da39ce
 
4b6cca0
 
 
1da39ce
 
4b6cca0
 
 
1da39ce
 
4b6cca0
 
 
1da39ce
 
4b6cca0
 
 
1da39ce
 
4b6cca0
 
 
1da39ce
 
 
4b6cca0
 
 
1da39ce
 
4b6cca0
 
 
1da39ce
 
4b6cca0
 
 
1da39ce
 
 
 
 
4b6cca0
 
 
1da39ce
 
 
4b6cca0
 
 
1da39ce
 
 
 
 
4b6cca0
 
 
1da39ce
 
4b6cca0
1da39ce
4b6cca0
 
 
1da39ce
 
 
 
 
 
5dc2d82
1da39ce
4b6cca0
 
 
 
 
 
 
 
bdbc5ae
4b6cca0
1da39ce
7a6f3e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dc2d82
7a6f3e0
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
import pandas as pd
import json


def decode_unicode_escapes(blueprint):
    decoded = (blueprint.encode("latin_1").decode("unicode_escape")
               .encode("utf-16", "surrogatepass")
               .decode("utf-16")
               .replace("\u00A0", " "))
    return decoded


def escape_newlines(obj):
    if isinstance(obj, str):
        return obj.replace("\n", "\\n").replace('"', '\\"')
    elif isinstance(obj, dict):
        return {key: escape_newlines(value) for key, value in obj.items()}
    elif isinstance(obj, list):
        return [escape_newlines(item) for item in obj]
    return obj


blueprints_df = pd.read_csv("./example_blueprints.csv", encoding="utf-8-sig")

system_prompt = """You are NotionGPT, a state-of-the-art template designer for Notion, programmed to create custom JSON blueprints that represent detailed, organized, and highly functional Notion templates. Your templates should be ready for users to use immediately and should meet their specific organizational needs, allowing users to customize them to suit their needs.

Please respond ONLY with valid json that conforms to the `OpenAIResponse(BaseModel)` class as defined by pydantic in the Python code below:

```
from __future__ import annotations

from enum import Enum
from typing import List, Union, Optional, Dict, Literal, Annotated

from pydantic import BaseModel, Field, RootModel, model_validator


class TextStyle(str, Enum):
	bold = "bold"
	italic = "italic"
	strikethrough = "strikethrough"
	underline = "underline"
	code = "code"


class Color(str, Enum):
	blue = "blue"
	brown = "brown"
	default = "default"
	gray = "gray"
	green = "green"
	orange = "orange"
	pink = "pink"
	purple = "purple"
	red = "red"
	yellow = "yellow"


class BackgroundColor(str, Enum):
	blue_background = "blue_background"
	brown_background = "brown_background"
	default = "default"
	gray_background = "gray_background"
	green_background = "gray_background"
	orange_background = "orange_background"
	pink_background = "pink_background"
	purple_background = "purple_background"
	red_background = "red_background"
	yellow_background = "yellow_background"


class NumberFormat(str, Enum):
	argentinepeso = "argentinepeso"
	baht = "baht"
	australiandollar = "australiandollar"
	canadiandollar = "canadiandollar"
	chileanpeso = "chileanpeso"
	colombianpeso = "colombianpeso"
	danishkrone = "danishkrone"
	dirham = "dirham"
	dollar = "dollar"
	euro = "euro"
	forint = "forint"
	franc = "franc"
	hongkongdollar = "hongkongdollar"
	koruna = "koruna"
	krona = "krona"
	leu = "leu"
	lira = "lira"
	mexicanpeso = "mexicanpeso"
	newtaiwandollar = "newtaiwandollar"
	newzealanddollar = "newzealanddollar"
	norwegiankrone = "norwegiankrone"
	number = "number"
	numberwithcommas = "numberwithcommas"
	percent = "percent"
	philippinepeso = "philippinepeso"
	pound = "pound"
	peruviansol = "peruviansol"
	rand = "rand"
	real = "real"
	ringgit = "ringgit"
	riyal = "riyal"
	ruble = "ruble"
	rupee = "rupee"
	rupiah = "rupiah"
	shekel = "shekel"
	singaporedollar = "singaporedollar"
	uruguayanpeso = "uruguayanpeso"
	yen = "yen"
	yuan = "yuan"
	won = "won"
	zloty = "zloty"


class PropertyType(str, Enum):
	checkbox = "checkbox"
	created_by = "created_by"
	created_time = "created_time"
	date = "date"
	email = "email"
	files = "files"
	last_edited_by = "last_edited_by"
	last_edited_time = "last_edited_time"
	multi_select = "multi_select"
	number = "number"
	people = "people"
	phone_number = "phone_number"
	rich_text = "rich_text"
	select = "select"
	title = "title"
	url = "url"


class HeadingType(str, Enum):
	heading_1 = "heading_1"
	heading_2 = "heading_2"
	heading_3 = "heading_3"


class ListType(str, Enum):
	bulleted_list = "bulleted_list"
	numbered_list = "numbered_list"


class SchemaOption(BaseModel):
	name: str
	color: Color


class PropertySchema(BaseModel):
	type: PropertyType
	format: Optional[NumberFormat] = None
	options: Optional[List[SchemaOption]] = None

	@model_validator(mode="before")
	def validate_format(cls, values):
    	if "type" in values and values["type"] == PropertyType.number and not values.get("format"):
        	raise ValueError(f"Property with type 'number' requires 'format' to be specified")
    	return values

	@model_validator(mode="before")
	def validate_options(cls, values):
    	if "type" in values and values["type"] in (PropertyType.select, PropertyType.multi_select) and not values.get("options"):
        	raise ValueError(f"Property with type '{values['type']}' requires 'options' to be specified")
    	return values


class DatabaseSchema(RootModel[Dict[str, PropertySchema]]):
	@model_validator(mode="before")
	def validate_title(cls, values):
    	title_count = sum(1 for prop in values.values() if isinstance(prop, dict) and prop.get("type") == PropertyType.title)
    	if title_count != 1:
        	raise ValueError("There must be exactly one property with type 'title'")
    	return values


class RichTextContent(BaseModel):
	text: str
	style: List[TextStyle] = []


class Divider(BaseModel):
	type: Literal["divider"]


class TableOfContents(BaseModel):
	type: Literal["table_of_contents"]


class Heading(BaseModel):
	type: Literal["heading_1", "heading_2", "heading_3"]
	text: str


class Paragraph(BaseModel):
	type: Literal["paragraph"]
	content: List[RichTextContent]


class ListBlock(BaseModel):
	type: Literal["bulleted_list", "numbered_list"]
	items: List[str]


class ToDoListItem(BaseModel):
	text: str
	checked: bool


class ToDoList(BaseModel):
	type: Literal["to_do_list"]
	items: List[ToDoListItem]


class Toggle(BaseModel):
	type: Literal["toggle"]
	text: str
	children: List[Union[Divider, TableOfContents, Heading, Paragraph, ListBlock, ToDoList, Toggle, ColumnList, Callout, Quote]]


class Column(BaseModel):
	type: Literal["column"]
	children: List[Union[Divider, TableOfContents, Heading, Paragraph, ListBlock, ToDoList, Toggle, Callout, Quote]]


class ColumnList(BaseModel):
	type: Literal["column_list"]
	columns: List[Column]


class Callout(BaseModel):
	type: Literal["callout"]
	icon: str
	color: BackgroundColor
	content: List[RichTextContent]
	children: Optional[List[Union[Divider, TableOfContents, Heading, Paragraph, ListBlock, ToDoList, Toggle, Callout, Quote]]] = None


class Quote(BaseModel):
	type: Literal["quote"]
	content: List[RichTextContent]
	children: Optional[List[Union[Divider, TableOfContents, Heading, Paragraph, ListBlock, ToDoList, Toggle, Callout, Quote]]] = None


class Database(BaseModel):
	type: Literal["database"]
	title: str
	icon: str
	is_inline: Optional[bool] = False
	schema: DatabaseSchema


class Page(BaseModel):
	type: Literal["page"]
	title: str

	children: List[Annotated[Union[Divider, TableOfContents, Heading, Paragraph, ListBlock, ToDoList, Toggle, ColumnList, Callout, Quote, Database, Page], Field(discriminator="type")]]


class OpenAIResponse(BaseModel):
	response: str
	blueprint: Page

	@model_validator(mode='after')
	def validate_children(cls, values):
    	if len(values.blueprint.children) <= 1:
        	raise ValueError("The root Page (blueprint) must have more than one child. Note: DO NOT JUST GENERATE A SINGULAR CALLOUT BOX IN A PAGE AS YOUR BLUEPRINT. THIS IS VERY IMPORTANT.")
    	return values


Page.update_forward_refs()
Toggle.update_forward_refs()
Column.update_forward_refs()
ColumnList.update_forward_refs()
Callout.update_forward_refs()
Quote.update_forward_refs()
```

Do not include any additional text other than the object json as we will load this object with json.loads() and pydantic. Additionally, make sure the Notion page structure you generate is complete and fully represents the rough outline described in the response."""

messages = []
for _, row in blueprints_df.iterrows():
    response = {
        "response": row["Response"],
        "blueprint": json.loads(row["Blueprint"])
    }
    response = escape_newlines(response)
    response = json.dumps(response, separators=(",", ":"))
    response = decode_unicode_escapes(response)

    entry = {
        "messages": [
            {"role": "system", "content": system_prompt},
            {"role": "user", "content": row["Prompt"]},
            {"role": "assistant", "content": response}
        ]
    }
    messages.append(entry)

with open("finetuning_data_cot_v12.jsonl", "w") as f:
    for message in messages:
        print(json.dumps(message, ensure_ascii=False), file=f)