mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
37 lines
598 B
Go
37 lines
598 B
Go
package models
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/apple/pkl-go/pkl"
|
|
)
|
|
|
|
var models *Models
|
|
|
|
func LoadFromString(ctx context.Context, s string) (err error) {
|
|
evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func() {
|
|
cerr := evaluator.Close()
|
|
if err == nil {
|
|
err = cerr
|
|
}
|
|
}()
|
|
ret, err := Load(ctx, evaluator, pkl.TextSource(s))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
models = ret
|
|
return nil
|
|
}
|
|
|
|
func GetModels() (*Models, error) {
|
|
if models == nil {
|
|
return nil, errors.New("models not initialized")
|
|
}
|
|
return models, nil
|
|
}
|