opik-optimizer 0.9.0rc0__py3-none-any.whl → 0.9.1__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.
- opik_optimizer/__init__.py +1 -1
- opik_optimizer/few_shot_bayesian_optimizer/few_shot_bayesian_optimizer.py +11 -9
- opik_optimizer/optimization_config/chat_prompt.py +2 -2
- opik_optimizer/task_evaluator.py +11 -4
- {opik_optimizer-0.9.0rc0.dist-info → opik_optimizer-0.9.1.dist-info}/METADATA +1 -1
- {opik_optimizer-0.9.0rc0.dist-info → opik_optimizer-0.9.1.dist-info}/RECORD +9 -9
- {opik_optimizer-0.9.0rc0.dist-info → opik_optimizer-0.9.1.dist-info}/WHEEL +0 -0
- {opik_optimizer-0.9.0rc0.dist-info → opik_optimizer-0.9.1.dist-info}/licenses/LICENSE +0 -0
- {opik_optimizer-0.9.0rc0.dist-info → opik_optimizer-0.9.1.dist-info}/top_level.txt +0 -0
opik_optimizer/__init__.py
CHANGED
@@ -12,8 +12,8 @@ from .logging_config import setup_logging
|
|
12
12
|
from .meta_prompt_optimizer import MetaPromptOptimizer
|
13
13
|
from .mipro_optimizer import MiproOptimizer
|
14
14
|
from .optimization_config.chat_prompt import ChatPrompt
|
15
|
-
from .optimization_result import OptimizationResult
|
16
15
|
from .optimization_config.configs import TaskConfig
|
16
|
+
from .optimization_result import OptimizationResult
|
17
17
|
|
18
18
|
__version__ = importlib.metadata.version("opik_optimizer")
|
19
19
|
|
@@ -39,8 +39,9 @@ Your task:
|
|
39
39
|
- Add a section title in XML or markdown format. The examples will be provided as `example_1\nexample_2\n...` with each example following the example template.
|
40
40
|
- Analyze the examples to infer a consistent structure, and create a single string few_shot_example_template using the Python .format() style. Make sure to follow the following instructions:
|
41
41
|
- Unless absolutely relevant, do not return an object but instead a string that can be inserted as part of {FEW_SHOT_EXAMPLE_PLACEHOLDER}
|
42
|
-
- Make sure to include the variables as part of this string so we can before string formatting with actual examples. Only variables available in the examples can be used.
|
43
|
-
-
|
42
|
+
- Make sure to include the variables as part of this string so we can before string formatting with actual examples. Only variables available in the examples can be used.
|
43
|
+
- Do not apply any transformations to the variables either, only the variable name should be included in the format `{{<variable_name>}}`
|
44
|
+
- The few shot examples should include the expected response as the goal is to provide examples of the response.
|
44
45
|
- Ensure the format of the few shot examples are consistent with how the model will be called
|
45
46
|
|
46
47
|
Return your output as a JSON object with:
|
@@ -252,7 +253,7 @@ class FewShotBayesianOptimizer(base_optimizer.BaseOptimizer):
|
|
252
253
|
processed_demo_examples.append(
|
253
254
|
fewshot_prompt_template.example_template.format(**processed_example)
|
254
255
|
)
|
255
|
-
except Exception
|
256
|
+
except Exception:
|
256
257
|
logger.error(f"Failed to format fewshot prompt template {fewshot_prompt_template} with example: {processed_example} ")
|
257
258
|
raise
|
258
259
|
few_shot_examples = "\n\n".join(processed_demo_examples)
|
@@ -301,7 +302,7 @@ class FewShotBayesianOptimizer(base_optimizer.BaseOptimizer):
|
|
301
302
|
trial_config = {
|
302
303
|
"demo_examples": demo_examples,
|
303
304
|
"message_list_with_placeholder": fewshot_prompt_template.message_list_with_placeholder,
|
304
|
-
"message_list":
|
305
|
+
"message_list": messages_for_reporting
|
305
306
|
}
|
306
307
|
trial.set_user_attr("score", score)
|
307
308
|
trial.set_user_attr("config", trial_config)
|
@@ -562,10 +563,11 @@ class FewShotBayesianOptimizer(base_optimizer.BaseOptimizer):
|
|
562
563
|
self, messages: List[Dict[str, str]], few_shot_examples: Optional[str] = None
|
563
564
|
):
|
564
565
|
def llm_task(dataset_item: Dict[str, Any]) -> Dict[str, Any]:
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
566
|
+
for key, value in dataset_item.items():
|
567
|
+
prompt_ = [{
|
568
|
+
"role": item["role"],
|
569
|
+
"content": item["content"].replace("{" + key + "}", str(value))
|
570
|
+
} for item in messages]
|
569
571
|
|
570
572
|
if few_shot_examples:
|
571
573
|
prompt_ = [{
|
@@ -584,4 +586,4 @@ class FewShotBayesianOptimizer(base_optimizer.BaseOptimizer):
|
|
584
586
|
mappers.EVALUATED_LLM_TASK_OUTPUT: response.choices[0].message.content
|
585
587
|
}
|
586
588
|
|
587
|
-
return llm_task
|
589
|
+
return llm_task
|
@@ -94,8 +94,8 @@ class ChatPrompt:
|
|
94
94
|
}
|
95
95
|
|
96
96
|
@classmethod
|
97
|
-
def model_validate(cls, obj: Any, *, strict: bool
|
98
|
-
context: Any
|
97
|
+
def model_validate(cls, obj: Any, *, strict: Optional[bool] = None, from_attributes: Optional[bool] = None,
|
98
|
+
context: Optional[Any] = None, by_alias: Optional[bool] = None, by_name: Optional[bool] = None) -> 'ChatPrompt':
|
99
99
|
"""Custom validation method to handle nested objects during deserialization."""
|
100
100
|
return ChatPrompt(
|
101
101
|
system=obj.get('system', None),
|
opik_optimizer/task_evaluator.py
CHANGED
@@ -11,16 +11,23 @@ def _create_metric_class(metric: Callable):
|
|
11
11
|
class MetricClass(base_metric.BaseMetric):
|
12
12
|
def __init__(self):
|
13
13
|
self.name = metric.__name__
|
14
|
-
|
14
|
+
|
15
15
|
def score(self, llm_output, **kwargs) -> score_result.ScoreResult:
|
16
16
|
try:
|
17
17
|
metric_val = metric(dataset_item=kwargs, llm_output=llm_output)
|
18
18
|
if isinstance(metric_val , score_result.ScoreResult):
|
19
|
-
return
|
19
|
+
return score_result.ScoreResult(
|
20
|
+
name = self.name,
|
21
|
+
value = metric_val.value,
|
22
|
+
scoring_failed=metric_val.scoring_failed,
|
23
|
+
metadata=metric_val.metadata,
|
24
|
+
reason=metric_val.reason
|
25
|
+
)
|
20
26
|
else:
|
21
27
|
return score_result.ScoreResult(
|
22
28
|
name = self.name,
|
23
|
-
value = metric_val
|
29
|
+
value = metric_val,
|
30
|
+
scoring_failed=False
|
24
31
|
)
|
25
32
|
except Exception:
|
26
33
|
return score_result.ScoreResult(
|
@@ -71,7 +78,7 @@ def evaluate(
|
|
71
78
|
items = [item for item in items if item.get("id") in dataset_item_ids]
|
72
79
|
|
73
80
|
eval_metrics = [_create_metric_class(metric)]
|
74
|
-
|
81
|
+
|
75
82
|
if optimization_id is not None:
|
76
83
|
result = opik_evaluator.evaluate_optimization_trial(
|
77
84
|
optimization_id=optimization_id,
|
@@ -1,11 +1,11 @@
|
|
1
|
-
opik_optimizer/__init__.py,sha256=
|
1
|
+
opik_optimizer/__init__.py,sha256=CmFF0SEE_zdvlOLFeZceXqDBHzcsCGDb59b9I9Yeg6g,1089
|
2
2
|
opik_optimizer/_throttle.py,sha256=ztub8qlwz4u0GVA2TIoLig0D1Cs0hJ7_o_SnT_C7Nmk,1360
|
3
3
|
opik_optimizer/base_optimizer.py,sha256=mg5D5m2hIzq3XbVjRhx8c_HuXWZWaRE2J6QtkHnxkqE,4439
|
4
4
|
opik_optimizer/cache_config.py,sha256=EzF4RAzxhSG8vtMJANdiUpNHQ9HzL2CrCXp0iik0f4A,580
|
5
5
|
opik_optimizer/logging_config.py,sha256=XECPnSoh8ghbllv1F0vj6ofO8YmE2HL0coLWjLdaNTU,2780
|
6
6
|
opik_optimizer/optimization_result.py,sha256=PeDIoNIHaJsi9WsDoKPgO6sW3CkPKZKK7RvY8tmjUN0,7508
|
7
7
|
opik_optimizer/reporting_utils.py,sha256=pRcRhE9w1q6PVdTmqrTyqIlUmeMAknwJJFT99FG0tuk,5523
|
8
|
-
opik_optimizer/task_evaluator.py,sha256=
|
8
|
+
opik_optimizer/task_evaluator.py,sha256=212shzapI7GtrqrFvn_6wkvWR5_Zhm30CR5t-tW0bV8,4380
|
9
9
|
opik_optimizer/utils.py,sha256=y7I58vESRphuMLA4cfH3sNiSuntyiqG8hwK5UuwVdt4,8239
|
10
10
|
opik_optimizer/data/hotpot-500.json,sha256=YXxCtuvYvxSu5u0y4559a6b1qwgAYsWzT_SUKv_21ew,76862
|
11
11
|
opik_optimizer/datasets/__init__.py,sha256=V4LVDOaRjwzaYvhdQ3V6CAwFaeKnxyTV1lp_ES9Z31E,691
|
@@ -27,7 +27,7 @@ opik_optimizer/evolutionary_optimizer/__init__.py,sha256=OQ2ART5g-7EVGOISvTGY-Ab
|
|
27
27
|
opik_optimizer/evolutionary_optimizer/evolutionary_optimizer.py,sha256=cnpga8ytSjx5lNq2URLBCyV9s5r1s9_eKD4BU7rWW_g,76259
|
28
28
|
opik_optimizer/evolutionary_optimizer/reporting.py,sha256=Gl52sH7XaU4GXUhFt_FcfjYFN3MghnDt1ISULATjbP4,9944
|
29
29
|
opik_optimizer/few_shot_bayesian_optimizer/__init__.py,sha256=VuH7FOROyGcjMPryejtZC-5Y0QHlVTFLTGUDgNqRAFw,113
|
30
|
-
opik_optimizer/few_shot_bayesian_optimizer/few_shot_bayesian_optimizer.py,sha256=
|
30
|
+
opik_optimizer/few_shot_bayesian_optimizer/few_shot_bayesian_optimizer.py,sha256=trQ7lAdPyNpMrCwdQeq67FCosQuoN3uvLM6lXoJPkQQ,24457
|
31
31
|
opik_optimizer/few_shot_bayesian_optimizer/reporting.py,sha256=j1mNEQyFT7YUVlMU1TxPZxrf5sPwiHZ2nx1fOL4ZIog,4756
|
32
32
|
opik_optimizer/meta_prompt_optimizer/__init__.py,sha256=syiN2_fMm5iZDQezZCHYe-ZiGOIPlBkLt49Sa1kuR70,97
|
33
33
|
opik_optimizer/meta_prompt_optimizer/meta_prompt_optimizer.py,sha256=LrN8kGoB-qm5Tvncpmcy2qd79vxkcMokei2sMXrv0jw,34404
|
@@ -38,11 +38,11 @@ opik_optimizer/mipro_optimizer/_mipro_optimizer_v2.py,sha256=wQP3D5g3X2e0h05vJy_
|
|
38
38
|
opik_optimizer/mipro_optimizer/mipro_optimizer.py,sha256=pfD8toZVCpqSDdGwyOUvAeyORyGyYqrua71JFzVw2GA,23305
|
39
39
|
opik_optimizer/mipro_optimizer/utils.py,sha256=-d9xOKxmYbKwpNM2aheKQVf3gxCh5B1ENuAvzc38xe8,2509
|
40
40
|
opik_optimizer/optimization_config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
41
|
-
opik_optimizer/optimization_config/chat_prompt.py,sha256=
|
41
|
+
opik_optimizer/optimization_config/chat_prompt.py,sha256=nGSElB4CyOegYi06oFmaVeFKI6XRv6LJOWJ1axhjyyY,3500
|
42
42
|
opik_optimizer/optimization_config/configs.py,sha256=HzpEP84bnqtDs76dtmPGecDQ-Ux2wIk0JVv7A2gsE3k,496
|
43
43
|
opik_optimizer/optimization_config/mappers.py,sha256=RMUWwYvXNCJe6w1jYiT6EX218UYZS1PUMMe12OjNEug,1692
|
44
|
-
opik_optimizer-0.9.
|
45
|
-
opik_optimizer-0.9.
|
46
|
-
opik_optimizer-0.9.
|
47
|
-
opik_optimizer-0.9.
|
48
|
-
opik_optimizer-0.9.
|
44
|
+
opik_optimizer-0.9.1.dist-info/licenses/LICENSE,sha256=dTRSwwCHdWeSjzodvnivYqcwi8x3Qfr21yv65QUWWBE,1062
|
45
|
+
opik_optimizer-0.9.1.dist-info/METADATA,sha256=XodSnPMwsIwJ2WF618unt3iXHoCbYfokqEM7xnN9vW4,6588
|
46
|
+
opik_optimizer-0.9.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
47
|
+
opik_optimizer-0.9.1.dist-info/top_level.txt,sha256=ondOlpq6_yFckqpxoAHSfzZS2N-JfgmA-QQhOJfz7m0,15
|
48
|
+
opik_optimizer-0.9.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|