Skip to content

Commit cf994a3

Browse files
authored
Merge pull request #21 from jjmachan/fix/api_token
some polish
2 parents 6022423 + 7aaf93b commit cf994a3

File tree

8 files changed

+90
-69
lines changed

8 files changed

+90
-69
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ $ pip install ragas_experimental
2222

2323
## Getting Started
2424

25-
First lets init a
25+
First do signup to [beta.app.ragas.io](https://beta.app.ragas.io/) and
26+
generate the App Token and put it in the as the env variable
27+
`RAGAS_APP_TOKEN`.
28+
29+
``` python
30+
import os
31+
# ideally you load this from a .env file so as to not commit it to the repo
32+
os.environ["RAGAS_APP_TOKEN"] = "api-key"
33+
```
34+
35+
Now lets init a
2636
[`Project`](https://explodinggradients.github.io/ragas_experimental/project/core.html#project)
27-
from notion.
37+
in the App
38+
39+
``` python
40+
from ragas_experimental import Project
41+
42+
project = Project.create("my-project")
43+
project
44+
```

nbs/backends/ragas_api_client.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"metadata": {},
2525
"outputs": [],
2626
"source": [
27-
"RAGAS_APP_TOKEN = \"apt.47bd-c55e4a45b27c-02f8-8446-1441f09b-651a8\"\n",
27+
"RAGAS_APP_TOKEN = \"api_key\"\n",
2828
"RAGAS_API_ENDPOINT = \"https://api.dev.app.ragas.io\""
2929
]
3030
},

nbs/dataset.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
"metadata": {},
247247
"outputs": [],
248248
"source": [
249-
"RAGAS_APP_TOKEN = \"apt.47bd-c55e4a45b27c-02f8-8446-1441f09b-651a8\"\n",
249+
"RAGAS_APP_TOKEN = \"api_key\"\n",
250250
"RAGAS_API_BASE_URL = \"https://api.dev.app.ragas.io\"\n",
251251
"\n",
252252
"os.environ[\"RAGAS_APP_TOKEN\"] = RAGAS_APP_TOKEN\n",
@@ -279,7 +279,7 @@
279279
}
280280
],
281281
"source": [
282-
"p = Project(project_id=\"3d9b529b-c23f-4e87-8a26-dd1923749aa7\", ragas_app_client=ragas_api_client)\n",
282+
"p = Project(project_id=\"3d9b529b-c23f-4e87-8a26-dd1923749aa7\", ragas_api_client=ragas_api_client)\n",
283283
"test_dataset = p.create_dataset(name=\"TestModel_with_long_text\", model=TestModel)\n",
284284
"test_dataset"
285285
]

nbs/index.ipynb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,37 @@
5757
"cell_type": "markdown",
5858
"metadata": {},
5959
"source": [
60-
"First lets init a `Project` from notion."
60+
"First do signup to [beta.app.ragas.io](https://beta.app.ragas.io/) and generate the App Token and put it in the as the env variable `RAGAS_APP_TOKEN`. "
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": null,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"import os\n",
70+
"# ideally you load this from a .env file so as to not commit it to the repo\n",
71+
"os.environ[\"RAGAS_APP_TOKEN\"] = \"api-key\""
72+
]
73+
},
74+
{
75+
"cell_type": "markdown",
76+
"metadata": {},
77+
"source": [
78+
"Now lets init a `Project` in the App"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": null,
84+
"metadata": {},
85+
"outputs": [],
86+
"source": [
87+
"from ragas_experimental import Project\n",
88+
"\n",
89+
"project = Project.create(\"my-project\")\n",
90+
"project"
6191
]
6292
}
6393
],

