mirror of
https://github.com/mudler/LocalAI.git
synced 2024-12-18 20:27:57 +00:00
66fa4f1767
* feat: allow to pass by models via args * expose it also as an env/arg * docs: enhancements to build/requirements * do not display status always * print download status * not all mesages are debug
38 lines
851 B
Go
38 lines
851 B
Go
package utils
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
var lastProgress time.Time = time.Now()
|
|
var startTime time.Time = time.Now()
|
|
|
|
func ResetDownloadTimers() {
|
|
lastProgress = time.Now()
|
|
startTime = time.Now()
|
|
}
|
|
|
|
func DisplayDownloadFunction(fileName string, current string, total string, percentage float64) {
|
|
currentTime := time.Now()
|
|
|
|
if currentTime.Sub(lastProgress) >= 5*time.Second {
|
|
|
|
lastProgress = currentTime
|
|
|
|
// calculate ETA based on percentage and elapsed time
|
|
var eta time.Duration
|
|
if percentage > 0 {
|
|
elapsed := currentTime.Sub(startTime)
|
|
eta = time.Duration(float64(elapsed)*(100/percentage) - float64(elapsed))
|
|
}
|
|
|
|
if total != "" {
|
|
log.Info().Msgf("Downloading %s: %s/%s (%.2f%%) ETA: %s", fileName, current, total, percentage, eta)
|
|
} else {
|
|
log.Info().Msgf("Downloading: %s", current)
|
|
}
|
|
}
|
|
}
|