forked from TEN-framework/ten-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
108 lines (87 loc) · 4.1 KB
/
Copy pathmain.go
File metadata and controls
108 lines (87 loc) · 4.1 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
package main
import (
"flag"
"log/slog"
"os"
"strconv"
"github.com/tidwall/sjson"
"app/internal"
)
func main() {
httpServerConfig := &internal.HttpServerConfig{}
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.ManifestJsonFile, "manifestJsonFile", os.Getenv("MANIFEST_JSON_FILE"), "manifest json file")
flag.IntVar(&httpServerConfig.WorkersMax, "workersMax", workersMax, "workers max")
flag.IntVar(&httpServerConfig.WorkerQuitTimeoutSeconds, "workerQuitTimeoutSeconds", workerQuitTimeoutSeconds, "worker quit timeout seconds")
flag.StringVar(&httpServerConfig.Port, "port", ":8080", "http server port")
flag.Parse()
slog.Info("server config", "appId", httpServerConfig.AppId, "manifestJsonFile", httpServerConfig.ManifestJsonFile,
"workersMax", httpServerConfig.WorkersMax, "workerQuitTimeoutSeconds", httpServerConfig.WorkerQuitTimeoutSeconds)
processManifest(httpServerConfig.ManifestJsonFile)
httpServer := internal.NewHttpServer(httpServerConfig)
httpServer.Start()
}
func processManifest(manifestJsonFile string) {
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")
slog.Info("processManifest", "AGORA_APP_ID", appId)
if appId != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="agora_rtc").property.app_id`, appId)
}
azureSttKey := os.Getenv("AZURE_STT_KEY")
slog.Info("processManifest", "AZURE_STT_KEY", azureSttKey)
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")
slog.Info("processManifest", "AZURE_STT_REGION", azureSttRegion)
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")
slog.Info("processManifest", "OPENAI_BASE_URL", openaiBaseUrl)
if openaiBaseUrl != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="openai_chatgpt").property.base_url`, openaiBaseUrl)
}
openaiApiKey := os.Getenv("OPENAI_API_KEY")
slog.Info("processManifest", "OPENAI_API_KEY", openaiApiKey)
if openaiApiKey != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="openai_chatgpt").property.api_key`, openaiApiKey)
}
openaiModel := os.Getenv("OPENAI_MODEL")
slog.Info("processManifest", "OPENAI_MODEL", openaiModel)
if openaiModel != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="openai_chatgpt").property.model`, openaiModel)
}
proxyUrl := os.Getenv("PROXY_URL")
slog.Info("processManifest", "PROXY_URL", proxyUrl)
if proxyUrl != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="openai_chatgpt").property.proxy_url`, proxyUrl)
}
azureTtsKey := os.Getenv("AZURE_TTS_KEY")
slog.Info("processManifest", "AZURE_TTS_KEY", azureTtsKey)
if azureTtsKey != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="azure_tts").property.azure_subscription_key`, azureTtsKey)
}
azure_tts_region := os.Getenv("AZURE_TTS_REGION")
slog.Info("processManifest", "AZURE_TTS_REGION", azure_tts_region)
if azure_tts_region != "" {
manifestJson, _ = sjson.Set(manifestJson, `predefined_graphs.0.nodes.#(name=="azure_tts").property.azure_subscription_region`, azure_tts_region)
}
os.WriteFile(manifestJsonFile, []byte(manifestJson), 0644)
return
}