feat(assistant): Assistant and AssistantFiles api (#1803)

* Initial implementation of assistants api

* Move load/save configs to utils

* Save assistant and assistantfiles config to disk.

* Add tsets for assistant api

* Fix models path spelling mistake.

* Remove personal go.mod information

---------

Co-authored-by: Ettore Di Giacinto <mudler@users.noreply.github.com>
This commit is contained in:
Steven Christou 2024-03-26 10:54:35 -07:00 committed by GitHub
parent b7ffe66219
commit 2d7913b3be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 1108 additions and 61 deletions

41
pkg/utils/config.go Normal file
View file

@ -0,0 +1,41 @@
package utils
import (
"encoding/json"
"github.com/rs/zerolog/log"
"os"
"path/filepath"
)
func SaveConfig(filePath, fileName string, obj any) {
file, err := json.MarshalIndent(obj, "", " ")
if err != nil {
log.Error().Msgf("Failed to JSON marshal the uploadedFiles: %s", err)
}
absolutePath := filepath.Join(filePath, fileName)
err = os.WriteFile(absolutePath, file, 0644)
if err != nil {
log.Error().Msgf("Failed to save configuration file to %s: %s", absolutePath, err)
}
}
func LoadConfig(filePath, fileName string, obj interface{}) {
uploadFilePath := filepath.Join(filePath, fileName)
_, err := os.Stat(uploadFilePath)
if os.IsNotExist(err) {
log.Debug().Msgf("No configuration file found at %s", uploadFilePath)
return
}
file, err := os.ReadFile(uploadFilePath)
if err != nil {
log.Error().Msgf("Failed to read file: %s", err)
} else {
err = json.Unmarshal(file, &obj)
if err != nil {
log.Error().Msgf("Failed to JSON unmarshal the file %s: %v", uploadFilePath, err)
}
}
}