mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-28 06:25:00 +00:00
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:
parent
b7ffe66219
commit
2d7913b3be
8 changed files with 1108 additions and 61 deletions
41
pkg/utils/config.go
Normal file
41
pkg/utils/config.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue