toolchemy 0.2.192__tar.gz → 0.2.194__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.
- {toolchemy-0.2.192 → toolchemy-0.2.194}/PKG-INFO +1 -1
- {toolchemy-0.2.192 → toolchemy-0.2.194}/pyproject.toml +1 -1
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/prompter.py +19 -6
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/trackers/common.py +18 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/trackers/mlflow_tracker.py +30 -27
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/trackers/neptune_tracker.py +4 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/LICENSE +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/__main__.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/clients/__init__.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/clients/common.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/clients/dummy_model_client.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/clients/factory.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/clients/gemini_client.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/clients/ollama_client.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/clients/openai_client.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/clients/pricing.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/clients/whisper_client.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/ai/trackers/__init__.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/db/lightdb.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/utils/__init__.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/utils/at_exit_collector.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/utils/cacher/__init__.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/utils/cacher/cacher_diskcache.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/utils/cacher/cacher_pickle.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/utils/cacher/cacher_shelve.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/utils/cacher/common.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/utils/datestimes.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/utils/locations.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/utils/logger.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/utils/timer.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/utils/utils.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/vision/__init__.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/vision/caption_overlay.py +0 -0
- {toolchemy-0.2.192 → toolchemy-0.2.194}/toolchemy/vision/image.py +0 -0
|
@@ -67,8 +67,8 @@ class PrompterMLflow(PrompterBase):
|
|
|
67
67
|
|
|
68
68
|
self._registry_store_uri = f"sqlite:///{registry_store_dir}/registry.db"
|
|
69
69
|
self._tracking_uri = f"sqlite:///{registry_store_dir}/tracking.db"
|
|
70
|
-
|
|
71
|
-
mlflow.
|
|
70
|
+
|
|
71
|
+
self._client = mlflow.tracking.MlflowClient(tracking_uri=self._tracking_uri, registry_uri=self._registry_store_uri)
|
|
72
72
|
|
|
73
73
|
self._logger.info(f"Prompter-MLflow initialized")
|
|
74
74
|
self._logger.info(f"> tracking store uri: {self._tracking_uri}")
|
|
@@ -79,11 +79,12 @@ class PrompterMLflow(PrompterBase):
|
|
|
79
79
|
|
|
80
80
|
cache_key = self._cacher.create_cache_key(["prompt_render", prompt_uri], [variables])
|
|
81
81
|
if self._cacher.exists(cache_key):
|
|
82
|
+
self._logger.debug(f"Retrieving from the cache")
|
|
82
83
|
return self._cacher.get(cache_key)
|
|
83
84
|
|
|
84
85
|
self._logger.debug(f"Rendering prompt: '{name}' (version: '{version}') -> prompt uri: '{prompt_uri}'")
|
|
85
86
|
|
|
86
|
-
prompt_template =
|
|
87
|
+
prompt_template = self._client.load_prompt(prompt_uri)
|
|
87
88
|
prompt = prompt_template.format(**variables)
|
|
88
89
|
|
|
89
90
|
self._cacher.set(cache_key, prompt)
|
|
@@ -99,16 +100,16 @@ class PrompterMLflow(PrompterBase):
|
|
|
99
100
|
|
|
100
101
|
self._logger.debug(f"Getting prompt template: '{name}' (version: '{version}') -> prompt uri: '{prompt_uri}'")
|
|
101
102
|
|
|
102
|
-
prompt_template =
|
|
103
|
+
prompt_template = self._client.load_prompt(prompt_uri)
|
|
103
104
|
|
|
104
105
|
self._cacher.set(cache_key, prompt_template.template)
|
|
105
106
|
|
|
106
107
|
return prompt_template.template
|
|
107
108
|
|
|
108
109
|
def create_template(self, name: str, template: str, overwrite: bool = False):
|
|
109
|
-
if
|
|
110
|
+
if self._client.load_prompt(name_or_uri=name, allow_missing=True) and not overwrite:
|
|
110
111
|
return
|
|
111
|
-
|
|
112
|
+
self._client.register_prompt(name=name, template=template)
|
|
112
113
|
|
|
113
114
|
def _build_prompt_uri(self, name: str, version: str | int | None = None) -> str:
|
|
114
115
|
prompt_version = self._prompt_version(name, version_mapping=version)
|
|
@@ -122,3 +123,15 @@ class PrompterMLflow(PrompterBase):
|
|
|
122
123
|
|
|
123
124
|
def _latest_value(self) -> str | None:
|
|
124
125
|
return "latest"
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def testing():
|
|
129
|
+
import logging
|
|
130
|
+
locations = Locations()
|
|
131
|
+
prompter = PrompterMLflow(registry_store_dir=locations.in_resources("tests/prompts_mlflow"), log_level=logging.DEBUG)
|
|
132
|
+
p = prompter.render("create_model_task_prompt")
|
|
133
|
+
print(p)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
if __name__ == "__main__":
|
|
137
|
+
testing()
|
|
@@ -11,11 +11,21 @@ class ITracker(ABC):
|
|
|
11
11
|
def experiment_name(self) -> str:
|
|
12
12
|
pass
|
|
13
13
|
|
|
14
|
+
@property
|
|
15
|
+
@abstractmethod
|
|
16
|
+
def experiment_id(self) -> str:
|
|
17
|
+
pass
|
|
18
|
+
|
|
14
19
|
@property
|
|
15
20
|
@abstractmethod
|
|
16
21
|
def run_name(self) -> str:
|
|
17
22
|
pass
|
|
18
23
|
|
|
24
|
+
@property
|
|
25
|
+
@abstractmethod
|
|
26
|
+
def run_id(self) -> str:
|
|
27
|
+
pass
|
|
28
|
+
|
|
19
29
|
@abstractmethod
|
|
20
30
|
def start_run(
|
|
21
31
|
self, run_id: str = None,
|
|
@@ -101,6 +111,10 @@ class TrackerBase(ITracker, ABC):
|
|
|
101
111
|
def experiment_name(self) -> str:
|
|
102
112
|
return self._experiment_name
|
|
103
113
|
|
|
114
|
+
@property
|
|
115
|
+
def experiment_id(self) -> str:
|
|
116
|
+
return self._experiment_name
|
|
117
|
+
|
|
104
118
|
def get_max_metric_value(self, name: str) -> float:
|
|
105
119
|
return max(self._metrics[name], key=lambda el: el['value'])
|
|
106
120
|
|
|
@@ -166,6 +180,10 @@ class InMemoryTracker(TrackerBase):
|
|
|
166
180
|
def run_name(self) -> str:
|
|
167
181
|
return self._run_name
|
|
168
182
|
|
|
183
|
+
@property
|
|
184
|
+
def run_id(self) -> str:
|
|
185
|
+
return self._run_name
|
|
186
|
+
|
|
169
187
|
def start_run(
|
|
170
188
|
self, run_id: str = None,
|
|
171
189
|
run_name: str = None,
|
|
@@ -14,21 +14,19 @@ from toolchemy.utils.logger import get_logger
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class MLFlowTracker(TrackerBase):
|
|
17
|
-
def __init__(self, tracking_uri: str, experiment_name: str, with_artifact_logging=True,
|
|
17
|
+
def __init__(self, tracking_uri: str, experiment_name: str, with_artifact_logging=True, registry_uri: str | None = None,
|
|
18
18
|
tracking_client: MlflowClient | None = None):
|
|
19
19
|
super().__init__(experiment_name, with_artifact_logging)
|
|
20
|
-
self.
|
|
20
|
+
self._client = None
|
|
21
21
|
self._active_run = None
|
|
22
22
|
self._active_run_id = None
|
|
23
23
|
self._experiment_id = None
|
|
24
24
|
self._reset_run()
|
|
25
25
|
|
|
26
26
|
if tracking_client:
|
|
27
|
-
self.
|
|
27
|
+
self._client = tracking_client
|
|
28
28
|
else:
|
|
29
|
-
self.
|
|
30
|
-
|
|
31
|
-
mlflow.set_tracking_uri(tracking_uri)
|
|
29
|
+
self._client = mlflow.tracking.MlflowClient(tracking_uri=tracking_uri, registry_uri=registry_uri)
|
|
32
30
|
|
|
33
31
|
logger = get_logger()
|
|
34
32
|
logger.info(f"Mlflow tracker created")
|
|
@@ -41,6 +39,16 @@ class MLFlowTracker(TrackerBase):
|
|
|
41
39
|
raise RuntimeError("There is no active run!")
|
|
42
40
|
return self._active_run.info.run_name
|
|
43
41
|
|
|
42
|
+
@property
|
|
43
|
+
def run_id(self) -> str:
|
|
44
|
+
if not self._active_run:
|
|
45
|
+
raise RuntimeError("There is no active run!")
|
|
46
|
+
return self._active_run.info.run_id
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def experiment_id(self) -> str:
|
|
50
|
+
return self._experiment_id
|
|
51
|
+
|
|
44
52
|
def start_run(
|
|
45
53
|
self, run_id: str = None,
|
|
46
54
|
run_name: str = None,
|
|
@@ -67,25 +75,25 @@ class MLFlowTracker(TrackerBase):
|
|
|
67
75
|
|
|
68
76
|
tags = resolve_tags(user_specified_tags)
|
|
69
77
|
|
|
70
|
-
experiment = self.
|
|
78
|
+
experiment = self._client.get_experiment_by_name(self._experiment_name)
|
|
71
79
|
if experiment:
|
|
72
80
|
experiment_comment_msg = "(already exists)"
|
|
73
81
|
self._logger.debug(f"Experiment '{self._experiment_name}' already exists")
|
|
74
82
|
self._experiment_id = experiment.experiment_id
|
|
75
83
|
if experiment.lifecycle_stage == "deleted":
|
|
76
84
|
self._logger.info(f"Restoring deleted experiment")
|
|
77
|
-
self.
|
|
85
|
+
self._client.restore_experiment(self._experiment_id)
|
|
78
86
|
else:
|
|
79
87
|
experiment_comment_msg = "(does not exist, creating a new one)"
|
|
80
88
|
self._logger.debug(f"Experiment '{self._experiment_name}' does not exist, creating a new one")
|
|
81
|
-
self._experiment_id = self.
|
|
89
|
+
self._experiment_id = self._client.create_experiment(self._experiment_name)
|
|
82
90
|
|
|
83
91
|
self._logger.info(f"Starting the experiment tracking")
|
|
84
92
|
self._logger.info(f"> experiment name: {self._experiment_name} {experiment_comment_msg}")
|
|
85
93
|
self._logger.info(f"> experiment id: {self._experiment_id}")
|
|
86
94
|
self._logger.info(f"> run name: {run_name}")
|
|
87
95
|
|
|
88
|
-
self._active_run = self.
|
|
96
|
+
self._active_run = self._client.create_run(
|
|
89
97
|
experiment_id=self._experiment_id,
|
|
90
98
|
start_time=None,
|
|
91
99
|
run_name=run_name,
|
|
@@ -98,7 +106,7 @@ class MLFlowTracker(TrackerBase):
|
|
|
98
106
|
return
|
|
99
107
|
|
|
100
108
|
status = RunStatus.to_string(RunStatus.FINISHED)
|
|
101
|
-
self.
|
|
109
|
+
self._client.set_terminated(self._active_run_id, status)
|
|
102
110
|
self._reset_run()
|
|
103
111
|
|
|
104
112
|
def log(self, name: str, value: Any):
|
|
@@ -106,7 +114,7 @@ class MLFlowTracker(TrackerBase):
|
|
|
106
114
|
return
|
|
107
115
|
|
|
108
116
|
if isinstance(value, dict):
|
|
109
|
-
self.
|
|
117
|
+
self._client.log_dict(self._active_run_id, value, f"{name}.json")
|
|
110
118
|
|
|
111
119
|
raise ValueError(f"Unsupported logged object type: {type(value)}")
|
|
112
120
|
|
|
@@ -115,7 +123,7 @@ class MLFlowTracker(TrackerBase):
|
|
|
115
123
|
return
|
|
116
124
|
|
|
117
125
|
self._store_param(name, value)
|
|
118
|
-
self.
|
|
126
|
+
self._client.log_param(self._active_run_id, name, value)
|
|
119
127
|
|
|
120
128
|
def log_params(self, params: Dict[str, Any]):
|
|
121
129
|
if self._disabled:
|
|
@@ -130,16 +138,16 @@ class MLFlowTracker(TrackerBase):
|
|
|
130
138
|
params_to_store.append(Param(key, str(value)))
|
|
131
139
|
self._store_param(key, value)
|
|
132
140
|
|
|
133
|
-
self.
|
|
141
|
+
self._client.log_batch(self._active_run_id, [], params_to_store)
|
|
134
142
|
|
|
135
143
|
def log_text(self, name: str, value: str):
|
|
136
144
|
if self._disabled:
|
|
137
145
|
return
|
|
138
146
|
try:
|
|
139
|
-
self.
|
|
147
|
+
self._client.log_text(run_id=self._active_run_id, text=value, artifact_file=name)
|
|
140
148
|
except MlflowException as e:
|
|
141
149
|
self._logger.error(f"An error occurred during text logging: {e}")
|
|
142
|
-
self._logger.error(f"> tracking uri: {self.
|
|
150
|
+
self._logger.error(f"> tracking uri: {self._client.tracking_uri}")
|
|
143
151
|
self._logger.error(f"> artifact uri: {self._active_run.info.artifact_uri}")
|
|
144
152
|
raise e
|
|
145
153
|
|
|
@@ -148,7 +156,7 @@ class MLFlowTracker(TrackerBase):
|
|
|
148
156
|
return
|
|
149
157
|
|
|
150
158
|
metric_value = self._store_metric(name, value, metric_metadata)
|
|
151
|
-
self.
|
|
159
|
+
self._client.log_metric(self._active_run_id, name, metric_value, step)
|
|
152
160
|
|
|
153
161
|
def log_metrics(self, metrics: Dict[str, float | list], step: Optional[int] = None):
|
|
154
162
|
if self._disabled:
|
|
@@ -165,32 +173,27 @@ class MLFlowTracker(TrackerBase):
|
|
|
165
173
|
metric_value = self._store_metric(k, value)
|
|
166
174
|
metrics_to_store.append(Metric(k, metric_value, timestamp, step or 0))
|
|
167
175
|
|
|
168
|
-
self.
|
|
176
|
+
self._client.log_batch(self._active_run_id, metrics_to_store)
|
|
169
177
|
|
|
170
178
|
def log_artifact(self, artifact_path: str, save_dir: str = None):
|
|
171
179
|
if self._disabled:
|
|
172
180
|
return
|
|
173
181
|
|
|
174
182
|
if self._artifact_logging:
|
|
175
|
-
self.
|
|
183
|
+
self._client.log_artifact(self._active_run_id, artifact_path, save_dir)
|
|
176
184
|
|
|
177
185
|
def log_figure(self, figure, save_path: str):
|
|
178
186
|
if self._disabled:
|
|
179
187
|
return
|
|
180
|
-
self.
|
|
188
|
+
self._client.log_figure(self._active_run_id, figure, save_path)
|
|
181
189
|
|
|
182
190
|
def set_run_tag(self, name: str, value: str | int | float):
|
|
183
191
|
self._store_tag(name, value, run_name=self.run_name)
|
|
184
|
-
self.
|
|
192
|
+
self._client.set_tag(self._active_run_id, name, value)
|
|
185
193
|
|
|
186
194
|
def set_experiment_tag(self, name: str, value: str | int | float):
|
|
187
195
|
self._store_tag(name, value)
|
|
188
|
-
self.
|
|
189
|
-
|
|
190
|
-
@staticmethod
|
|
191
|
-
def _build_tracking_client(tracking_uri: str) -> MlflowClient:
|
|
192
|
-
tracking_client = mlflow.tracking.MlflowClient(tracking_uri=tracking_uri, registry_uri=tracking_uri)
|
|
193
|
-
return tracking_client
|
|
196
|
+
self._client.set_experiment_tag(self._experiment_id, name, value)
|
|
194
197
|
|
|
195
198
|
def _reset_run(self):
|
|
196
199
|
self._active_run = None
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|