opik-optimizer 0.7.1__py3-none-any.whl → 0.7.2__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 +14 -36
- opik_optimizer/base_optimizer.py +0 -2
- opik_optimizer/demo/cache.py +1 -0
- opik_optimizer/few_shot_bayesian_optimizer/few_shot_bayesian_optimizer.py +5 -3
- opik_optimizer-0.7.2.dist-info/METADATA +172 -0
- {opik_optimizer-0.7.1.dist-info → opik_optimizer-0.7.2.dist-info}/RECORD +9 -9
- opik_optimizer-0.7.1.dist-info/METADATA +0 -35
- {opik_optimizer-0.7.1.dist-info → opik_optimizer-0.7.2.dist-info}/WHEEL +0 -0
- {opik_optimizer-0.7.1.dist-info → opik_optimizer-0.7.2.dist-info}/licenses/LICENSE +0 -0
- {opik_optimizer-0.7.1.dist-info → opik_optimizer-0.7.2.dist-info}/top_level.txt +0 -0
opik_optimizer/__init__.py
CHANGED
@@ -7,42 +7,20 @@ __version__ = importlib.metadata.version("opik_optimizer")
|
|
7
7
|
# Using WARNING as a sensible default to avoid flooding users with INFO/DEBUG
|
8
8
|
setup_logging(level=logging.WARNING)
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
return MetaPromptOptimizer
|
25
|
-
elif name == "FewShotBayesianOptimizer":
|
26
|
-
from .few_shot_bayesian_optimizer import FewShotBayesianOptimizer
|
27
|
-
|
28
|
-
return FewShotBayesianOptimizer
|
29
|
-
elif name in ["MetricConfig", "OptimizationConfig", "TaskConfig"]:
|
30
|
-
from .optimization_config.configs import (
|
31
|
-
MetricConfig,
|
32
|
-
OptimizationConfig,
|
33
|
-
TaskConfig,
|
34
|
-
)
|
35
|
-
|
36
|
-
return locals()[name]
|
37
|
-
elif name in ["from_dataset_field", "from_llm_response_text"]:
|
38
|
-
from .optimization_config.mappers import (
|
39
|
-
from_dataset_field,
|
40
|
-
from_llm_response_text,
|
41
|
-
)
|
42
|
-
|
43
|
-
return locals()[name]
|
44
|
-
raise AttributeError(f"module 'opik_optimizer' has no attribute '{name}'")
|
45
|
-
|
10
|
+
# Regular imports
|
11
|
+
from .mipro_optimizer import MiproOptimizer
|
12
|
+
from .base_optimizer import BaseOptimizer
|
13
|
+
from .meta_prompt_optimizer import MetaPromptOptimizer
|
14
|
+
from .few_shot_bayesian_optimizer import FewShotBayesianOptimizer
|
15
|
+
from .optimization_config.configs import (
|
16
|
+
MetricConfig,
|
17
|
+
OptimizationConfig,
|
18
|
+
TaskConfig,
|
19
|
+
)
|
20
|
+
from .optimization_config.mappers import (
|
21
|
+
from_dataset_field,
|
22
|
+
from_llm_response_text,
|
23
|
+
)
|
46
24
|
|
47
25
|
from opik.evaluation.models.litellm import warning_filters
|
48
26
|
|
opik_optimizer/base_optimizer.py
CHANGED
opik_optimizer/demo/cache.py
CHANGED
@@ -9,6 +9,7 @@ import requests
|
|
9
9
|
NAMED_CACHES = {
|
10
10
|
"test": "https://drive.google.com/file/d/1RifNtpN-pl0DW49daRaAMJwW7MCsOh6y/view?usp=sharing",
|
11
11
|
"test2": "https://drive.google.com/uc?id=1RifNtpN-pl0DW49daRaAMJwW7MCsOh6y&export=download",
|
12
|
+
"opik-workshop": "https://drive.google.com/file/d/1l0aK6KhDPs2bFsQTkfzvOvfacJlhdmHr/view?usp=sharing",
|
12
13
|
}
|
13
14
|
CACHE_DIR = os.path.expanduser("~/.litellm_cache")
|
14
15
|
|
@@ -85,7 +85,7 @@ class FewShotBayesianOptimizer(base_optimizer.BaseOptimizer):
|
|
85
85
|
split_idx = int(len(dataset) * train_ratio)
|
86
86
|
return dataset[:split_idx], dataset[split_idx:]
|
87
87
|
|
88
|
-
def _optimize_prompt(
|
88
|
+
def _optimize_prompt(
|
89
89
|
self,
|
90
90
|
dataset: Union[str, Dataset],
|
91
91
|
metric_config: MetricConfig,
|
@@ -171,8 +171,10 @@ class FewShotBayesianOptimizer(base_optimizer.BaseOptimizer):
|
|
171
171
|
n_examples = trial.suggest_int(
|
172
172
|
"n_examples", self.min_examples, self.max_examples
|
173
173
|
)
|
174
|
-
|
175
|
-
|
174
|
+
example_indices = [
|
175
|
+
trial.suggest_categorical(f"example_{i}", list(range(len(dataset_items))))
|
176
|
+
for i in range(n_examples)
|
177
|
+
]
|
176
178
|
trial.set_user_attr("example_indices", example_indices)
|
177
179
|
|
178
180
|
instruction = task_config.instruction_prompt
|
@@ -0,0 +1,172 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: opik_optimizer
|
3
|
+
Version: 0.7.2
|
4
|
+
Summary: Agent optimization with Opik
|
5
|
+
Home-page: https://github.com/comet-ml/opik
|
6
|
+
Author: Comet ML
|
7
|
+
Author-email: support@comet.com
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
9
|
+
Classifier: Intended Audience :: Developers
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
12
|
+
Requires-Python: >=3.9,<3.13
|
13
|
+
Description-Content-Type: text/markdown
|
14
|
+
License-File: LICENSE
|
15
|
+
Requires-Dist: opik>=1.7.17
|
16
|
+
Requires-Dist: dspy<3,>=2.6.18
|
17
|
+
Requires-Dist: litellm
|
18
|
+
Requires-Dist: tqdm
|
19
|
+
Requires-Dist: datasets
|
20
|
+
Requires-Dist: optuna
|
21
|
+
Requires-Dist: pydantic
|
22
|
+
Requires-Dist: pandas
|
23
|
+
Requires-Dist: hf_xet
|
24
|
+
Provides-Extra: dev
|
25
|
+
Requires-Dist: adalflow; extra == "dev"
|
26
|
+
Requires-Dist: pytest; extra == "dev"
|
27
|
+
Requires-Dist: pytest-conv; extra == "dev"
|
28
|
+
Dynamic: author
|
29
|
+
Dynamic: author-email
|
30
|
+
Dynamic: classifier
|
31
|
+
Dynamic: description
|
32
|
+
Dynamic: description-content-type
|
33
|
+
Dynamic: home-page
|
34
|
+
Dynamic: license-file
|
35
|
+
Dynamic: provides-extra
|
36
|
+
Dynamic: requires-dist
|
37
|
+
Dynamic: requires-python
|
38
|
+
Dynamic: summary
|
39
|
+
|
40
|
+
# Opik Optimizer
|
41
|
+
|
42
|
+
The Opik Opitmizer can refine your prompts to get better performance
|
43
|
+
from your LLMs. You can use a variety of algorithms, including:
|
44
|
+
|
45
|
+
* FewShotBayesianOptimizer
|
46
|
+
* MiproOptimizer
|
47
|
+
* MetaPromptOptimizer
|
48
|
+
|
49
|
+
## Quickstart
|
50
|
+
|
51
|
+
|
52
|
+
[Open Quickstart Notebook in Colab](https://colab.research.google.com/github/comet-ml/opik/blob/main/sdks/opik_optimizer/notebooks/OpikOptimizerIntro.ipynb)
|
53
|
+
|
54
|
+
|
55
|
+
## Setup
|
56
|
+
|
57
|
+
1. Configure Opik:
|
58
|
+
```bash
|
59
|
+
# Install Comet ML CLI
|
60
|
+
pip install opik
|
61
|
+
|
62
|
+
# Configure your API key
|
63
|
+
opik configure
|
64
|
+
# When prompted, enter your Opik API key
|
65
|
+
```
|
66
|
+
|
67
|
+
2. Set up your environment variables:
|
68
|
+
```bash
|
69
|
+
# OpenAI API key for LLM access
|
70
|
+
export OPENAI_API_KEY=your_openai_api_key
|
71
|
+
```
|
72
|
+
|
73
|
+
3. Install the package:
|
74
|
+
```bash
|
75
|
+
pip install git+https://github.com/comet-ml/opik#subdirectory=sdks/opik_optimizer
|
76
|
+
```
|
77
|
+
|
78
|
+
You'll need:
|
79
|
+
|
80
|
+
1. An LLM model name
|
81
|
+
2. An Opik Dataset (or Opik Dataset name)
|
82
|
+
3. An Opik Metric (possibly a custom one)
|
83
|
+
4. A starting prompt (string)
|
84
|
+
|
85
|
+
## Example
|
86
|
+
|
87
|
+
We have prepared some sample datasets for testing:
|
88
|
+
|
89
|
+
* "tiny-test"
|
90
|
+
* "halu-eval-300"
|
91
|
+
* "hotpot-300"
|
92
|
+
|
93
|
+
You can see how to use those below:
|
94
|
+
|
95
|
+
```python
|
96
|
+
from opik.evaluation.metrics import LevenshteinRatio
|
97
|
+
from opik_optimizer.few_shot_bayesian_optimizer import FewShotBayesianOptimizer
|
98
|
+
from opik_optimizer.demo import get_or_create_dataset
|
99
|
+
|
100
|
+
from opik_optimizer import (
|
101
|
+
OptimizationConfig,
|
102
|
+
MetricConfig,
|
103
|
+
TaskConfig,
|
104
|
+
from_dataset_field,
|
105
|
+
from_llm_response_text,
|
106
|
+
)
|
107
|
+
|
108
|
+
hot_pot_dataset = get_or_create_dataset("hotpot-300")
|
109
|
+
|
110
|
+
# For chat prompts instruction doesn't need to contain input parameters from dataset examples.
|
111
|
+
prompt_instruction = """
|
112
|
+
Answer the question.
|
113
|
+
"""
|
114
|
+
|
115
|
+
initial_prompt_no_examples = [
|
116
|
+
{"role": "system", "content": prompt_instruction},
|
117
|
+
{"role": "user", "content": "{{question}}"},
|
118
|
+
]
|
119
|
+
|
120
|
+
optimizer = FewShotBayesianOptimizer(
|
121
|
+
model="gpt-4o-mini",
|
122
|
+
project_name="optimize-few-shot-bayesian-hotpot",
|
123
|
+
min_examples=3,
|
124
|
+
max_examples=8,
|
125
|
+
n_threads=16,
|
126
|
+
seed=42,
|
127
|
+
)
|
128
|
+
|
129
|
+
optimization_config = OptimizationConfig(
|
130
|
+
dataset=hot_pot_dataset,
|
131
|
+
objective=MetricConfig(
|
132
|
+
metric=LevenshteinRatio(),
|
133
|
+
inputs={
|
134
|
+
"output": from_llm_response_text(),
|
135
|
+
"reference": from_dataset_field(name="answer"),
|
136
|
+
},
|
137
|
+
),
|
138
|
+
task=TaskConfig(
|
139
|
+
instruction_prompt=prompt_instruction,
|
140
|
+
input_dataset_fields=["question"],
|
141
|
+
output_dataset_field="answer",
|
142
|
+
use_chat_prompt=True,
|
143
|
+
),
|
144
|
+
)
|
145
|
+
|
146
|
+
result = optimizer.optimize_prompt(optimization_config, n_trials=10)
|
147
|
+
print(result)
|
148
|
+
```
|
149
|
+
|
150
|
+
More examples can be found in the `scripts` folder.
|
151
|
+
|
152
|
+
## Installation
|
153
|
+
|
154
|
+
```bash
|
155
|
+
pip install git+https://github.com/comet-ml/opik#subdirectory=sdks/opik_optimizer
|
156
|
+
```
|
157
|
+
|
158
|
+
## Development
|
159
|
+
|
160
|
+
To use the Opik Optimizer from source:
|
161
|
+
|
162
|
+
```bash
|
163
|
+
git clone git clone git@github.com:comet-ml/opik
|
164
|
+
cd sdks/opik_optimizer
|
165
|
+
pip install -e .
|
166
|
+
```
|
167
|
+
|
168
|
+
## Requirements
|
169
|
+
|
170
|
+
- Python 3.10+
|
171
|
+
- Opik API key
|
172
|
+
- OpenAI API key (or other LLM provider)
|
@@ -1,6 +1,6 @@
|
|
1
|
-
opik_optimizer/__init__.py,sha256=
|
1
|
+
opik_optimizer/__init__.py,sha256=x5QSFom-TtmmUNzqyYIJY2AujMJXbyhXs2oz44-4Af0,1121
|
2
2
|
opik_optimizer/_throttle.py,sha256=7vcHoISqXbysymwdb1LPAFJB28tOmih9zzZQWajpH0k,1494
|
3
|
-
opik_optimizer/base_optimizer.py,sha256=
|
3
|
+
opik_optimizer/base_optimizer.py,sha256=EEFx9ekIV5IjLaf18e6zFzxBO44uxkeHelGmC70GPpo,8260
|
4
4
|
opik_optimizer/cache_config.py,sha256=EzF4RAzxhSG8vtMJANdiUpNHQ9HzL2CrCXp0iik0f4A,580
|
5
5
|
opik_optimizer/logging_config.py,sha256=ELevhxtflYinTo-jVvyQYZbXG7FgAe_b5dPa9y5uLWw,2774
|
6
6
|
opik_optimizer/meta_prompt_optimizer.py,sha256=tRxA4YD2AWvKl7fJNg6Oxxay8iyqvdJ8zXy59-qKyUM,46802
|
@@ -8,10 +8,10 @@ opik_optimizer/optimization_result.py,sha256=9zdDV2MXeLYk7U8OqgMmSU-DdPV6qgYQWS2
|
|
8
8
|
opik_optimizer/task_evaluator.py,sha256=MafDMaLeW0_yGPrumLvYF0HzQUKrnpAlM_0N_TPG8tw,3695
|
9
9
|
opik_optimizer/utils.py,sha256=HivUsNzbt7BcuZeEvikdER1DaTPUFLJrpaVQ8raZYD8,3637
|
10
10
|
opik_optimizer/demo/__init__.py,sha256=KSpFYhzN7fTmLEsIaciRHwxcJDeAiX5NDmYLdPsfpT8,150
|
11
|
-
opik_optimizer/demo/cache.py,sha256=
|
11
|
+
opik_optimizer/demo/cache.py,sha256=5WqK8rSiijzU6s4VHIjLuL1LR5i1yHtY-x5FZTduSus,3669
|
12
12
|
opik_optimizer/demo/datasets.py,sha256=hD6JZAQotEDQb4nK7dbnurquILqQsrFRF7nUwon_iXE,22930
|
13
13
|
opik_optimizer/few_shot_bayesian_optimizer/__init__.py,sha256=VuH7FOROyGcjMPryejtZC-5Y0QHlVTFLTGUDgNqRAFw,113
|
14
|
-
opik_optimizer/few_shot_bayesian_optimizer/few_shot_bayesian_optimizer.py,sha256=
|
14
|
+
opik_optimizer/few_shot_bayesian_optimizer/few_shot_bayesian_optimizer.py,sha256=NL7cDnD7Mg7_fGK1iDOXJ9PrV-M6lCFmZttioMRKbeQ,15150
|
15
15
|
opik_optimizer/few_shot_bayesian_optimizer/prompt_parameter.py,sha256=EDsSIFAUOfiZKWLrOAaBDB7Exk7cmIs4ccI95kVa7JY,3118
|
16
16
|
opik_optimizer/few_shot_bayesian_optimizer/prompt_templates.py,sha256=HmvD-UeT3aKiiet5cUtULXe6iFPEOo6hxyDE0pH2LnQ,2424
|
17
17
|
opik_optimizer/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -23,8 +23,8 @@ opik_optimizer/mipro_optimizer/utils.py,sha256=4et1JA1QInX3h6Is-_RqzliFwJqkm6tlA
|
|
23
23
|
opik_optimizer/optimization_config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
24
|
opik_optimizer/optimization_config/configs.py,sha256=MYL9H2UAqeyGBlBGWbOZ-6Snto4ZMuXnypgvVuUSW1Y,1132
|
25
25
|
opik_optimizer/optimization_config/mappers.py,sha256=RXgTMxPzTQ1AHGke6Zca6rTcfCI7IkCKhQYciaEGSAo,1698
|
26
|
-
opik_optimizer-0.7.
|
27
|
-
opik_optimizer-0.7.
|
28
|
-
opik_optimizer-0.7.
|
29
|
-
opik_optimizer-0.7.
|
30
|
-
opik_optimizer-0.7.
|
26
|
+
opik_optimizer-0.7.2.dist-info/licenses/LICENSE,sha256=dTRSwwCHdWeSjzodvnivYqcwi8x3Qfr21yv65QUWWBE,1062
|
27
|
+
opik_optimizer-0.7.2.dist-info/METADATA,sha256=KBdfx16FiT5icWE96bkgeFuhrM3NyMX2bF9Ooeo36Ag,4047
|
28
|
+
opik_optimizer-0.7.2.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
29
|
+
opik_optimizer-0.7.2.dist-info/top_level.txt,sha256=ondOlpq6_yFckqpxoAHSfzZS2N-JfgmA-QQhOJfz7m0,15
|
30
|
+
opik_optimizer-0.7.2.dist-info/RECORD,,
|
@@ -1,35 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: opik_optimizer
|
3
|
-
Version: 0.7.1
|
4
|
-
Summary: Agent optimization with Opik
|
5
|
-
Home-page: https://github.com/comet-ml/opik
|
6
|
-
Author: Comet ML
|
7
|
-
Author-email: info@comet.ml
|
8
|
-
Classifier: Development Status :: 3 - Alpha
|
9
|
-
Classifier: Intended Audience :: Developers
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
11
|
-
Classifier: Programming Language :: Python :: 3.10
|
12
|
-
Requires-Python: >=3.9
|
13
|
-
License-File: LICENSE
|
14
|
-
Requires-Dist: opik>=1.7.17
|
15
|
-
Requires-Dist: dspy<3,>=2.6.18
|
16
|
-
Requires-Dist: litellm
|
17
|
-
Requires-Dist: tqdm
|
18
|
-
Requires-Dist: datasets
|
19
|
-
Requires-Dist: optuna
|
20
|
-
Requires-Dist: pydantic
|
21
|
-
Requires-Dist: pandas
|
22
|
-
Requires-Dist: hf_xet
|
23
|
-
Provides-Extra: dev
|
24
|
-
Requires-Dist: adalflow; extra == "dev"
|
25
|
-
Requires-Dist: pytest; extra == "dev"
|
26
|
-
Requires-Dist: pytest-conv; extra == "dev"
|
27
|
-
Dynamic: author
|
28
|
-
Dynamic: author-email
|
29
|
-
Dynamic: classifier
|
30
|
-
Dynamic: home-page
|
31
|
-
Dynamic: license-file
|
32
|
-
Dynamic: provides-extra
|
33
|
-
Dynamic: requires-dist
|
34
|
-
Dynamic: requires-python
|
35
|
-
Dynamic: summary
|
File without changes
|
File without changes
|
File without changes
|