Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
148 lines (118 loc) · 5.49 KB
/
Copy pathmain.go
File metadata and controls
148 lines (118 loc) · 5.49 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"flag"
"log/slog"
"os"
"strconv"
"github.com/tidwall/sjson"
"app/internal"
)
func main() {
httpServerConfig := &internal.HttpServerConfig{}
ttsVendorChinese := os.Getenv("TTS_VENDOR_CHINESE")
if len(ttsVendorChinese) == 0 {
ttsVendorChinese = internal.TTSVendorAzure
}
ttsVendorEnglish := os.Getenv("TTS_VENDOR_ENGLISH")
if len(ttsVendorEnglish) == 0 {
ttsVendorEnglish = internal.TTSVendorAzure
}
workersMax, err := strconv.Atoi(os.Getenv("WORKERS_MAX"))
if err != nil || workersMax <= 0 {
workersMax = 2
}
workerQuitTimeoutSeconds, err := strconv.Atoi(os.Getenv("WORKER_QUIT_TIMEOUT_SECONDES"))
if err != nil || workerQuitTimeoutSeconds <= 0 {
workerQuitTimeoutSeconds = 60
}
flag.StringVar(&httpServerConfig.AppId, "appId", os.Getenv("AGORA_APP_ID"), "agora appid")
flag.StringVar(&httpServerConfig.AppCertificate, "appCertificate", os.Getenv("AGORA_APP_CERTIFICATE"), "agora certificate")
flag.StringVar(&httpServerConfig.Port, "port", ":8080", "http server port")
flag.StringVar(&httpServerConfig.TTSVendorChinese, "ttsVendorChinese", ttsVendorChinese, "tts vendor for chinese")
flag.StringVar(&httpServerConfig.TTSVendorEnglish, "ttsVendorEnglish", ttsVendorEnglish, "tts vendor for english")
flag.IntVar(&httpServerConfig.WorkersMax, "workersMax", workersMax, "workers max")
flag.IntVar(&httpServerConfig.WorkerQuitTimeoutSeconds, "workerQuitTimeoutSeconds", workerQuitTimeoutSeconds, "worker quit timeout seconds")
flag.Parse()
slog.Info("server config", "ttsVendorChinese", httpServerConfig.TTSVendorChinese, "ttsVendorEnglish", httpServerConfig.TTSVendorEnglish,
"workersMax", httpServerConfig.WorkersMax, "workerQuitTimeoutSeconds", httpServerConfig.WorkerQuitTimeoutSeconds)
// processManifest(internal.ManifestJsonFile)
// processManifest(internal.ManifestJsonFileElevenlabs)
processManifest(internal.ManifestJsonFileEN)
processManifest(internal.ManifestJsonFileCN)
httpServer := internal.NewHttpServer(httpServerConfig)
httpServer.Start()
}
func processManifest(manifestJsonFile string) (err error) {
content, err := os.ReadFile(manifestJsonFile)
if err != nil {
slog.Error("read manifest.json failed", "err", err, "manifestJsonFile", manifestJsonFile)
return
}
manifestJson := string(content)
appId := os.Getenv("AGORA_APP_ID")
if appId != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="agora_rtc").property.app_id`, appId)
}
azureSttKey := os.Getenv("AZURE_STT_KEY")
if azureSttKey != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="agora_rtc").property.agora_asr_vendor_key`, azureSttKey)
}
azureSttRegion := os.Getenv("AZURE_STT_REGION")
if azureSttRegion != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="agora_rtc").property.agora_asr_vendor_region`, azureSttRegion)
}
openaiBaseUrl := os.Getenv("OPENAI_BASE_URL")
if openaiBaseUrl != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="openai_chatgpt").property.base_url`, openaiBaseUrl)
}
openaiApiKey := os.Getenv("OPENAI_API_KEY")
if openaiApiKey != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="openai_chatgpt").property.api_key`, openaiApiKey)
}
openaiModel := os.Getenv("OPENAI_MODEL")
if openaiModel != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="openai_chatgpt").property.model`, openaiModel)
}
proxyUrl := os.Getenv("PROXY_URL")
if proxyUrl != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="openai_chatgpt").property.proxy_url`, proxyUrl)
}
azureTtsKey := os.Getenv("AZURE_TTS_KEY")
if azureTtsKey != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="azure_tts").property.azure_subscription_key`, azureTtsKey)
}
azureTtsRegion := os.Getenv("AZURE_TTS_REGION")
if azureTtsRegion != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="azure_tts").property.azure_subscription_region`, azureTtsRegion)
}
awsRegion := os.Getenv("AWS_REGION")
if awsRegion != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="bedrock_llm").property.region`, awsRegion)
}
awsAccessKey := os.Getenv("AWS_ACCESS_KEY_ID")
if awsAccessKey != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="bedrock_llm").property.access_key`, awsAccessKey)
}
awsSecretKey := os.Getenv("AWS_SECRET_ACCESS_KEY")
if awsSecretKey != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="bedrock_llm").property.secret_key`, awsSecretKey)
}
bedrockModel := os.Getenv("AWS_BEDROCK_MODEL")
if bedrockModel != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="bedrock_llm").property.model`, bedrockModel)
}
elevenlabsTtsKey := os.Getenv("ELEVENLABS_TTS_KEY")
if elevenlabsTtsKey != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="elevenlabs_tts").property.api_key`, elevenlabsTtsKey)
}
cosyTtsKey := os.Getenv("COSY_TTS_KEY")
if cosyTtsKey != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="cosy_tts").property.api_key`, cosyTtsKey)
}
qwenApiKey := os.Getenv("QWEN_API_KEY")
if qwenApiKey != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="qwen_llm").property.api_key`, qwenApiKey)
}
err = os.WriteFile(manifestJsonFile, []byte(manifestJson), 0644)
return
}