nbs/project/core.ipynb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@
7171
" def __init__(\n",
7272
" self,\n",
7373
" project_id: str,\n",
74-
" ragas_app_client: t.Optional[RagasApiClient] = None,\n",
74+
" ragas_api_client: t.Optional[RagasApiClient] = None,\n",
7575
" ):\n",
7676
" self.project_id = project_id\n",
77-
" if ragas_app_client is None:\n",
77+
" if ragas_api_client is None:\n",
7878
" self._ragas_api_client = RagasApiClientFactory.create()\n",
7979
" else:\n",
80-
" self._ragas_api_client = ragas_app_client\n",
80+
" self._ragas_api_client = ragas_api_client\n",
8181
"\n",
8282
" # create the project\n",
8383
" try:\n",
@@ -94,12 +94,12 @@
9494
" cls,\n",
9595
" name: str,\n",
9696
" description: str = \"\",\n",
97-
" ragas_app_client: t.Optional[RagasApiClient] = None,\n",
97+
" ragas_api_client: t.Optional[RagasApiClient] = None,\n",
9898
" ):\n",
99-
" ragas_app_client = RagasApiClientFactory.create()\n",
100-
" sync_version = async_to_sync(ragas_app_client.create_project)\n",
99+
" ragas_api_client = RagasApiClientFactory.create()\n",
100+
" sync_version = async_to_sync(ragas_api_client.create_project)\n",
101101
" new_project = sync_version(title=name, description=description)\n",
102-
" return cls(new_project[\"id\"], ragas_app_client)\n",
102+
" return cls(new_project[\"id\"], ragas_api_client)\n",
103103
"\n",
104104
" def delete(self):\n",
105105
" sync_version = async_to_sync(self._ragas_api_client.delete_project)\n",
@@ -116,7 +116,7 @@
116116
"metadata": {},
117117
"outputs": [],
118118
"source": [
119-
"RAGAS_APP_TOKEN = \"apt.47bd-c55e4a45b27c-02f8-8446-1441f09b-651a8\"\n",
119+
"RAGAS_APP_TOKEN = \"api-key\"\n",
120120
"RAGAS_API_BASE_URL = \"https://api.dev.app.ragas.io\"\n",
121121
"\n",
122122
"os.environ[\"RAGAS_APP_TOKEN\"] = RAGAS_APP_TOKEN\n",
@@ -153,22 +153,22 @@
153153
"source": [
154154
"# | export\n",
155155
"@patch(cls_method=True)\n",
156-
"def get(cls: Project, name: str, ragas_app_client: t.Optional[RagasApiClient] = None) -> Project:\n",
156+
"def get(cls: Project, name: str, ragas_api_client: t.Optional[RagasApiClient] = None) -> Project:\n",
157157
" \"\"\"Get an existing project by name.\"\"\"\n",
158158
" # Search for project with given name\n",
159-
" if ragas_app_client is None:\n",
160-
" ragas_app_client = RagasApiClientFactory.create()\n",
159+
" if ragas_api_client is None:\n",
160+
" ragas_api_client = RagasApiClientFactory.create()\n",
161161
"\n",
162162
" # get the project by name\n",
163-
" sync_version = async_to_sync(ragas_app_client.get_project_by_name)\n",
163+
" sync_version = async_to_sync(ragas_api_client.get_project_by_name)\n",
164164
" project_info = sync_version(\n",
165165
" project_name=name\n",
166166
" )\n",
167167
"\n",
168168
" # Return Project instance\n",
169169
" return Project(\n",
170170
" project_id=project_info[\"id\"],\n",
171-
" ragas_app_client=ragas_app_client,\n",
171+
" ragas_api_client=ragas_api_client,\n",
172172
" )"
173173
]
174174
},

