Skip to content

Commit d5c94b6

Browse files
authored
feat: added Ragas API Relay
Feat/simpler annotation
2 parents b9fa013 + 5d39f9a commit d5c94b6

23 files changed

+3897
-444
lines changed

nbs/backends/.notest

Whitespace-only changes.

nbs/backends/factory.ipynb

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"metadata": {},
1616
"outputs": [],
1717
"source": [
18-
"#| default_exp backends.factory"
18+
"# | default_exp backends.factory"
1919
]
2020
},
2121
{
@@ -24,7 +24,7 @@
2424
"metadata": {},
2525
"outputs": [],
2626
"source": [
27-
"#| export\n",
27+
"# | export\n",
2828
"import typing as t\n",
2929
"import os\n",
3030
"\n",
@@ -39,31 +39,31 @@
3939
"metadata": {},
4040
"outputs": [],
4141
"source": [
42-
"#| export\n",
42+
"# | export\n",
4343
"class NotionClientFactory:\n",
4444
" \"\"\"Factory for creating Notion client instances.\"\"\"\n",
45-
" \n",
45+
"\n",
4646
" @staticmethod\n",
4747
" def create(\n",
4848
" use_mock: bool = False,\n",
4949
" api_key: t.Optional[str] = None,\n",
5050
" initialize_project: bool = False,\n",
51-
" root_page_id: t.Optional[str] = None\n",
51+
" root_page_id: t.Optional[str] = None,\n",
5252
" ) -> t.Union[NotionClient, MockNotionClient]:\n",
5353
" \"\"\"Create a Notion client.\n",
54-
" \n",
54+
"\n",
5555
" Args:\n",
5656
" use_mock: If True, create a mock client\n",
5757
" api_key: Notion API key (only used for real client)\n",
5858
" initialize_project: If True and using mock, initialize project structure\n",
5959
" root_page_id: Required if initialize_project is True\n",
60-
" \n",
60+
"\n",
6161
" Returns:\n",
6262
" Union[NotionClient, MockNotionClient]: A real or mock client\n",
6363
" \"\"\"\n",
6464
" if use_mock:\n",
6565
" client = MockNotionClient()\n",
66-
" \n",
66+
"\n",
6767
" # Optionally initialize project structure\n",
6868
" if initialize_project and root_page_id:\n",
6969
" # Create root page if it doesn't exist in the mock client\n",
@@ -77,18 +77,24 @@
7777
" \"archived\": False,\n",
7878
" \"properties\": {\n",
7979
" \"title\": {\n",
80-
" \"type\": \"title\", \n",
81-
" \"title\": [{\"plain_text\": \"Root Page\", \"type\": \"text\", \"text\": {\"content\": \"Root Page\"}}]\n",
80+
" \"type\": \"title\",\n",
81+
" \"title\": [\n",
82+
" {\n",
83+
" \"plain_text\": \"Root Page\",\n",
84+
" \"type\": \"text\",\n",
85+
" \"text\": {\"content\": \"Root Page\"},\n",
86+
" }\n",
87+
" ],\n",
8288
" }\n",
83-
" }\n",
89+
" },\n",
8490
" }\n",
8591
" client.add_page(root_page)\n",
86-
" \n",
92+
"\n",
8793
" # Create required sub-pages\n",
8894
" for page_name in [\"Datasets\", \"Experiments\", \"Comparisons\"]:\n",
8995
" # Create page ID\n",
9096
" page_id = client._create_id()\n",
91-
" \n",
97+
"\n",
9298
" # Create page\n",
9399
" page = {\n",
94100
" \"id\": page_id,\n",
@@ -98,37 +104,43 @@
98104
" \"archived\": False,\n",
99105
" \"properties\": {\n",
100106
" \"title\": {\n",
101-
" \"type\": \"title\", \n",
102-
" \"title\": [{\"plain_text\": page_name, \"type\": \"text\", \"text\": {\"content\": page_name}}]\n",
107+
" \"type\": \"title\",\n",
108+
" \"title\": [\n",
109+
" {\n",
110+
" \"plain_text\": page_name,\n",
111+
" \"type\": \"text\",\n",
112+
" \"text\": {\"content\": page_name},\n",
113+
" }\n",
114+
" ],\n",
103115
" }\n",
104116
" },\n",
105-
" \"parent\": {\"type\": \"page_id\", \"page_id\": root_page_id}\n",
117+
" \"parent\": {\"type\": \"page_id\", \"page_id\": root_page_id},\n",
106118
" }\n",
107119
" client.add_page(page)\n",
108-
" \n",
120+
"\n",
109121
" # Add child block to root\n",
110122
" child_block = {\n",
111123
" \"id\": client._create_id(),\n",
112124
" \"object\": \"block\",\n",
113125
" \"type\": \"child_page\",\n",
114126
" \"created_time\": client._get_timestamp(),\n",
115127
" \"last_edited_time\": client._get_timestamp(),\n",
116-
" \"child_page\": {\n",
117-
" \"title\": page_name\n",
118-
" }\n",
128+
" \"child_page\": {\"title\": page_name},\n",
119129
" }\n",
120-
" \n",
130+
"\n",
121131
" client.add_children(root_page_id, [child_block])\n",
122-
" \n",
132+
"\n",
123133
" return client\n",
124134
" else:\n",
125135
" # For real client, use provided API key or environment variable\n",
126136
" if api_key is None:\n",
127137
" api_key = os.getenv(\"NOTION_API_KEY\")\n",
128-
" \n",
138+
"\n",
129139
" if api_key is None:\n",
130-
" raise ValueError(\"api_key must be provided or set as NOTION_API_KEY environment variable\")\n",
131-
" \n",
140+
" raise ValueError(\n",
141+
" \"api_key must be provided or set as NOTION_API_KEY environment variable\"\n",
142+
" )\n",
143+
"\n",
132144
" return NotionClient(auth=api_key)"
133145
]
134146
},
@@ -179,9 +191,7 @@
179191
],
180192
"source": [
181193
"mock_notion_client = NotionClientFactory.create(\n",
182-
" use_mock=True, \n",
183-
" initialize_project=True, \n",
184-
" root_page_id=\"your_root_page_id\"\n",
194+
" use_mock=True, initialize_project=True, root_page_id=\"your_root_page_id\"\n",
185195
")\n",
186196
"mock_notion_client"
187197
]
@@ -192,27 +202,27 @@
192202
"metadata": {},
193203
"outputs": [],
194204
"source": [
195-
"#| export\n",
205+
"# | export\n",
196206
"class NotionBackendFactory:\n",
197207
" \"\"\"Factory for creating NotionBackend instances.\"\"\"\n",
198-
" \n",
208+
"\n",
199209
" @staticmethod\n",
200210
" def create(\n",
201211
" root_page_id: str,\n",
202212
" use_mock: bool = False,\n",
203213
" api_key: t.Optional[str] = None,\n",
204214
" initialize_project: bool = False,\n",
205-
" notion_client: t.Optional[t.Union[NotionClient, MockNotionClient]] = None\n",
215+
" notion_client: t.Optional[t.Union[NotionClient, MockNotionClient]] = None,\n",
206216
" ) -> NotionBackend:\n",
207217
" \"\"\"Create a NotionBackend instance.\n",
208-
" \n",
218+
"\n",
209219
" Args:\n",
210220
" root_page_id: The ID of the root page\n",
211221
" use_mock: If True, create a backend with a mock client\n",
212222
" api_key: Notion API key (only used for real client)\n",
213223
" initialize_project: If True and using mock, initialize project structure\n",
214224
" notion_client: Optional pre-configured Notion client\n",
215-
" \n",
225+
"\n",
216226
" Returns:\n",
217227
" NotionBackend: A backend instance with either real or mock client\n",
218228
" \"\"\"\n",
@@ -222,14 +232,11 @@
222232
" use_mock=use_mock,\n",
223233
" api_key=api_key,\n",
224234
" initialize_project=initialize_project,\n",
225-
" root_page_id=root_page_id\n",
235+
" root_page_id=root_page_id,\n",
226236
" )\n",
227-
" \n",
237+
"\n",
228238
" # Create and return the backend\n",
229-
" return NotionBackend(\n",
230-
" root_page_id=root_page_id,\n",
231-
" notion_client=notion_client\n",
232-
" )"
239+
" return NotionBackend(root_page_id=root_page_id, notion_client=notion_client)"
233240
]
234241
}
235242
],

0 commit comments

Comments
 (0)