opik-optimizer 0.7.3__py3-none-any.whl → 0.7.5__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.
@@ -3,7 +3,8 @@ from typing import Literal, List, Dict, Any
3
3
  from .. import utils
4
4
  from datasets import load_dataset
5
5
  import traceback
6
-
6
+ from importlib.resources import files
7
+ import json
7
8
 
8
9
  class HaltError(Exception):
9
10
  """Exception raised when we need to halt the process due to a critical error."""
@@ -116,50 +117,32 @@ def get_or_create_dataset(
116
117
 
117
118
 
118
119
  def _load_hotpot_500(test_mode: bool = False) -> List[Dict[str, Any]]:
119
- from dspy.datasets import HotPotQA
120
-
121
- seed = 2024
122
120
  size = 500 if not test_mode else 5
123
121
 
124
- try:
125
- trainset = [
126
- x.with_inputs("question")
127
- for x in HotPotQA(train_seed=seed, train_size=size).train
128
- ]
129
- except Exception:
130
- raise Exception("Unable to download HotPotQA; please try again") from None
122
+ # This is not a random dataset
123
+
124
+ json_content = (files('opik_optimizer') / 'data' / 'hotpot-500.json').read_text(encoding='utf-8')
125
+ all_data = json.loads(json_content)
126
+ trainset = all_data[:size]
131
127
 
132
128
  data = []
133
129
  for row in reversed(trainset):
134
- d = row.toDict()
135
- del d["dspy_uuid"]
136
- del d["dspy_split"]
137
- data.append(d)
138
-
130
+ data.append(row)
139
131
  return data
140
132
 
141
133
 
142
134
  def _load_hotpot_300(test_mode: bool = False) -> List[Dict[str, Any]]:
143
- from dspy.datasets import HotPotQA
144
-
145
- seed = 42
146
135
  size = 300 if not test_mode else 3
147
136
 
148
- try:
149
- trainset = [
150
- x.with_inputs("question")
151
- for x in HotPotQA(train_seed=seed, train_size=size).train
152
- ]
153
- except Exception:
154
- raise Exception("Unable to download HotPotQA; please try again") from None
137
+ # This is not a random dataset
155
138
 
156
- data = []
157
- for row in trainset:
158
- d = row.toDict()
159
- del d["dspy_uuid"]
160
- del d["dspy_split"]
161
- data.append(d)
139
+ json_content = (files('opik_optimizer') / 'data' / 'hotpot-500.json').read_text(encoding='utf-8')
140
+ all_data = json.loads(json_content)
141
+ trainset = all_data[:size]
162
142
 
143
+ data = []
144
+ for row in reversed(trainset):
145
+ data.append(row)
163
146
  return data
164
147
 
165
148
 
@@ -0,0 +1 @@
1
+ from .evolutionary_optimizer import EvolutionaryOptimizer