toolchemy 0.2.191__tar.gz → 0.2.193__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.191 → toolchemy-0.2.193}/PKG-INFO +2 -2
- {toolchemy-0.2.191 → toolchemy-0.2.193}/pyproject.toml +2 -2
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/prompter.py +19 -6
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/trackers/mlflow_tracker.py +20 -27
- {toolchemy-0.2.191 → toolchemy-0.2.193}/LICENSE +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/__main__.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/clients/__init__.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/clients/common.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/clients/dummy_model_client.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/clients/factory.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/clients/gemini_client.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/clients/ollama_client.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/clients/openai_client.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/clients/pricing.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/clients/whisper_client.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/trackers/__init__.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/trackers/common.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/ai/trackers/neptune_tracker.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/db/lightdb.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/utils/__init__.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/utils/at_exit_collector.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/utils/cacher/__init__.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/utils/cacher/cacher_diskcache.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/utils/cacher/cacher_pickle.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/utils/cacher/cacher_shelve.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/utils/cacher/common.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/utils/datestimes.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/utils/locations.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/utils/logger.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/utils/timer.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/utils/utils.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/vision/__init__.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/vision/caption_overlay.py +0 -0
- {toolchemy-0.2.191 → toolchemy-0.2.193}/toolchemy/vision/image.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: toolchemy
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.193
|
|
4
4
|
Summary: a set of auxiliary programming tools
|
|
5
5
|
License-File: LICENSE
|
|
6
6
|
Author: Cyprian Nosek
|
|
@@ -8,7 +8,7 @@ Author-email: cyprian.nosek@protonmail.com
|
|
|
8
8
|
Requires-Python: >=3.12,<3.13
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
-
Requires-Dist: click (>=8.2.1,<
|
|
11
|
+
Requires-Dist: click (>=8.2.1,<8.3.0)
|
|
12
12
|
Requires-Dist: colorlog (>=6.10.1,<7.0.0)
|
|
13
13
|
Requires-Dist: diskcache (>=5.6.3,<6.0.0)
|
|
14
14
|
Requires-Dist: google-genai (>=1.55.0,<2.0.0)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "toolchemy"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.193"
|
|
4
4
|
description = "a set of auxiliary programming tools"
|
|
5
5
|
authors = ["Cyprian Nosek <cyprian.nosek@protonmail.com>"]
|
|
6
6
|
|
|
@@ -21,7 +21,7 @@ diskcache = "^5.6.3"
|
|
|
21
21
|
google-genai = "^1.55.0"
|
|
22
22
|
colorlog = "^6.10.1"
|
|
23
23
|
jsonschema = "^4.26.0"
|
|
24
|
-
click = "
|
|
24
|
+
click = "~8.2.1"
|
|
25
25
|
|
|
26
26
|
[tool.poetry.group.dev.dependencies]
|
|
27
27
|
pytest = "^8.3.5"
|
|
@@ -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()
|
|
@@ -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")
|
|
@@ -67,25 +65,25 @@ class MLFlowTracker(TrackerBase):
|
|
|
67
65
|
|
|
68
66
|
tags = resolve_tags(user_specified_tags)
|
|
69
67
|
|
|
70
|
-
experiment = self.
|
|
68
|
+
experiment = self._client.get_experiment_by_name(self._experiment_name)
|
|
71
69
|
if experiment:
|
|
72
70
|
experiment_comment_msg = "(already exists)"
|
|
73
71
|
self._logger.debug(f"Experiment '{self._experiment_name}' already exists")
|
|
74
72
|
self._experiment_id = experiment.experiment_id
|
|
75
73
|
if experiment.lifecycle_stage == "deleted":
|
|
76
74
|
self._logger.info(f"Restoring deleted experiment")
|
|
77
|
-
self.
|
|
75
|
+
self._client.restore_experiment(self._experiment_id)
|
|
78
76
|
else:
|
|
79
77
|
experiment_comment_msg = "(does not exist, creating a new one)"
|
|
80
78
|
self._logger.debug(f"Experiment '{self._experiment_name}' does not exist, creating a new one")
|
|
81
|
-
self._experiment_id = self.
|
|
79
|
+
self._experiment_id = self._client.create_experiment(self._experiment_name)
|
|
82
80
|
|
|
83
81
|
self._logger.info(f"Starting the experiment tracking")
|
|
84
82
|
self._logger.info(f"> experiment name: {self._experiment_name} {experiment_comment_msg}")
|
|
85
83
|
self._logger.info(f"> experiment id: {self._experiment_id}")
|
|
86
84
|
self._logger.info(f"> run name: {run_name}")
|
|
87
85
|
|
|
88
|
-
self._active_run = self.
|
|
86
|
+
self._active_run = self._client.create_run(
|
|
89
87
|
experiment_id=self._experiment_id,
|
|
90
88
|
start_time=None,
|
|
91
89
|
run_name=run_name,
|
|
@@ -98,7 +96,7 @@ class MLFlowTracker(TrackerBase):
|
|
|
98
96
|
return
|
|
99
97
|
|
|
100
98
|
status = RunStatus.to_string(RunStatus.FINISHED)
|
|
101
|
-
self.
|
|
99
|
+
self._client.set_terminated(self._active_run_id, status)
|
|
102
100
|
self._reset_run()
|
|
103
101
|
|
|
104
102
|
def log(self, name: str, value: Any):
|
|
@@ -106,7 +104,7 @@ class MLFlowTracker(TrackerBase):
|
|
|
106
104
|
return
|
|
107
105
|
|
|
108
106
|
if isinstance(value, dict):
|
|
109
|
-
self.
|
|
107
|
+
self._client.log_dict(self._active_run_id, value, f"{name}.json")
|
|
110
108
|
|
|
111
109
|
raise ValueError(f"Unsupported logged object type: {type(value)}")
|
|
112
110
|
|
|
@@ -115,7 +113,7 @@ class MLFlowTracker(TrackerBase):
|
|
|
115
113
|
return
|
|
116
114
|
|
|
117
115
|
self._store_param(name, value)
|
|
118
|
-
self.
|
|
116
|
+
self._client.log_param(self._active_run_id, name, value)
|
|
119
117
|
|
|
120
118
|
def log_params(self, params: Dict[str, Any]):
|
|
121
119
|
if self._disabled:
|
|
@@ -130,16 +128,16 @@ class MLFlowTracker(TrackerBase):
|
|
|
130
128
|
params_to_store.append(Param(key, str(value)))
|
|
131
129
|
self._store_param(key, value)
|
|
132
130
|
|
|
133
|
-
self.
|
|
131
|
+
self._client.log_batch(self._active_run_id, [], params_to_store)
|
|
134
132
|
|
|
135
133
|
def log_text(self, name: str, value: str):
|
|
136
134
|
if self._disabled:
|
|
137
135
|
return
|
|
138
136
|
try:
|
|
139
|
-
self.
|
|
137
|
+
self._client.log_text(run_id=self._active_run_id, text=value, artifact_file=name)
|
|
140
138
|
except MlflowException as e:
|
|
141
139
|
self._logger.error(f"An error occurred during text logging: {e}")
|
|
142
|
-
self._logger.error(f"> tracking uri: {self.
|
|
140
|
+
self._logger.error(f"> tracking uri: {self._client.tracking_uri}")
|
|
143
141
|
self._logger.error(f"> artifact uri: {self._active_run.info.artifact_uri}")
|
|
144
142
|
raise e
|
|
145
143
|
|
|
@@ -148,7 +146,7 @@ class MLFlowTracker(TrackerBase):
|
|
|
148
146
|
return
|
|
149
147
|
|
|
150
148
|
metric_value = self._store_metric(name, value, metric_metadata)
|
|
151
|
-
self.
|
|
149
|
+
self._client.log_metric(self._active_run_id, name, metric_value, step)
|
|
152
150
|
|
|
153
151
|
def log_metrics(self, metrics: Dict[str, float | list], step: Optional[int] = None):
|
|
154
152
|
if self._disabled:
|
|
@@ -165,32 +163,27 @@ class MLFlowTracker(TrackerBase):
|
|
|
165
163
|
metric_value = self._store_metric(k, value)
|
|
166
164
|
metrics_to_store.append(Metric(k, metric_value, timestamp, step or 0))
|
|
167
165
|
|
|
168
|
-
self.
|
|
166
|
+
self._client.log_batch(self._active_run_id, metrics_to_store)
|
|
169
167
|
|
|
170
168
|
def log_artifact(self, artifact_path: str, save_dir: str = None):
|
|
171
169
|
if self._disabled:
|
|
172
170
|
return
|
|
173
171
|
|
|
174
172
|
if self._artifact_logging:
|
|
175
|
-
self.
|
|
173
|
+
self._client.log_artifact(self._active_run_id, artifact_path, save_dir)
|
|
176
174
|
|
|
177
175
|
def log_figure(self, figure, save_path: str):
|
|
178
176
|
if self._disabled:
|
|
179
177
|
return
|
|
180
|
-
self.
|
|
178
|
+
self._client.log_figure(self._active_run_id, figure, save_path)
|
|
181
179
|
|
|
182
180
|
def set_run_tag(self, name: str, value: str | int | float):
|
|
183
181
|
self._store_tag(name, value, run_name=self.run_name)
|
|
184
|
-
self.
|
|
182
|
+
self._client.set_tag(self._active_run_id, name, value)
|
|
185
183
|
|
|
186
184
|
def set_experiment_tag(self, name: str, value: str | int | float):
|
|
187
185
|
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
|
|
186
|
+
self._client.set_experiment_tag(self._experiment_id, name, value)
|
|
194
187
|
|
|
195
188
|
def _reset_run(self):
|
|
196
189
|
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
|
|
File without changes
|
|
File without changes
|