Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
455 changes: 380 additions & 75 deletions nbs/backends/ragas_api_client.ipynb

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions nbs/exceptions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
"# | default_exp exceptions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"class RagasError(Exception):\n",
" \"\"\"Base class for all Ragas-related exceptions.\"\"\"\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -42,6 +54,56 @@
"\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"\n",
"class ResourceNotFoundError(RagasError):\n",
" \"\"\"Exception raised when a requested resource doesn't exist.\"\"\"\n",
" pass\n",
"\n",
"class ProjectNotFoundError(ResourceNotFoundError):\n",
" \"\"\"Exception raised when a project doesn't exist.\"\"\"\n",
" pass\n",
"\n",
"class DatasetNotFoundError(ResourceNotFoundError):\n",
" \"\"\"Exception raised when a dataset doesn't exist.\"\"\"\n",
" pass\n",
"\n",
"class ExperimentNotFoundError(ResourceNotFoundError):\n",
" \"\"\"Exception raised when an experiment doesn't exist.\"\"\"\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"\n",
"class DuplicateResourceError(RagasError):\n",
" \"\"\"Exception raised when multiple resources exist with the same identifier.\"\"\"\n",
" pass\n",
"\n",
"class DuplicateProjectError(DuplicateResourceError):\n",
" \"\"\"Exception raised when multiple projects exist with the same name.\"\"\"\n",
" pass\n",
"\n",
"class DuplicateDatasetError(DuplicateResourceError):\n",
" \"\"\"Exception raised when multiple datasets exist with the same name.\"\"\"\n",
" pass\n",
"\n",
"class DuplicateExperimentError(DuplicateResourceError):\n",
" \"\"\"Exception raised when multiple experiments exist with the same name.\"\"\"\n",
" pass"
]
}
],
"metadata": {
Expand Down
93 changes: 80 additions & 13 deletions nbs/project/core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,53 @@
"project"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# | export\n",
"@patch(cls_method=True)\n",
"def get(cls: Project, name: str, ragas_app_client: t.Optional[RagasApiClient] = None) -> Project:\n",
" \"\"\"Get an existing project by name.\"\"\"\n",
" # Search for project with given name\n",
" if ragas_app_client is None:\n",
" ragas_app_client = RagasApiClientFactory.create()\n",
"\n",
" # get the project by name\n",
" sync_version = async_to_sync(ragas_app_client.get_project_by_name)\n",
" project_info = sync_version(\n",
" project_name=name\n",
" )\n",
"\n",
" # Return Project instance\n",
" return Project(\n",
" project_id=project_info[\"id\"],\n",
" ragas_app_client=ragas_app_client,\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Project(name='SuperMe')"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Project.get(\"SuperMe\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -268,7 +315,7 @@
{
"data": {
"text/plain": [
"'bbe45632-3268-43a6-9694-b020b3f5226f'"
"'3d9b529b-c23f-4e87-8a26-dd1923749aa7'"
]
},
"execution_count": null,
Expand All @@ -288,7 +335,7 @@
{
"data": {
"text/plain": [
"'0fee5330-9f6e-44a9-a85c-e3b947b697de'"
"'5f7839e7-f4f9-4ada-9082-bc1c5528c259'"
]
},
"execution_count": null,
Expand All @@ -308,7 +355,7 @@
"source": [
"# | export\n",
"@patch\n",
"def get_dataset(self: Project, dataset_id: str, model) -> Dataset:\n",
"def get_dataset_by_id(self: Project, dataset_id: str, model) -> Dataset:\n",
" \"\"\"Get an existing dataset by name.\"\"\"\n",
" # Search for database with given name\n",
" sync_version = async_to_sync(self._ragas_api_client.get_dataset)\n",
Expand Down Expand Up @@ -344,7 +391,34 @@
}
],
"source": [
"project.get_dataset(test_dataset.dataset_id, TestModel)"
"project.get_dataset_by_id(test_dataset.dataset_id, TestModel)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# | export\n",
"@patch\n",
"def get_dataset(self: Project, dataset_name: str, model) -> Dataset:\n",
" \"\"\"Get an existing dataset by name.\"\"\"\n",
" # Search for dataset with given name\n",
" sync_version = async_to_sync(self._ragas_api_client.get_dataset_by_name)\n",
" dataset_info = sync_version(\n",
" project_id=self.project_id,\n",
" dataset_name=dataset_name\n",
" )\n",
"\n",
" # Return Dataset instance\n",
" return Dataset(\n",
" name=dataset_info[\"name\"],\n",
" model=model,\n",
" project_id=self.project_id,\n",
" dataset_id=dataset_info[\"id\"],\n",
" ragas_api_client=self._ragas_api_client,\n",
" )"
]
},
{
Expand All @@ -355,7 +429,7 @@
{
"data": {
"text/plain": [
"'0a7c4ecb-b313-4bb0-81c0-852c9634ce03'"
"Dataset(name=TestModel, model=TestModel, len=0)"
]
},
"execution_count": null,
Expand All @@ -364,15 +438,8 @@
}
],
"source": [
"project.project_id"
"project.get_dataset(\"TestModel\", TestModel)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading