Skip to content

Commit 84b59c0

Browse files
authored
Merge pull request #19 from explodinggradients/ragas-experimental
merge experimental onto main
2 parents 2a29d04 + 87966c0 commit 84b59c0

Some content is hidden

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

87 files changed

+8895
-4751
lines changed

.github/workflows/test.yaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
name: CI
2-
on: [workflow_dispatch, pull_request, push]
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
38

49
jobs:
510
test:
611
runs-on: ubuntu-latest
7-
steps: [uses: fastai/workflows/nbdev-ci@master]
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-python@v4
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- uses: fastai/workflows/nbdev-ci@master

.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

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ragas_annotator
1+
# Ragas Experimental
22

33

44
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
@@ -8,16 +8,16 @@
88
### Installation
99

1010
Install latest from the GitHub
11-
[repository](https://github.com/explodinggradients/ragas_annotator):
11+
[repository](https://github.com/explodinggradients/ragas_experimental):
1212

1313
``` sh
14-
$ pip install git+https://github.com/explodinggradients/ragas_annotator.git
14+
$ pip install git+https://github.com/explodinggradients/ragas_experimental.git
1515
```
1616

17-
or from [pypi](https://pypi.org/project/ragas_annotator/)
17+
or from [pypi](https://pypi.org/project/ragas_experimental/)
1818

1919
``` sh
20-
$ pip install ragas_annotator
20+
$ pip install ragas_experimental
2121
```
2222

2323
## Getting Started
File renamed without changes.

nbs/backends/factory.ipynb

Lines changed: 21 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
"metadata": {},
2525
"outputs": [],
2626
"source": [
27-
"# | export\n",
27+
"#| export\n",
2828
"import typing as t\n",
2929
"import os\n",
3030
"\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"
31+
"from ragas_experimental.backends.ragas_api_client import RagasApiClient"
3432
]
3533
},
3634
{
@@ -39,204 +37,37 @@
3937
"metadata": {},
4038
"outputs": [],
4139
"source": [
42-
"# | export\n",
43-
"class NotionClientFactory:\n",
44-
" \"\"\"Factory for creating Notion client instances.\"\"\"\n",
40+
"#| export\n",
41+
"class RagasApiClientFactory:\n",
42+
" \"\"\"Factory for creating Ragas API client instances.\"\"\"\n",
4543
"\n",
4644
" @staticmethod\n",
4745
" 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",
46+
" app_token: t.Optional[str] = None,\n",
47+
" base_url: t.Optional[str] = None,\n",
48+
" ) -> RagasApiClient:\n",
49+
" \"\"\"Create a Ragas API client.\n",
5450
"\n",
5551
" 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",
52+
" api_key: The API key for the Ragas API\n",
53+
" base_url: The base URL for the Ragas API\n",
6054
"\n",
6155
" Returns:\n",
62-
" Union[NotionClient, MockNotionClient]: A real or mock client\n",
56+
" RagasApiClient: A Ragas API client instance\n",
6357
" \"\"\"\n",
64-
" if use_mock:\n",
65-
" client = MockNotionClient()\n",
58+
" if app_token is None:\n",
59+
" app_token = os.getenv(\"RAGAS_APP_TOKEN\")\n",
6660
"\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",
61+
" if app_token is None:\n",
62+
" raise ValueError(\"RAGAS_API_KEY environment variable is not set\")\n",
9263
"\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",
64+
" if base_url is None:\n",
65+
" base_url = os.getenv(\"RAGAS_API_BASE_URL\")\n",
9766
"\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",
67+
" if base_url is None:\n",
68+
" base_url = \"https://api.dev.app.ragas.io\"\n",
12069
"\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)"
70+
" return RagasApiClient(app_token=app_token, base_url=base_url)\n"
24071
]
24172
}
24273
],

0 commit comments

Comments
 (0)