Skip to content

Commit 866c662

Browse files
authored
Scrubbed the references to app.ragas.io (#2207)
## Issue Link / Problem Description Scrubbed the references to app.ragas.io
1 parent 6136e12 commit 866c662

File tree

5 files changed

+13
-362
lines changed

5 files changed

+13
-362
lines changed

src/ragas/dataset_schema.py

Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,11 @@
99
from uuid import UUID
1010

1111
import numpy as np
12-
import requests
13-
from datasets import Dataset as HFDataset
1412
from pydantic import BaseModel, field_validator
1513

16-
from ragas._version import __version__
17-
from ragas.callbacks import ChainRunEncoder, parse_run_traces
14+
from ragas.callbacks import parse_run_traces
1815
from ragas.cost import CostCallbackHandler
19-
from ragas.exceptions import UploadException
2016
from ragas.messages import AIMessage, HumanMessage, ToolCall, ToolMessage
21-
from ragas.sdk import (
22-
RAGAS_API_SOURCE,
23-
build_evaluation_app_url,
24-
check_api_response,
25-
get_api_url,
26-
get_app_token,
27-
get_app_url,
28-
upload_packet,
29-
)
3017
from ragas.utils import safe_nanmean
3118

3219
if t.TYPE_CHECKING:
@@ -537,48 +524,6 @@ def total_cost(
537524
cost_per_input_token, cost_per_output_token, per_model_costs
538525
)
539526

540-
def upload(
541-
self,
542-
verbose: bool = True,
543-
) -> str:
544-
from datetime import datetime, timezone
545-
546-
timestamp = datetime.now(timezone.utc).isoformat()
547-
root_trace = [
548-
trace for trace in self.ragas_traces.values() if trace.parent_run_id is None
549-
][0]
550-
packet = json.dumps(
551-
{
552-
"run_id": str(root_trace.run_id),
553-
"created_at": timestamp,
554-
"evaluation_run": [t.model_dump() for t in self.ragas_traces.values()],
555-
},
556-
cls=ChainRunEncoder,
557-
)
558-
response = upload_packet(
559-
path="/alignment/evaluation",
560-
data_json_string=packet,
561-
)
562-
563-
# check status codes
564-
app_url = get_app_url()
565-
evaluation_app_url = build_evaluation_app_url(app_url, root_trace.run_id)
566-
if response.status_code == 409:
567-
# this evalution already exists
568-
if verbose:
569-
print(f"Evaluation run already exists. View at {evaluation_app_url}")
570-
return evaluation_app_url
571-
elif response.status_code != 200:
572-
# any other error
573-
raise UploadException(
574-
status_code=response.status_code,
575-
message=f"Failed to upload results: {response.text}",
576-
)
577-
578-
if verbose:
579-
print(f"Evaluation results uploaded! View at {evaluation_app_url}")
580-
return evaluation_app_url
581-
582527

583528
class PromptAnnotation(BaseModel):
584529
prompt_input: t.Dict[str, t.Any]
@@ -642,63 +587,6 @@ def from_json(cls, path: str, metric_name: t.Optional[str]) -> "MetricAnnotation
642587
dataset = json.load(open(path))
643588
return cls._process_dataset(dataset, metric_name)
644589

645-
@classmethod
646-
def from_app(
647-
cls,
648-
run_id: str,
649-
metric_name: t.Optional[str] = None,
650-
) -> "MetricAnnotation":
651-
"""
652-
Fetch annotations from a URL using either evaluation result or run_id
653-
654-
Parameters
655-
----------
656-
run_id : str
657-
Direct run ID to fetch annotations
658-
metric_name : str, optional
659-
Name of the specific metric to filter
660-
661-
Returns
662-
-------
663-
MetricAnnotation
664-
Annotation data from the API
665-
666-
Raises
667-
------
668-
ValueError
669-
If run_id is not provided
670-
"""
671-
if run_id is None:
672-
raise ValueError("run_id must be provided")
673-
674-
endpoint = f"/api/v1/alignment/evaluation/annotation/{run_id}"
675-
676-
app_token = get_app_token()
677-
base_url = get_api_url()
678-
app_url = get_app_url()
679-
680-
response = requests.get(
681-
f"{base_url}{endpoint}",
682-
headers={
683-
"Content-Type": "application/json",
684-
"x-app-token": app_token,
685-
"x-source": RAGAS_API_SOURCE,
686-
"x-app-version": __version__,
687-
},
688-
)
689-
690-
check_api_response(response)
691-
dataset = response.json()["data"]
692-
693-
if not dataset:
694-
evaluation_url = build_evaluation_app_url(app_url, run_id)
695-
raise ValueError(
696-
f"No annotations found. Please annotate the Evaluation first then run this method. "
697-
f"\nNote: you can annotate the evaluations using the Ragas app by going to {evaluation_url}"
698-
)
699-
700-
return cls._process_dataset(dataset, metric_name)
701-
702590
def __len__(self):
703591
return sum(len(value) for value in self.root.values())
704592

src/ragas/exceptions.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,6 @@ def __init__(self):
4141
super().__init__(msg)
4242

4343

44-
class UploadException(RagasException):
45-
"""
46-
Exception raised when the app fails to upload the results.
47-
"""
48-
49-
def __init__(self, status_code: int, message: str):
50-
self.status_code = status_code
51-
super().__init__(message)
52-
53-
5444
# Exceptions migrated from experimental module
5545
class RagasError(Exception):
5646
"""Base class for all Ragas-related exceptions."""

src/ragas/metrics/base.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,7 @@ def _optimize_demonstration(
344344

345345
def train(
346346
self,
347-
path: t.Optional[str] = None,
348-
run_id: t.Optional[str] = None,
347+
path: str,
349348
demonstration_config: t.Optional[DemonstrationConfig] = None,
350349
instruction_config: t.Optional[InstructionConfig] = None,
351350
callbacks: t.Optional[Callbacks] = None,
@@ -355,14 +354,12 @@ def train(
355354
raise_exceptions: bool = True,
356355
) -> None:
357356
"""
358-
Train the metric using local JSON data or annotations from Ragas platform
357+
Train the metric using local JSON data
359358
360359
Parameters
361360
----------
362-
path : str, optional
361+
path : str
363362
Path to local JSON training data file
364-
run_id : str, optional
365-
Direct run ID to fetch annotations
366363
demonstration_config : DemonstrationConfig, optional
367364
Configuration for demonstration optimization
368365
instruction_config : InstructionConfig, optional
@@ -381,30 +378,20 @@ def train(
381378
Raises
382379
------
383380
ValueError
384-
If invalid combination of path, and run_id is provided
381+
If path is not provided or not a JSON file
385382
"""
386383
# Validate input parameters
387-
provided_inputs = sum(x is not None for x in [path, run_id])
388-
if provided_inputs == 0:
389-
raise ValueError("One of path or run_id must be provided")
390-
if provided_inputs > 1:
391-
raise ValueError("Only one of path or run_id should be provided")
384+
if not path:
385+
raise ValueError("Path to training data file must be provided")
386+
387+
if not path.endswith(".json"):
388+
raise ValueError("Train data must be in json format")
392389

393390
run_config = run_config or RunConfig()
394391
callbacks = callbacks or []
395392

396-
# Load the dataset based on input type
397-
if path is not None:
398-
if not path.endswith(".json"):
399-
raise ValueError("Train data must be in json format")
400-
dataset = MetricAnnotation.from_json(path, metric_name=self.name)
401-
elif run_id is not None:
402-
dataset = MetricAnnotation.from_app(
403-
run_id=run_id,
404-
metric_name=self.name,
405-
)
406-
else:
407-
raise ValueError("One of path or run_id must be provided")
393+
# Load the dataset from JSON file
394+
dataset = MetricAnnotation.from_json(path, metric_name=self.name)
408395

409396
# only optimize the instruction if instruction_config is provided
410397
if instruction_config is not None:

0 commit comments

Comments
 (0)