-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.ts
190 lines (161 loc) · 6.41 KB
/
config.ts
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import process from "process";
import { TranscriptionMode } from "./types/transcription-mode";
import { TTSMode } from "./types/tts-mode";
import { AWSPollyEngine } from "./types/aws-polly-engine";
// Environment variables
import dotenv from "dotenv";
dotenv.config();
// Config Interface
interface IConfig {
// Access control
whitelistedPhoneNumbers: string[];
whitelistedEnabled: boolean;
// OpenAI
openAIModel: string;
openAIAPIKeys: string[];
maxModelTokens: number;
prePrompt: string | undefined;
// Prefix
prefixEnabled: boolean;
prefixSkippedForMe: boolean;
gptPrefix: string;
dallePrefix: string;
stableDiffusionPrefix: string;
langChainPrefix: string;
resetPrefix: string;
aiConfigPrefix: string;
// Groupchats
groupchatsEnabled: boolean;
// Prompt Moderation
promptModerationEnabled: boolean;
promptModerationBlacklistedCategories: string[];
// AWS
awsAccessKeyId: string;
awsSecretAccessKey: string;
awsRegion: string;
awsPollyVoiceId: string;
awsPollyEngine: AWSPollyEngine;
// Voice transcription & Text-to-Speech
speechServerUrl: string;
whisperServerUrl: string;
openAIServerUrl: string;
whisperApiKey: string;
ttsEnabled: boolean;
ttsMode: TTSMode;
ttsTranscriptionResponse: boolean;
transcriptionEnabled: boolean;
transcriptionMode: TranscriptionMode;
transcriptionLanguage: string;
}
// Config
export const config: IConfig = {
whitelistedPhoneNumbers: process.env.WHITELISTED_PHONE_NUMBERS?.split(",") || [],
whitelistedEnabled: getEnvBooleanWithDefault("WHITELISTED_ENABLED", false),
openAIAPIKeys: (process.env.OPENAI_API_KEYS || process.env.OPENAI_API_KEY || "").split(",").filter((key) => !!key), // Default: []
openAIModel: process.env.OPENAI_GPT_MODEL || "gpt-3.5-turbo", // Default: gpt-3.5-turbo
maxModelTokens: getEnvMaxModelTokens(), // Default: 4096
prePrompt: process.env.PRE_PROMPT, // Default: undefined
// Prefix
prefixEnabled: getEnvBooleanWithDefault("PREFIX_ENABLED", true), // Default: true
prefixSkippedForMe: getEnvBooleanWithDefault("PREFIX_SKIPPED_FOR_ME", true), // Default: true
gptPrefix: process.env.GPT_PREFIX || "!gpt", // Default: !gpt
dallePrefix: process.env.DALLE_PREFIX || "!dalle", // Default: !dalle
stableDiffusionPrefix: process.env.STABLE_DIFFUSION_PREFIX || "!sd", // Default: !sd
resetPrefix: process.env.RESET_PREFIX || "!reset", // Default: !reset
aiConfigPrefix: process.env.AI_CONFIG_PREFIX || "!config", // Default: !config
langChainPrefix: process.env.LANGCHAIN_PREFIX || "!lang", // Default: !lang
// Groupchats
groupchatsEnabled: getEnvBooleanWithDefault("GROUPCHATS_ENABLED", false), // Default: false
// Prompt Moderation
promptModerationEnabled: getEnvBooleanWithDefault("PROMPT_MODERATION_ENABLED", false), // Default: false
promptModerationBlacklistedCategories: getEnvPromptModerationBlacklistedCategories(), // Default: ["hate", "hate/threatening", "self-harm", "sexual", "sexual/minors", "violence", "violence/graphic"]
// AWS
awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID || "", // Default: ""
awsSecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || "", // Default: ""
awsRegion: process.env.AWS_REGION || "", // Default: ""
awsPollyVoiceId: process.env.AWS_POLLY_VOICE_ID || "", // Default: "Joanna"
awsPollyEngine: getEnvAWSPollyVoiceEngine(), // Default: standard
// Speech API, Default: https://speech-service.verlekar.com
speechServerUrl: process.env.SPEECH_API_URL || "https://speech-service.verlekar.com",
whisperServerUrl: process.env.WHISPER_API_URL || "https://transcribe.whisperapi.com",
openAIServerUrl: process.env.OPENAI_API_URL || "https://api.openai.com/v1/audio/transcriptions",
whisperApiKey: process.env.WHISPER_API_KEY || "", // Default: ""
// Text-to-Speech
ttsEnabled: getEnvBooleanWithDefault("TTS_ENABLED", false), // Default: false
ttsMode: getEnvTTSMode(), // Default: speech-api
ttsTranscriptionResponse: getEnvBooleanWithDefault("TTS_TRANSCRIPTION_RESPONSE_ENABLED", true), // Default: true
// Transcription
transcriptionEnabled: getEnvBooleanWithDefault("TRANSCRIPTION_ENABLED", false), // Default: false
transcriptionMode: getEnvTranscriptionMode(), // Default: local
transcriptionLanguage: process.env.TRANSCRIPTION_LANGUAGE || "" // Default: null
};
/**
* Get the max model tokens from the environment variable
* @returns The max model tokens from the environment variable or 4096
*/
function getEnvMaxModelTokens() {
const envValue = process.env.MAX_MODEL_TOKENS;
if (envValue == undefined || envValue == "") {
return 4096;
}
return parseInt(envValue);
}
/**
* Get an environment variable as a boolean with a default value
* @param key The environment variable key
* @param defaultValue The default value
* @returns The value of the environment variable or the default value
*/
function getEnvBooleanWithDefault(key: string, defaultValue: boolean): boolean {
const envValue = process.env[key]?.toLowerCase();
if (envValue == undefined || envValue == "") {
return defaultValue;
}
return envValue == "true";
}
/**
* Get the blacklist categories for prompt moderation from the environment variable
* @returns Blacklisted categories for prompt moderation
*/
function getEnvPromptModerationBlacklistedCategories(): string[] {
const envValue = process.env.PROMPT_MODERATION_BLACKLISTED_CATEGORIES;
if (envValue == undefined || envValue == "") {
return ["hate", "hate/threatening", "self-harm", "sexual", "sexual/minors", "violence", "violence/graphic"];
} else {
return JSON.parse(envValue.replace(/'/g, '"'));
}
}
/**
* Get the transcription mode from the environment variable
* @returns The transcription mode
*/
function getEnvTranscriptionMode(): TranscriptionMode {
const envValue = process.env.TRANSCRIPTION_MODE?.toLowerCase();
if (envValue == undefined || envValue == "") {
return TranscriptionMode.Local;
}
return envValue as TranscriptionMode;
}
/**
* Get the tss mode from the environment variable
* @returns The tts mode
*/
function getEnvTTSMode(): TTSMode {
const envValue = process.env.TTS_MODE?.toLowerCase();
if (envValue == undefined || envValue == "") {
return TTSMode.SpeechAPI;
}
return envValue as TTSMode;
}
/**
* Get the AWS Polly voice engine from the environment variable
* @returns The voice engine
*/
function getEnvAWSPollyVoiceEngine(): AWSPollyEngine {
const envValue = process.env.AWS_POLLY_VOICE_ENGINE?.toLowerCase();
if (envValue == undefined || envValue == "") {
return AWSPollyEngine.Standard;
}
return envValue as AWSPollyEngine;
}
export default config;