nbs/project/experiments.ipynb

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
}
145145
],
146146
"source": [
147-
"RAGAS_APP_TOKEN = \"apt.4e81-99ed3e6efdfe-bb9c-88e3-f88438f5-5dfef\"\n",
147+
"RAGAS_APP_TOKEN = \"api-key\"\n",
148148
"RAGAS_API_BASE_URL = \"https://api.dev.app.ragas.io\"\n",
149149
"\n",
150150
"os.environ[\"RAGAS_APP_TOKEN\"] = RAGAS_APP_TOKEN\n",
@@ -458,32 +458,6 @@
458458
" return commit_hash"
459459
]
460460
},
461-
{
462-
"cell_type": "code",
463-
"execution_count": null,
464-
"metadata": {},
465-
"outputs": [
466-
{
467-
"name": "stdout",
468-
"output_type": "stream",
469-
"text": [
470-
"\u001b[31mSignature:\u001b[39m\n",
471-
"show_doc(\n",
472-
" sym,\n",
473-
" renderer=\u001b[38;5;28;01mNone\u001b[39;00m,\n",
474-
" name: \u001b[33m'str | None'\u001b[39m = \u001b[38;5;28;01mNone\u001b[39;00m,\n",
475-
" title_level: \u001b[33m'int'\u001b[39m = \u001b[32m3\u001b[39m,\n",
476-
")\n",
477-
"\u001b[31mDocstring:\u001b[39m Show signature and docstring for `sym`\n",
478-
"\u001b[31mFile:\u001b[39m ~/workspace/eglabs/ragas_annotator/.venv/lib/python3.12/site-packages/nbdev/showdoc.py\n",
479-
"\u001b[31mType:\u001b[39m function"
480-
]
481-
}
482-
],
483-
"source": [
484-
"show_doc?"
485-
]
486-
},
487461
{
488462
"cell_type": "code",
489463
"execution_count": null,
@@ -642,7 +616,7 @@
642616
"# | export\n",
643617
"@patch\n",
644618
"def experiment(\n",
645-
" self: Project, experiment_model, name_prefix: str = \"\", save_to_git: bool = True, stage_all: bool = False\n",
619+
" self: Project, experiment_model, name_prefix: str = \"\", save_to_git: bool = True, stage_all: bool = True\n",
646620
"):\n",
647621
" \"\"\"Decorator for creating experiment functions without Langfuse integration.\n",
648622
"\n",

ragas_experimental/project/core.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ class Project:
2525
def __init__(
2626
self,
2727
project_id: str,
28-
ragas_app_client: t.Optional[RagasApiClient] = None,
28+
ragas_api_client: t.Optional[RagasApiClient] = None,
2929
):
3030
self.project_id = project_id
31-
if ragas_app_client is None:
31+
if ragas_api_client is None:
3232
self._ragas_api_client = RagasApiClientFactory.create()
3333
else:
34-
self._ragas_api_client = ragas_app_client
34+
self._ragas_api_client = ragas_api_client
3535

3636
# create the project
3737
try:
@@ -48,12 +48,12 @@ def create(
4848
cls,
4949
name: str,
5050
description: str = "",
51-
ragas_app_client: t.Optional[RagasApiClient] = None,
51+
ragas_api_client: t.Optional[RagasApiClient] = None,
5252
):
53-
ragas_app_client = RagasApiClientFactory.create()
54-
sync_version = async_to_sync(ragas_app_client.create_project)
53+
ragas_api_client = RagasApiClientFactory.create()
54+
sync_version = async_to_sync(ragas_api_client.create_project)
5555
new_project = sync_version(title=name, description=description)
56-
return cls(new_project["id"], ragas_app_client)
56+
return cls(new_project["id"], ragas_api_client)
5757

5858
def delete(self):
5959
sync_version = async_to_sync(self._ragas_api_client.delete_project)
@@ -66,21 +66,21 @@ def __repr__(self):
6666
# %% ../../nbs/project/core.ipynb 8
6767
@patch(cls_method=True)
6868
def get(
69-
cls: Project, name: str, ragas_app_client: t.Optional[RagasApiClient] = None
69+
cls: Project, name: str, ragas_api_client: t.Optional[RagasApiClient] = None
7070
) -> Project:
7171
"""Get an existing project by name."""
7272
# Search for project with given name
73-
if ragas_app_client is None:
74-
ragas_app_client = RagasApiClientFactory.create()
73+
if ragas_api_client is None:
74+
ragas_api_client = RagasApiClientFactory.create()
7575

7676
# get the project by name
77-
sync_version = async_to_sync(ragas_app_client.get_project_by_name)
77+
sync_version = async_to_sync(ragas_api_client.get_project_by_name)
7878
project_info = sync_version(project_name=name)
7979

8080
# Return Project instance
8181
return Project(
8282
project_id=project_info["id"],
83-
ragas_app_client=ragas_app_client,
83+
ragas_api_client=ragas_api_client,
8484
)
8585

8686
# %% ../../nbs/project/core.ipynb 12

ragas_experimental/project/experiments.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def version_experiment(
202202

203203
return commit_hash
204204

205-
# %% ../../nbs/project/experiments.ipynb 22
205+
# %% ../../nbs/project/experiments.ipynb 21
206206
def cleanup_experiment_branches(
207207
prefix: str = "ragas/",
208208
repo_path: t.Union[str, Path, None] = None,
@@ -281,26 +281,26 @@ def cleanup_experiment_branches(
281281

282282
return deleted_branches
283283

284-
# %% ../../nbs/project/experiments.ipynb 25
284+
# %% ../../nbs/project/experiments.ipynb 24
285285
@t.runtime_checkable
286286
class ExperimentProtocol(t.Protocol):
287287
async def __call__(self, *args, **kwargs): ...
288288
async def run_async(self, name: str, dataset: Dataset): ...
289289

290-
# %% ../../nbs/project/experiments.ipynb 26
290+
# %% ../../nbs/project/experiments.ipynb 25
291291
from .naming import MemorableNames
292292

293-
# %% ../../nbs/project/experiments.ipynb 27
293+
# %% ../../nbs/project/experiments.ipynb 26
294294
memorable_names = MemorableNames()
295295

296-
# %% ../../nbs/project/experiments.ipynb 28
296+
# %% ../../nbs/project/experiments.ipynb 27
297297
@patch
298298
def experiment(
299299
self: Project,
300300
experiment_model,
301301
name_prefix: str = "",
302302
save_to_git: bool = True,
303-
stage_all: bool = False,
303+
stage_all: bool = True,
304304
):
305305
"""Decorator for creating experiment functions without Langfuse integration.
306306
@@ -400,11 +400,11 @@ async def run_async(
400400

401401
return decorator
402402

403-
# %% ../../nbs/project/experiments.ipynb 32
403+
# %% ../../nbs/project/experiments.ipynb 31
404404
# this one we have to clean up
405405
from langfuse.decorators import observe
406406

407-
# %% ../../nbs/project/experiments.ipynb 33
407+
# %% ../../nbs/project/experiments.ipynb 32
408408
@patch
409409
def langfuse_experiment(self: Project, experiment_model, name_prefix: str = ""):
410410
"""Decorator for creating experiment functions with Langfuse integration.
@@ -436,7 +436,7 @@ async def langfuse_wrapped_func(*args, **kwargs):
436436

437437
return decorator
438438

439-
# %% ../../nbs/project/experiments.ipynb 40
439+
# %% ../../nbs/project/experiments.ipynb 39
440440
from mlflow import trace
441441

442442

@@ -481,7 +481,7 @@ async def run_async_with_mlflow(dataset: Dataset, name: t.Optional[str] = None):
481481

482482
return decorator
483483

484-
# %% ../../nbs/project/experiments.ipynb 41
484+
# %% ../../nbs/project/experiments.ipynb 40
485485
import logging
486486
from ..utils import plot_experiments_as_subplots
487487

0 commit comments

Comments
 (0)