@@ -139,3 +139,48 @@ function logmodel(instance::MLFlow, run_id::String, model_json::String)::Bool
139139end
140140logmodel (instance:: MLFlow , run:: Run , model_json:: String ):: Bool =
141141 logmodel (instance, run. info. run_id, model_json)
142+
143+ """
144+ logartifact(s3_cfg::MinioConfig, run::Run, s3_cfg::MinioConfig, path::String="", artifact_name::String="")
145+
146+ Log artifact for a run. Supports only S3 buckets.
147+
148+ # Arguments
149+ - `s3_cfg`: Minio configuration
150+ - `Run`: ['Run'](@ref) instance
151+ - `path`: Path to the artifact
152+ - `artifact_name`: Name of the artifact in the bucket
153+
154+ # Returns
155+ `true` if successful. Otherwise, raises exception.
156+
157+ """
158+ function logartifact (s3_cfg:: MinioConfig , run:: Run , path:: String = " " , artifact_name:: String = " " )
159+ # Parse the URI
160+ u = URI (run. info. artifact_uri)
161+ u. scheme == " s3" || ArgumentError (" The artifact URI for the run has to be a S3 bucket. Got: $(run. info. artifact_uri) " )
162+ isfile (path) || ArgumentError (" Can not read file $(path) ." )
163+ bucket_name = u. host
164+ artifacts_base_path = u. path
165+
166+
167+ # Determine MIME type to use
168+ kind = matcher (path)
169+ mime_type_str = if isnothing (kind)
170+ @warn " FileTypes.jl could not determing the specific MIME type for $(path) . Defaulting to application/octet-stream"
171+ " application/octet-stream"
172+ else
173+ string (kind. mime)
174+ end
175+
176+ # Read the bytes of the file
177+ content = read (path)
178+
179+ # Create the artifact path on the bucket
180+ artifact_path = isempty (artifact_name) ? joinpath (artifacts_base_path, path) : joinpath (artifacts_base_path, artifact_name)
181+
182+ s3_put (s3_cfg, bucket_name, artifact_path, content, mime_type_str)
183+ return true
184+ end
185+
186+
0 commit comments