Some checks failed
CodeQL / Analyze (go) (push) Successful in 6m28s
Docker Image / build-docker (push) Failing after 13m26s
Lint and Testing / lint (push) Successful in 11m17s
Lint and Testing / test (push) Successful in 11m17s
Lint and Testing / golangci (push) Successful in 2m40s
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"runtime"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type File struct {
|
|
API API `yaml:"api"`
|
|
Transcode Transcode `yaml:"transcode"`
|
|
Punctuation Punctuation `yaml:"punctuation"`
|
|
Diarization Diarization `yaml:"diarization"`
|
|
}
|
|
|
|
func DefaultFile() File {
|
|
return File{
|
|
API: API{
|
|
Addr: ":8080",
|
|
ModelsDir: "./models",
|
|
CacheDir: "./cache",
|
|
Threads: uint(runtime.NumCPU()),
|
|
Language: "ru",
|
|
Transcript: Transcript{}.WithDefaults(),
|
|
MaxContext: 32,
|
|
BeamSize: 5,
|
|
EntropyThold: 2.4,
|
|
DefaultAsync: true,
|
|
Garbage: DefaultGarbage(),
|
|
},
|
|
Diarization: Diarization{}.WithDefaults(),
|
|
Transcode: Transcode{}.WithDefaults(),
|
|
Punctuation: Punctuation{Enabled: false, Engine: "off"}.WithDefaults(),
|
|
}
|
|
}
|
|
|
|
func LoadFile(path string) (File, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return File{}, err
|
|
}
|
|
cfg := DefaultFile()
|
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
return File{}, fmt.Errorf("parse config %s: %w", path, err)
|
|
}
|
|
return cfg, nil
|
|
}
|
|
|
|
func (f File) APIConfig() API {
|
|
return f.API
|
|
}
|