2
2
import csv
3
3
import datetime
4
4
import json
5
- from rich .console import Console
6
- from rich .progress import Progress , SpinnerColumn , TextColumn
7
- import requests
8
5
from dataclasses import dataclass , field
9
6
import os
10
7
from typing import List , Optional , Union , Literal
11
8
12
- from judgeval .constants import JUDGMENT_DATASETS_PUSH_API_URL , JUDGMENT_DATASETS_PULL_API_URL
13
9
from judgeval .data .datasets .ground_truth import GroundTruthExample
14
- from judgeval .data .datasets .utils import ground_truths_to_examples , examples_to_ground_truths
15
10
from judgeval .data import Example
16
11
from judgeval .common .logger import debug , error , warning , info
17
12
@@ -37,120 +32,6 @@ def __init__(self,
37
32
self ._id = None
38
33
self .judgment_api_key = judgment_api_key
39
34
40
- def push (self , alias : str , overwrite : Optional [bool ] = False ) -> bool :
41
- debug (f"Pushing dataset with alias '{ alias } ' (overwrite={ overwrite } )" )
42
- if overwrite :
43
- warning (f"Overwrite enabled for alias '{ alias } '" )
44
- """
45
- Pushes the dataset to Judgment platform
46
-
47
- Mock request:
48
- {
49
- "alias": alias,
50
- "ground_truths": [...],
51
- "examples": [...],
52
- "overwrite": overwrite
53
- } ==>
54
- {
55
- "_alias": alias,
56
- "_id": "..." # ID of the dataset
57
- }
58
- """
59
- with Progress (
60
- SpinnerColumn (style = "rgb(106,0,255)" ),
61
- TextColumn ("[progress.description]{task.description}" ),
62
- transient = False ,
63
- ) as progress :
64
- task_id = progress .add_task (
65
- f"Pushing [rgb(106,0,255)]'{ alias } ' to Judgment..." ,
66
- total = 100 ,
67
- )
68
- content = {
69
- "alias" : alias ,
70
- "ground_truths" : [g .to_dict () for g in self .ground_truths ],
71
- "examples" : [e .to_dict () for e in self .examples ],
72
- "overwrite" : overwrite ,
73
- "judgment_api_key" : self .judgment_api_key
74
- }
75
- try :
76
- response = requests .post (
77
- JUDGMENT_DATASETS_PUSH_API_URL ,
78
- json = content
79
- )
80
- if response .status_code == 500 :
81
- error (f"Server error during push: { content .get ('message' )} " )
82
- return False
83
- response .raise_for_status ()
84
- except requests .exceptions .HTTPError as err :
85
- if response .status_code == 422 :
86
- error (f"Validation error during push: { err .response .json ()} " )
87
- else :
88
- error (f"HTTP error during push: { err } " )
89
-
90
- info (f"Successfully pushed dataset with alias '{ alias } '" )
91
- payload = response .json ()
92
- self ._alias = payload .get ("_alias" )
93
- self ._id = payload .get ("_id" )
94
- progress .update (
95
- task_id ,
96
- description = f"{ progress .tasks [task_id ].description } [rgb(25,227,160)]Done!)" ,
97
- )
98
- return True
99
-
100
- def pull (self , alias : str ):
101
- debug (f"Pulling dataset with alias '{ alias } '" )
102
- """
103
- Pulls the dataset from Judgment platform
104
-
105
- Mock request:
106
- {
107
- "alias": alias,
108
- "user_id": user_id
109
- }
110
- ==>
111
- {
112
- "ground_truths": [...],
113
- "examples": [...],
114
- "_alias": alias,
115
- "_id": "..." # ID of the dataset
116
- }
117
- """
118
- # Make a POST request to the Judgment API to get the dataset
119
-
120
- with Progress (
121
- SpinnerColumn (style = "rgb(106,0,255)" ),
122
- TextColumn ("[progress.description]{task.description}" ),
123
- transient = False ,
124
- ) as progress :
125
- task_id = progress .add_task (
126
- f"Pulling [rgb(106,0,255)]'{ alias } '[/rgb(106,0,255)] from Judgment..." ,
127
- total = 100 ,
128
- )
129
- request_body = {
130
- "alias" : alias ,
131
- "judgment_api_key" : self .judgment_api_key
132
- }
133
-
134
- try :
135
- response = requests .post (
136
- JUDGMENT_DATASETS_PULL_API_URL ,
137
- json = request_body
138
- )
139
- response .raise_for_status ()
140
- except requests .exceptions .RequestException as e :
141
- error (f"Error pulling dataset: { str (e )} " )
142
- raise
143
-
144
- info (f"Successfully pulled dataset with alias '{ alias } '" )
145
- payload = response .json ()
146
- self .ground_truths = [GroundTruthExample (** g ) for g in payload .get ("ground_truths" , [])]
147
- self .examples = [Example (** e ) for e in payload .get ("examples" , [])]
148
- self ._alias = payload .get ("_alias" )
149
- self ._id = payload .get ("_id" )
150
- progress .update (
151
- task_id ,
152
- description = f"{ progress .tasks [task_id ].description } [rgb(25,227,160)]Done!)" ,
153
- )
154
35
155
36
def add_from_json (self , file_path : str ) -> None :
156
37
debug (f"Loading dataset from JSON file: { file_path } " )
@@ -402,6 +283,4 @@ def __str__(self):
402
283
f"_alias={ self ._alias } , "
403
284
f"_id={ self ._id } "
404
285
f")"
405
- )
406
-
407
-
286
+ )
0 commit comments