judgeval 0.3.2__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- from typing import Literal, List, Dict, Any, Union
1
+ from typing import Literal, List, Dict, Any, Union, Optional
2
2
  from requests import exceptions
3
3
  from judgeval.common.api.constants import (
4
4
  JUDGMENT_TRACES_FETCH_API_URL,
@@ -238,7 +238,7 @@ class JudgmentApiClient:
238
238
  }
239
239
  return self._do_request("POST", JUDGMENT_CHECK_EXAMPLE_KEYS_API_URL, payload)
240
240
 
241
- def save_scorer(self, name: str, prompt: str, options: dict):
241
+ def save_scorer(self, name: str, prompt: str, options: Optional[dict] = None):
242
242
  payload: ScorerSavePayload = {
243
243
  "name": name,
244
244
  "prompt": prompt,
@@ -162,7 +162,7 @@ JUDGMENT_SCORER_EXISTS_API_URL = f"{ROOT_API}/scorer_exists/"
162
162
  class ScorerSavePayload(TypedDict):
163
163
  name: str
164
164
  prompt: str
165
- options: dict
165
+ options: Optional[dict]
166
166
 
167
167
 
168
168
  class ScorerFetchPayload(TypedDict):
@@ -1,27 +1,29 @@
1
1
  from judgeval.scorers.api_scorer import APIScorerConfig
2
2
  from judgeval.constants import APIScorerType
3
- from typing import Mapping, Dict, Any
3
+ from typing import Dict, Any, Optional
4
4
  from judgeval.common.api import JudgmentApiClient, JudgmentAPIException
5
5
  import os
6
6
  from judgeval.common.exceptions import JudgmentAPIError
7
+ from copy import copy
8
+ from judgeval.common.logger import judgeval_logger
7
9
 
8
10
 
9
11
  def push_prompt_scorer(
10
12
  name: str,
11
13
  prompt: str,
12
- options: Mapping[str, float],
14
+ options: Optional[Dict[str, float]] = None,
13
15
  judgment_api_key: str = os.getenv("JUDGMENT_API_KEY") or "",
14
16
  organization_id: str = os.getenv("JUDGMENT_ORG_ID") or "",
15
17
  ) -> str:
16
18
  client = JudgmentApiClient(judgment_api_key, organization_id)
17
19
  try:
18
- r = client.save_scorer(name, prompt, dict(options))
20
+ r = client.save_scorer(name, prompt, options)
19
21
  except JudgmentAPIException as e:
20
22
  if e.status_code == 500:
21
23
  raise JudgmentAPIError(
22
24
  f"The server is temporarily unavailable. Please try your request again in a few moments. Error details: {e.error_detail}"
23
25
  )
24
- raise JudgmentAPIError(f"Failed to save classifier scorer: {e.error_detail}")
26
+ raise JudgmentAPIError(f"Failed to save prompt scorer: {e.error_detail}")
25
27
  return r["name"]
26
28
 
27
29
 
@@ -32,7 +34,7 @@ def fetch_prompt_scorer(
32
34
  ):
33
35
  client = JudgmentApiClient(judgment_api_key, organization_id)
34
36
  try:
35
- scorer_config = client.fetch_scorer(name)
37
+ scorer_config = client.fetch_scorer(name)["scorer"]
36
38
  scorer_config.pop("created_at")
37
39
  scorer_config.pop("updated_at")
38
40
  return scorer_config
@@ -42,7 +44,7 @@ def fetch_prompt_scorer(
42
44
  f"The server is temporarily unavailable. Please try your request again in a few moments. Error details: {e.error_detail}"
43
45
  )
44
46
  raise JudgmentAPIError(
45
- f"Failed to fetch classifier scorer '{name}': {e.error_detail}"
47
+ f"Failed to fetch prompt scorer '{name}': {e.error_detail}"
46
48
  )
47
49
 
48
50
 
@@ -72,7 +74,7 @@ class PromptScorer(APIScorerConfig):
72
74
  """
73
75
 
74
76
  prompt: str
75
- options: Mapping[str, float]
77
+ options: Optional[Dict[str, float]] = None
76
78
  score_type: APIScorerType = APIScorerType.PROMPT_SCORER
77
79
  judgment_api_key: str = os.getenv("JUDGMENT_API_KEY") or ""
78
80
  organization_id: str = os.getenv("JUDGMENT_ORG_ID") or ""
@@ -88,7 +90,7 @@ class PromptScorer(APIScorerConfig):
88
90
  return cls(
89
91
  name=name,
90
92
  prompt=scorer_config["prompt"],
91
- options=scorer_config["options"],
93
+ options=scorer_config.get("options"),
92
94
  judgment_api_key=judgment_api_key,
93
95
  organization_id=organization_id,
94
96
  )
@@ -98,12 +100,13 @@ class PromptScorer(APIScorerConfig):
98
100
  cls,
99
101
  name: str,
100
102
  prompt: str,
101
- options: Mapping[str, float],
103
+ options: Optional[Dict[str, float]] = None,
102
104
  judgment_api_key: str = os.getenv("JUDGMENT_API_KEY") or "",
103
105
  organization_id: str = os.getenv("JUDGMENT_ORG_ID") or "",
104
106
  ):
105
107
  if not scorer_exists(name, judgment_api_key, organization_id):
106
108
  push_prompt_scorer(name, prompt, options, judgment_api_key, organization_id)
109
+ judgeval_logger.info(f"Successfully created PromptScorer: {name}")
107
110
  return cls(
108
111
  name=name,
109
112
  prompt=prompt,
@@ -117,13 +120,6 @@ class PromptScorer(APIScorerConfig):
117
120
  )
118
121
 
119
122
  # Setter functions. Each setter function pushes the scorer to the DB.
120
- def set_name(self, name: str):
121
- """
122
- Updates the name of the scorer.
123
- """
124
- self.name = name
125
- self.push_prompt_scorer()
126
-
127
123
  def set_threshold(self, threshold: float):
128
124
  """
129
125
  Updates the threshold of the scorer.
@@ -140,8 +136,9 @@ class PromptScorer(APIScorerConfig):
140
136
  """
141
137
  self.prompt = prompt
142
138
  self.push_prompt_scorer()
139
+ judgeval_logger.info(f"Successfully updated prompt for {self.name}")
143
140
 
144
- def set_options(self, options: Mapping[str, float]):
141
+ def set_options(self, options: Dict[str, float]):
145
142
  """
146
143
  Updates the options with the new options.
147
144
 
@@ -150,6 +147,7 @@ class PromptScorer(APIScorerConfig):
150
147
  """
151
148
  self.options = options
152
149
  self.push_prompt_scorer()
150
+ judgeval_logger.info(f"Successfully updated options for {self.name}")
153
151
 
154
152
  def append_to_prompt(self, prompt_addition: str):
155
153
  """
@@ -157,6 +155,7 @@ class PromptScorer(APIScorerConfig):
157
155
  """
158
156
  self.prompt += prompt_addition
159
157
  self.push_prompt_scorer()
158
+ judgeval_logger.info(f"Successfully appended to prompt for {self.name}")
160
159
 
161
160
  # Getters
162
161
  def get_prompt(self) -> str | None:
@@ -165,11 +164,11 @@ class PromptScorer(APIScorerConfig):
165
164
  """
166
165
  return self.prompt
167
166
 
168
- def get_options(self) -> Mapping[str, float] | None:
167
+ def get_options(self) -> Dict[str, float] | None:
169
168
  """
170
169
  Returns the options of the scorer.
171
170
  """
172
- return self.options
171
+ return copy(self.options) if self.options is not None else None
173
172
 
174
173
  def get_name(self) -> str | None:
175
174
  """
judgeval/scorers/score.py CHANGED
@@ -48,6 +48,7 @@ async def safe_a_score_example(
48
48
  judgeval_logger.error(f"Error during scoring: {str(e)}")
49
49
  scorer.error = str(e)
50
50
  scorer.success = False
51
+ scorer.score = 0
51
52
  return
52
53
 
53
54
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: judgeval
3
- Version: 0.3.2
3
+ Version: 0.4.0
4
4
  Summary: Judgeval Package
5
5
  Project-URL: Homepage, https://github.com/JudgmentLabs/judgeval
6
6
  Project-URL: Issues, https://github.com/JudgmentLabs/judgeval/issues
@@ -12,8 +12,8 @@ judgeval/common/exceptions.py,sha256=OkgDznu2wpBQZMXiZarLJYNk1HIcC8qYW7VypDC3Ook
12
12
  judgeval/common/logger.py,sha256=514eFLYWS_UL8VY-zAR2ePUlpQe4rbYlleLASFllLE4,1511
13
13
  judgeval/common/utils.py,sha256=oxGDRVWOICKWeyGgsoc36_yAyHSYF4XtH842Mkznwis,34739
14
14
  judgeval/common/api/__init__.py,sha256=-E7lpZz1fG8puR_aYUMfPmQ-Vyhd0bgzoaU5EhIuFjQ,114
15
- judgeval/common/api/api.py,sha256=wty02HYANeOYlM8fHOLc33ux5bu9Ieq7iRqCr-UP0ng,14157
16
- judgeval/common/api/constants.py,sha256=vAW94pbyTS6rv1TKpt7z6xxMJvTaAxFiy1D4kzuLHeg,4567
15
+ judgeval/common/api/api.py,sha256=0Vd81CXoUYF1a7hOlI2PqXJcQO7eqWEbS8sX2W0CJMY,14184
16
+ judgeval/common/api/constants.py,sha256=DXej0m8HEhb871SdiR8t_o4fzeMoQjHYqb_X0Plj8wY,4577
17
17
  judgeval/common/storage/__init__.py,sha256=a-PI7OL-ydyzugGUKmJKRBASnK-Q-gs82L9K9rSyJP8,90
18
18
  judgeval/common/storage/s3_storage.py,sha256=0-bNKheqJJyBZ92KGrzQtd1zocIRWBlfn_58L4a-Ay0,3719
19
19
  judgeval/common/tracer/__init__.py,sha256=tJCJsmVmrL89Phv88gNCJ-j0ITPez6lh8vhMAAlLNSc,795
@@ -47,7 +47,7 @@ judgeval/scorers/api_scorer.py,sha256=xlhqkeMUBFxl8daSXOTWOYwZjBAz7o6b4sVD5f8cIH
47
47
  judgeval/scorers/base_scorer.py,sha256=eDfQk8N8TQfM1ayJDWr0NTdSQxcbk9-VZHd0Igb9EbI,2878
48
48
  judgeval/scorers/example_scorer.py,sha256=2n45y3LMV1Q-ARyXLHqvVWETlnY1DqS7OLzPu9IBGz8,716
49
49
  judgeval/scorers/exceptions.py,sha256=ACDHK5-TWiF3NTk-wycaedpbrdobm-CvvC1JA_iP-Mk,179
50
- judgeval/scorers/score.py,sha256=2-M_AmOjIQR2c0qvuB4WIIQD-7zSNdzsWC8ttqltw2g,6601
50
+ judgeval/scorers/score.py,sha256=SPoN5GG5sGKAt2aw_NgDj4-w5Mv1CGgaD9q-Sj1jRII,6626
51
51
  judgeval/scorers/utils.py,sha256=HQOYTJtNnsi_aPfMssePAaBbXpAv7LXgwUlWlDFuN2g,3965
52
52
  judgeval/scorers/judgeval_scorers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
53
53
  judgeval/scorers/judgeval_scorers/api_scorers/__init__.py,sha256=GX4KkwPR2p-c0Y5mZingJa8EUfjAbMGhrmRBDBunOGw,1484
@@ -58,14 +58,14 @@ judgeval/scorers/judgeval_scorers/api_scorers/execution_order.py,sha256=NABO_iBd
58
58
  judgeval/scorers/judgeval_scorers/api_scorers/faithfulness.py,sha256=ps51bTgQsD9xGYsk1v9bx0WxQMqywSllCE9_xlJkLd8,531
59
59
  judgeval/scorers/judgeval_scorers/api_scorers/hallucination.py,sha256=SnFLvU4FGsMeUVUp0SGHSy_6wgfwr_vHPGnZx5YJl_Q,691
60
60
  judgeval/scorers/judgeval_scorers/api_scorers/instruction_adherence.py,sha256=aQzu-TiGqG74JDQ927evv5yGmnZw2AOolyHvlIhiUbI,683
61
- judgeval/scorers/judgeval_scorers/api_scorers/prompt_scorer.py,sha256=TS3uZ6YQfMs2yGCwzlz-yxZ3Rid79MGxEQESZkSX_Vo,7038
61
+ judgeval/scorers/judgeval_scorers/api_scorers/prompt_scorer.py,sha256=nx73DeoVkSqJTP1hYxMsJobG9HVWgMDN5-xFOXt_8Ts,7348
62
62
  judgeval/scorers/judgeval_scorers/api_scorers/tool_dependency.py,sha256=Mcp1CjMNyOax9UkvoRdSyUYdO2Os1-Nko43y89m2Luo,594
63
63
  judgeval/scorers/judgeval_scorers/api_scorers/tool_order.py,sha256=Z2FLGBC7m_CLx-CMgXVuTvYvN0vY5yOcWA0ImBkeBfY,787
64
64
  judgeval/tracer/__init__.py,sha256=wkuXtOGDCrwgPPXlh_sSJmvGuWaAMHyNzk1TzB5f9aI,148
65
65
  judgeval/utils/alerts.py,sha256=3w_AjQrgfmOZvfqCridW8WAnHVxHHXokX9jNzVFyGjA,3297
66
66
  judgeval/utils/file_utils.py,sha256=PWHRs8dUr8iDwpglSSk4Yjd7C6ZhDzUaO-jV3m7riHM,1987
67
67
  judgeval/utils/requests.py,sha256=K3gUKrwL6TvwYKVYO5OeLWdUHn9NiUPmnIXhZEiEaHU,1534
68
- judgeval-0.3.2.dist-info/METADATA,sha256=3VDQzNPY0wKnaIpzmrP2OLsk6eEGJZH_dSl4QcJRVwE,10348
69
- judgeval-0.3.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
70
- judgeval-0.3.2.dist-info/licenses/LICENSE.md,sha256=tKmCg7k5QOmxPK19XMfzim04QiQJPmgIm0pAn55IJwk,11352
71
- judgeval-0.3.2.dist-info/RECORD,,
68
+ judgeval-0.4.0.dist-info/METADATA,sha256=6ZJMXn13RNp-LZfoBUNtmjt7nCvthWU9qT9YNBNe7Wo,10348
69
+ judgeval-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
70
+ judgeval-0.4.0.dist-info/licenses/LICENSE.md,sha256=tKmCg7k5QOmxPK19XMfzim04QiQJPmgIm0pAn55IJwk,11352
71
+ judgeval-0.4.0.dist-info/RECORD,,