Skip to content

Commit c85d340

Browse files
authored
Merge pull request #8 from explodinggradients/feat/complete-sdk
feat: complete sdk as per the `v3: Ragas App UI` spec
2 parents 2a29d04 + c2fad51 commit c85d340

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+4289
-4324
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,4 @@ cython_debug/
172172
.python-version
173173
uv.lock
174174
_proc
175+
experiments
File renamed without changes.

nbs/backends/factory.ipynb

Lines changed: 21 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@
2424
"metadata": {},
2525
"outputs": [],
2626
"source": [
27-
"# | export\n",
27+
"#| export\n",
2828
"import typing as t\n",
29-
"import os\n",
3029
"\n",
31-
"from notion_client import Client as NotionClient\n",
32-
"from ragas_annotator.backends.mock_notion import MockNotionClient\n",
33-
"from ragas_annotator.backends.notion_backend import NotionBackend"
30+
"from ragas_experimental.backends.ragas_api_client import RagasApiClient"
3431
]
3532
},
3633
{
@@ -39,204 +36,37 @@
3936
"metadata": {},
4037
"outputs": [],
4138
"source": [
42-
"# | export\n",
43-
"class NotionClientFactory:\n",
44-
" \"\"\"Factory for creating Notion client instances.\"\"\"\n",
39+
"#| export\n",
40+
"class RagasApiClientFactory:\n",
41+
" \"\"\"Factory for creating Ragas API client instances.\"\"\"\n",
4542
"\n",
4643
" @staticmethod\n",
4744
" def create(\n",
48-
" use_mock: bool = False,\n",
49-
" api_key: t.Optional[str] = None,\n",
50-
" initialize_project: bool = False,\n",
51-
" root_page_id: t.Optional[str] = None,\n",
52-
" ) -> t.Union[NotionClient, MockNotionClient]:\n",
53-
" \"\"\"Create a Notion client.\n",
45+
" app_token: t.Optional[str] = None,\n",
46+
" base_url: t.Optional[str] = None,\n",
47+
" ) -> RagasApiClient:\n",
48+
" \"\"\"Create a Ragas API client.\n",
5449
"\n",
5550
" Args:\n",
56-
" use_mock: If True, create a mock client\n",
57-
" api_key: Notion API key (only used for real client)\n",
58-
" initialize_project: If True and using mock, initialize project structure\n",
59-
" root_page_id: Required if initialize_project is True\n",
51+
" api_key: The API key for the Ragas API\n",
52+
" base_url: The base URL for the Ragas API\n",
6053
"\n",
6154
" Returns:\n",
62-
" Union[NotionClient, MockNotionClient]: A real or mock client\n",
55+
" RagasApiClient: A Ragas API client instance\n",
6356
" \"\"\"\n",
64-
" if use_mock:\n",
65-
" client = MockNotionClient()\n",
57+
" if app_token is None:\n",
58+
" app_token = os.getenv(\"RAGAS_APP_TOKEN\")\n",
6659
"\n",
67-
" # Optionally initialize project structure\n",
68-
" if initialize_project and root_page_id:\n",
69-
" # Create root page if it doesn't exist in the mock client\n",
70-
" if root_page_id not in client._pages:\n",
71-
" # Create root page\n",
72-
" root_page = {\n",
73-
" \"id\": root_page_id,\n",
74-
" \"object\": \"page\",\n",
75-
" \"created_time\": client._get_timestamp(),\n",
76-
" \"last_edited_time\": client._get_timestamp(),\n",
77-
" \"archived\": False,\n",
78-
" \"properties\": {\n",
79-
" \"title\": {\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",
88-
" }\n",
89-
" },\n",
90-
" }\n",
91-
" client.add_page(root_page)\n",
60+
" if app_token is None:\n",
61+
" raise ValueError(\"RAGAS_API_KEY environment variable is not set\")\n",
9262
"\n",
93-
" # Create required sub-pages\n",
94-
" for page_name in [\"Datasets\", \"Experiments\", \"Comparisons\"]:\n",
95-
" # Create page ID\n",
96-
" page_id = client._create_id()\n",
63+
" if base_url is None:\n",
64+
" base_url = os.getenv(\"RAGAS_API_BASE_URL\")\n",
9765
"\n",
98-
" # Create page\n",
99-
" page = {\n",
100-
" \"id\": page_id,\n",
101-
" \"object\": \"page\",\n",
102-
" \"created_time\": client._get_timestamp(),\n",
103-
" \"last_edited_time\": client._get_timestamp(),\n",
104-
" \"archived\": False,\n",
105-
" \"properties\": {\n",
106-
" \"title\": {\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",
115-
" }\n",
116-
" },\n",
117-
" \"parent\": {\"type\": \"page_id\", \"page_id\": root_page_id},\n",
118-
" }\n",
119-
" client.add_page(page)\n",
66+
" if base_url is None:\n",
67+
" base_url = \"https://api.dev.app.ragas.io\"\n",
12068
"\n",
121-
" # Add child block to root\n",
122-
" child_block = {\n",
123-
" \"id\": client._create_id(),\n",
124-
" \"object\": \"block\",\n",
125-
" \"type\": \"child_page\",\n",
126-
" \"created_time\": client._get_timestamp(),\n",
127-
" \"last_edited_time\": client._get_timestamp(),\n",
128-
" \"child_page\": {\"title\": page_name},\n",
129-
" }\n",
130-
"\n",
131-
" client.add_children(root_page_id, [child_block])\n",
132-
"\n",
133-
" return client\n",
134-
" else:\n",
135-
" # For real client, use provided API key or environment variable\n",
136-
" if api_key is None:\n",
137-
" api_key = os.getenv(\"NOTION_API_KEY\")\n",
138-
"\n",
139-
" if api_key is None:\n",
140-
" raise ValueError(\n",
141-
" \"api_key must be provided or set as NOTION_API_KEY environment variable\"\n",
142-
" )\n",
143-
"\n",
144-
" return NotionClient(auth=api_key)"
145-
]
146-
},
147-
{
148-
"cell_type": "code",
149-
"execution_count": null,
150-
"metadata": {},
151-
"outputs": [
152-
{
153-
"data": {
154-
"text/plain": [
155-
"MockNotionClient(num_pages=0, num_databases=0, num_blocks=0)"
156-
]
157-
},
158-
"execution_count": null,
159-
"metadata": {},
160-
"output_type": "execute_result"
161-
}
162-
],
163-
"source": [
164-
"# create the mock notion client\n",
165-
"mock_notion_client = NotionClientFactory.create(use_mock=True)\n",
166-
"mock_notion_client"
167-
]
168-
},
169-
{
170-
"cell_type": "markdown",
171-
"metadata": {},
172-
"source": [
173-
"the `initialize_project` adds the project pages too for you."
174-
]
175-
},
176-
{
177-
"cell_type": "code",
178-
"execution_count": null,
179-
"metadata": {},
180-
"outputs": [
181-
{
182-
"data": {
183-
"text/plain": [
184-
"MockNotionClient(num_pages=4, num_databases=0, num_blocks=0)"
185-
]
186-
},
187-
"execution_count": null,
188-
"metadata": {},
189-
"output_type": "execute_result"
190-
}
191-
],
192-
"source": [
193-
"mock_notion_client = NotionClientFactory.create(\n",
194-
" use_mock=True, initialize_project=True, root_page_id=\"your_root_page_id\"\n",
195-
")\n",
196-
"mock_notion_client"
197-
]
198-
},
199-
{
200-
"cell_type": "code",
201-
"execution_count": null,
202-
"metadata": {},
203-
"outputs": [],
204-
"source": [
205-
"# | export\n",
206-
"class NotionBackendFactory:\n",
207-
" \"\"\"Factory for creating NotionBackend instances.\"\"\"\n",
208-
"\n",
209-
" @staticmethod\n",
210-
" def create(\n",
211-
" root_page_id: str,\n",
212-
" use_mock: bool = False,\n",
213-
" api_key: t.Optional[str] = None,\n",
214-
" initialize_project: bool = False,\n",
215-
" notion_client: t.Optional[t.Union[NotionClient, MockNotionClient]] = None,\n",
216-
" ) -> NotionBackend:\n",
217-
" \"\"\"Create a NotionBackend instance.\n",
218-
"\n",
219-
" Args:\n",
220-
" root_page_id: The ID of the root page\n",
221-
" use_mock: If True, create a backend with a mock client\n",
222-
" api_key: Notion API key (only used for real client)\n",
223-
" initialize_project: If True and using mock, initialize project structure\n",
224-
" notion_client: Optional pre-configured Notion client\n",
225-
"\n",
226-
" Returns:\n",
227-
" NotionBackend: A backend instance with either real or mock client\n",
228-
" \"\"\"\n",
229-
" # Use provided client or create one\n",
230-
" if notion_client is None:\n",
231-
" notion_client = NotionClientFactory.create(\n",
232-
" use_mock=use_mock,\n",
233-
" api_key=api_key,\n",
234-
" initialize_project=initialize_project,\n",
235-
" root_page_id=root_page_id,\n",
236-
" )\n",
237-
"\n",
238-
" # Create and return the backend\n",
239-
" return NotionBackend(root_page_id=root_page_id, notion_client=notion_client)"
69+
" return RagasApiClient(app_token=app_token, base_url=base_url)\n"
24070
]
24171
}
24272
],

0 commit comments

Comments
 (0)