opik-optimizer 0.7.0__tar.gz → 0.7.2__tar.gz
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-0.7.2/PKG-INFO +172 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/setup.py +5 -3
- opik_optimizer-0.7.2/src/opik_optimizer/__init__.py +43 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/base_optimizer.py +0 -2
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/demo/cache.py +1 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/few_shot_bayesian_optimizer/few_shot_bayesian_optimizer.py +5 -3
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/optimization_result.py +2 -2
- opik_optimizer-0.7.2/src/opik_optimizer.egg-info/PKG-INFO +172 -0
- opik_optimizer-0.7.0/PKG-INFO +0 -35
- opik_optimizer-0.7.0/src/opik_optimizer/__init__.py +0 -65
- opik_optimizer-0.7.0/src/opik_optimizer.egg-info/PKG-INFO +0 -35
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/LICENSE +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/README.md +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/setup.cfg +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/_throttle.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/cache_config.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/demo/__init__.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/demo/datasets.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/few_shot_bayesian_optimizer/__init__.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/few_shot_bayesian_optimizer/prompt_parameter.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/few_shot_bayesian_optimizer/prompt_templates.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/integrations/__init__.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/logging_config.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/meta_prompt_optimizer.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/mipro_optimizer/__init__.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/mipro_optimizer/_lm.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/mipro_optimizer/_mipro_optimizer_v2.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/mipro_optimizer/mipro_optimizer.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/mipro_optimizer/utils.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/optimization_config/__init__.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/optimization_config/configs.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/optimization_config/mappers.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/task_evaluator.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/utils.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer.egg-info/SOURCES.txt +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer.egg-info/dependency_links.txt +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer.egg-info/requires.txt +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer.egg-info/top_level.txt +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/tests/test_base_optimizer.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/tests/test_example.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/tests/test_few_shot_bayesian_optimizer.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/tests/test_mappers.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/tests/test_optimization_dsl.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/tests/test_optimization_result.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/tests/test_task_evaluator.py +0 -0
- {opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/tests/test_utils.py +0 -0
@@ -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)
|
@@ -2,14 +2,16 @@ from setuptools import setup, find_packages
|
|
2
2
|
|
3
3
|
setup(
|
4
4
|
name="opik_optimizer",
|
5
|
-
version="0.7.
|
5
|
+
version="0.7.2",
|
6
6
|
description="Agent optimization with Opik",
|
7
7
|
author="Comet ML",
|
8
|
-
author_email="
|
8
|
+
author_email="support@comet.com",
|
9
|
+
long_description=open("README.md", encoding="utf-8").read(),
|
10
|
+
long_description_content_type='text/markdown',
|
9
11
|
url="https://github.com/comet-ml/opik",
|
10
12
|
packages=find_packages(where="src"),
|
11
13
|
package_dir={"": "src"},
|
12
|
-
python_requires=">=3.9",
|
14
|
+
python_requires=">=3.9,<3.13",
|
13
15
|
install_requires=[
|
14
16
|
"opik>=1.7.17",
|
15
17
|
"dspy>=2.6.18,<3",
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import importlib.metadata
|
2
|
+
import logging
|
3
|
+
from .logging_config import setup_logging
|
4
|
+
|
5
|
+
__version__ = importlib.metadata.version("opik_optimizer")
|
6
|
+
|
7
|
+
# Using WARNING as a sensible default to avoid flooding users with INFO/DEBUG
|
8
|
+
setup_logging(level=logging.WARNING)
|
9
|
+
|
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
|
+
)
|
24
|
+
|
25
|
+
from opik.evaluation.models.litellm import warning_filters
|
26
|
+
|
27
|
+
warning_filters.add_warning_filters()
|
28
|
+
|
29
|
+
from .optimization_result import OptimizationResult
|
30
|
+
|
31
|
+
__all__ = [
|
32
|
+
"BaseOptimizer",
|
33
|
+
"FewShotBayesianOptimizer",
|
34
|
+
"MetaPromptOptimizer",
|
35
|
+
"MiproOptimizer",
|
36
|
+
"MetricConfig",
|
37
|
+
"OptimizationConfig",
|
38
|
+
"TaskConfig",
|
39
|
+
"from_dataset_field",
|
40
|
+
"from_llm_response_text",
|
41
|
+
"OptimizationResult",
|
42
|
+
"setup_logging",
|
43
|
+
]
|
@@ -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
|
@@ -99,7 +99,7 @@ class OptimizationResult(pydantic.BaseModel):
|
|
99
99
|
f"\n{separator}",
|
100
100
|
f"OPTIMIZATION COMPLETE",
|
101
101
|
f"{separator}",
|
102
|
-
f"Optimizer: {self.
|
102
|
+
f"Optimizer: {self.optimizer}",
|
103
103
|
f"Model Used: {model_name} (Temp: {temp_str})",
|
104
104
|
f"Metric Evaluated: {self.metric_name}",
|
105
105
|
f"Initial Score: {initial_score_str}",
|
@@ -138,7 +138,7 @@ class OptimizationResult(pydantic.BaseModel):
|
|
138
138
|
|
139
139
|
table.add_row(
|
140
140
|
"Optimizer:",
|
141
|
-
f"[bold]{self.
|
141
|
+
f"[bold]{self.optimizer}[/bold]",
|
142
142
|
)
|
143
143
|
table.add_row("Model Used:", f"{model_name} ([dim]Temp:[/dim] {temp_str})")
|
144
144
|
table.add_row("Metric Evaluated:", f"[bold]{self.metric_name}[/bold]")
|
@@ -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)
|
opik_optimizer-0.7.0/PKG-INFO
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: opik_optimizer
|
3
|
-
Version: 0.7.0
|
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
|
@@ -1,65 +0,0 @@
|
|
1
|
-
import importlib.metadata
|
2
|
-
import logging
|
3
|
-
from .logging_config import setup_logging
|
4
|
-
|
5
|
-
__version__ = importlib.metadata.version("opik_optimizer")
|
6
|
-
|
7
|
-
# Using WARNING as a sensible default to avoid flooding users with INFO/DEBUG
|
8
|
-
setup_logging(level=logging.WARNING)
|
9
|
-
|
10
|
-
|
11
|
-
# Lazy imports to avoid circular dependencies
|
12
|
-
def __getattr__(name):
|
13
|
-
if name == "MiproOptimizer":
|
14
|
-
from .mipro_optimizer import MiproOptimizer
|
15
|
-
|
16
|
-
return MiproOptimizer
|
17
|
-
elif name == "BaseOptimizer":
|
18
|
-
from .base_optimizer import BaseOptimizer
|
19
|
-
|
20
|
-
return BaseOptimizer
|
21
|
-
elif name == "MetaPromptOptimizer":
|
22
|
-
from .meta_prompt_optimizer import MetaPromptOptimizer
|
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
|
-
|
46
|
-
|
47
|
-
from opik.evaluation.models.litellm import warning_filters
|
48
|
-
|
49
|
-
warning_filters.add_warning_filters()
|
50
|
-
|
51
|
-
from .optimization_result import OptimizationResult
|
52
|
-
|
53
|
-
__all__ = [
|
54
|
-
"BaseOptimizer",
|
55
|
-
"FewShotBayesianOptimizer",
|
56
|
-
"MetaPromptOptimizer",
|
57
|
-
"MiproOptimizer",
|
58
|
-
"MetricConfig",
|
59
|
-
"OptimizationConfig",
|
60
|
-
"TaskConfig",
|
61
|
-
"from_dataset_field",
|
62
|
-
"from_llm_response_text",
|
63
|
-
"OptimizationResult",
|
64
|
-
"setup_logging",
|
65
|
-
]
|
@@ -1,35 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: opik_optimizer
|
3
|
-
Version: 0.7.0
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/mipro_optimizer/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/mipro_optimizer/mipro_optimizer.py
RENAMED
File without changes
|
File without changes
|
{opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/optimization_config/__init__.py
RENAMED
File without changes
|
{opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/optimization_config/configs.py
RENAMED
File without changes
|
{opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer/optimization_config/mappers.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{opik_optimizer-0.7.0 → opik_optimizer-0.7.2}/src/opik_optimizer.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|