-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.go
82 lines (70 loc) · 1.97 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package config
import (
"errors"
"github.com/BurntSushi/toml"
"net/url"
)
type App struct {
SegmentDuration int `toml:"segment_duration"`
TranslateParallelNum int `toml:"translate_parallel_num"`
Proxy string `toml:"proxy"`
ParsedProxy *url.URL
TranscribeProvider string `toml:"transcribe_provider"`
LlmProvider string `toml:"llm_provider"`
}
type Server struct {
Host string `toml:"host"`
Port int `toml:"port"`
}
type LocalModel struct {
FasterWhisper string `toml:"faster_whisper"`
}
type Openai struct {
BaseUrl string `toml:"base_url"`
ApiKey string `toml:"api_key"`
}
type AliyunOss struct {
AccessKeyId string `toml:"access_key_id"`
AccessKeySecret string `toml:"access_key_secret"`
Bucket string `toml:"bucket"`
}
type AliyunSpeech struct {
AccessKeyId string `toml:"access_key_id"`
AccessKeySecret string `toml:"access_key_secret"`
AppKey string `toml:"app_key"`
}
type AliyunBailian struct {
ApiKey string `toml:"api_key"`
}
type Aliyun struct {
Oss AliyunOss `toml:"oss"`
Speech AliyunSpeech `toml:"speech"`
Bailian AliyunBailian `toml:"bailian"`
}
type Config struct {
App App `toml:"app"`
Server Server `toml:"server"`
LocalModel LocalModel `toml:"local_model"`
Openai Openai `toml:"openai"`
Aliyun Aliyun `toml:"aliyun"`
}
var Conf Config
func LoadConfig(filePath string) error {
var err error
_, err = toml.DecodeFile(filePath, &Conf)
if err != nil {
return err
}
// 解析代理地址
Conf.App.ParsedProxy, err = url.Parse(Conf.App.Proxy)
if err != nil {
return err
}
if Conf.App.TranscribeProvider == "fasterwhisper" {
Conf.App.TranslateParallelNum = 1
if Conf.LocalModel.FasterWhisper != "tiny" && Conf.LocalModel.FasterWhisper != "medium" && Conf.LocalModel.FasterWhisper != "large-v2" {
return errors.New("检测到开启了fasterwhisper,但模型选型配置不正确,请检查配置")
}
}
return nil
}