Skip to content

Commit 9124ef9

Browse files
committed
added longText as default text and fixed a bug in MetricResult
1 parent 86773b9 commit 9124ef9

File tree

9 files changed

+134
-374
lines changed

9 files changed

+134
-374
lines changed

nbs/backends/ragas_api_client.ipynb

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -704,25 +704,7 @@
704704
"outputs": [],
705705
"source": [
706706
"#| export\n",
707-
"from enum import Enum"
708-
]
709-
},
710-
{
711-
"cell_type": "code",
712-
"execution_count": null,
713-
"metadata": {},
714-
"outputs": [],
715-
"source": [
716-
"#| export\n",
717-
"class ColumnType(str, Enum):\n",
718-
" NUMBER = \"number\"\n",
719-
" TEXT = \"text\"\n",
720-
" LONG_TEXT = \"longText\"\n",
721-
" SELECT = \"select\"\n",
722-
" DATE = \"date\"\n",
723-
" MULTI_SELECT = \"multiSelect\"\n",
724-
" CHECKBOX = \"checkbox\"\n",
725-
" CUSTOM = \"custom\""
707+
"from ragas_experimental.typing import ColumnType"
726708
]
727709
},
728710
{

nbs/dataset.ipynb

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261
{
262262
"data": {
263263
"text/plain": [
264-
"Dataset(name=TestModel, model=TestModel, len=0)"
264+
"Dataset(name=TestModel_with_long_text, model=TestModel, len=0)"
265265
]
266266
},
267267
"execution_count": null,
@@ -271,7 +271,7 @@
271271
],
272272
"source": [
273273
"p = Project(project_id=\"1ef0843b-231f-4a2c-b64d-d39bcee9d830\", ragas_app_client=ragas_api_client)\n",
274-
"test_dataset = p.create_dataset(name=\"TestModel\", model=TestModel)\n",
274+
"test_dataset = p.create_dataset(name=\"TestModel_with_long_text\", model=TestModel)\n",
275275
"test_dataset"
276276
]
277277
},
@@ -283,11 +283,11 @@
283283
{
284284
"data": {
285285
"text/plain": [
286-
"{'id': '9375149c-20ce-4f07-9b2e-ebca6d00ea0c',\n",
287-
" 'name': 'TestModel',\n",
286+
"{'id': 'a7bd8b1f-dc29-4ae0-b1e5-24f0dfb76f7a',\n",
287+
" 'name': 'TestModel_with_long_text',\n",
288288
" 'description': None,\n",
289-
" 'created_at': '2025-04-15T19:02:22.275691+00:00',\n",
290-
" 'updated_at': '2025-04-15T19:02:22.275691+00:00',\n",
289+
" 'created_at': '2025-04-16T00:02:58.149112+00:00',\n",
290+
" 'updated_at': '2025-04-16T00:02:58.149112+00:00',\n",
291291
" 'version_counter': 0,\n",
292292
" 'project_id': '1ef0843b-231f-4a2c-b64d-d39bcee9d830'}"
293293
]
@@ -306,6 +306,31 @@
306306
"test_dataset"
307307
]
308308
},
309+
{
310+
"cell_type": "code",
311+
"execution_count": null,
312+
"metadata": {},
313+
"outputs": [
314+
{
315+
"data": {
316+
"text/plain": [
317+
"{'items': [],\n",
318+
" 'pagination': {'offset': 0,\n",
319+
" 'limit': 50,\n",
320+
" 'total': 0,\n",
321+
" 'order_by': 'created_at',\n",
322+
" 'sort_dir': 'asc'}}"
323+
]
324+
},
325+
"execution_count": null,
326+
"metadata": {},
327+
"output_type": "execute_result"
328+
}
329+
],
330+
"source": [
331+
"await ragas_api_client.list_dataset_rows(project_id=TEST_PROJECT_ID, dataset_id=TEST_DATASET_ID)"
332+
]
333+
},
309334
{
310335
"cell_type": "code",
311336
"execution_count": null,
@@ -325,11 +350,11 @@
325350
{
326351
"data": {
327352
"text/plain": [
328-
"{'id': 'g01hEImX5RLW',\n",
329-
" 'name': 'eBUi7lksCjTg',\n",
330-
" 'description': 'cCax9o3Mv6vQ',\n",
331-
" 'result': 'dJMynwKvhdaj',\n",
332-
" 'result_reason': 'dxuafEzCImGW'}"
353+
"{'id': 'eCYjJtBbLSDL',\n",
354+
" 'name': '1sfEb8iJ1TUg',\n",
355+
" 'description': 'gYsqmPXHbOyy',\n",
356+
" 'result': 'cAZanmY0CwWT',\n",
357+
" 'result_reason': 'e7IgZXICkmhA'}"
333358
]
334359
},
335360
"execution_count": null,
@@ -395,7 +420,7 @@
395420
{
396421
"data": {
397422
"text/plain": [
398-
"2"
423+
"1"
399424
]
400425
},
401426
"execution_count": null,

nbs/metric/result.ipynb

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,26 @@
303303
" \"reason\": self.reason,\n",
304304
" }\n",
305305
"\n",
306-
"# Add Pydantic compatibility methods\n",
307306
"@patch(cls_method=True)\n",
308307
"def __get_pydantic_core_schema__(\n",
309308
" cls: MetricResult, \n",
310309
" _source_type: t.Any, \n",
311310
" _handler: GetCoreSchemaHandler\n",
312311
") -> core_schema.CoreSchema:\n",
313-
" \"\"\"Generate a Pydantic core schema for MetricResult.\"\"\"\n",
314-
" # Create a schema that handles both validation and serialization\n",
312+
" \"\"\"Generate a Pydantic core schema for MetricResult.\n",
313+
" \n",
314+
" This custom schema handles different serialization behaviors:\n",
315+
" - For model_dump(): Returns the original MetricResult instance\n",
316+
" - For model_dump_json(): Converts to a JSON-compatible dict using __json__\n",
317+
" \"\"\"\n",
318+
" def serializer_function(instance, info):\n",
319+
" \"\"\"Handle different serialization modes for MetricResult.\"\"\"\n",
320+
" # For JSON serialization (model_dump_json), use __json__ method\n",
321+
" if getattr(info, 'mode', None) == 'json':\n",
322+
" return instance.__json__()\n",
323+
" # For Python serialization (model_dump), return the instance itself\n",
324+
" return instance\n",
325+
" \n",
315326
" return core_schema.union_schema([\n",
316327
" # First schema: handles validation of MetricResult instances\n",
317328
" core_schema.is_instance_schema(MetricResult),\n",
@@ -324,15 +335,9 @@
324335
" ),\n",
325336
" ]),\n",
326337
" ], serialization=core_schema.plain_serializer_function_ser_schema(\n",
327-
" # This function handles serialization\n",
328-
" lambda instance: instance.__json__()\n",
329-
" ))\n",
330-
"\n",
331-
"\n",
332-
"@patch\n",
333-
"def model_dump(self: MetricResult):\n",
334-
" \"\"\"Support Pydantic's model_dump method.\"\"\"\n",
335-
" return self.to_dict()"
338+
" serializer_function,\n",
339+
" info_arg=True # Explicitly specify that we're using the info argument\n",
340+
" ))"
336341
]
337342
},
338343
{
@@ -381,7 +386,7 @@
381386
{
382387
"data": {
383388
"text/plain": [
384-
"{'result': 1, 'reason': 'test'}"
389+
"{'response': 'test', 'grade': 1, 'faithfulness': 1}"
385390
]
386391
},
387392
"execution_count": null,
@@ -390,13 +395,13 @@
390395
}
391396
],
392397
"source": [
393-
"m.grade.model_dump()"
398+
"m.model_dump()"
394399
]
395400
},
396401
{
397402
"cell_type": "code",
398403
"execution_count": null,
399-
"id": "27f9bc1c",
404+
"id": "0bc2a1ec",
400405
"metadata": {},
401406
"outputs": [
402407
{
@@ -411,9 +416,7 @@
411416
}
412417
],
413418
"source": [
414-
"mt = TestModel(response=\"test\", grade=MetricResult(result=1, reason=\"test\"), faithfulness=MetricResult(result=1, reason=\"test\"))\n",
415-
"\n",
416-
"mt.model_dump_json()"
419+
"m.model_dump_json()"
417420
]
418421
}
419422
],

0 commit comments

Comments
 (0)