Skip to content

Commit

Permalink
✨ (env.example): Update model names in .env.example file to match the…
Browse files Browse the repository at this point in the history
… new model versions
  • Loading branch information
romantech committed Apr 6, 2024
1 parent cb7ba0f commit 7033c9e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ REDIS_PORT=
REDIS_USERNAME=
REDIS_PASSWORD=

MODEL_GPT_3_5_FT=
MODEL_GPT_3_5=
MODEL_GPT_4=
MODEL_GPT_3_5_FT=gpt-3.5-turbo
MODEL_GPT_3_5=gpt-3.5-turbo
MODEL_GPT_4=gpt-4

30 changes: 16 additions & 14 deletions src/config/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* */
import { env } from 'node:process';

export enum EnvVars {
export enum RequiredEnv { // Required Environment Variables
PORT = 'PORT',
NODE_ENV = 'NODE_ENV',
CORS_ORIGIN = 'CORS_ORIGIN',

OPENAI_API_KEY = 'OPENAI_API_KEY',
}

export enum OptionalEnv { // Optional Environment Variables
CORS_ORIGIN = 'CORS_ORIGIN',

REDIS_HOST = 'REDIS_HOST',
REDIS_PORT = 'REDIS_PORT',
Expand All @@ -23,24 +25,24 @@ export enum EnvVars {
}

const loadEnvironment = () => {
const isProd = env[EnvVars.NODE_ENV] === 'production';
const isProd = env[RequiredEnv.NODE_ENV] === 'production';
const DEFAULT_SERVER_PORT = 3001;

return {
isProd,
port: isProd ? env[EnvVars.PORT] : DEFAULT_SERVER_PORT,
corsOrigins: env[EnvVars.CORS_ORIGIN]?.split(','),
openAIKey: env[EnvVars.OPENAI_API_KEY],
port: isProd ? Number(env[RequiredEnv.PORT]) : DEFAULT_SERVER_PORT,
corsOrigins: env[OptionalEnv.CORS_ORIGIN]?.split(',') ?? [],
openAIKey: env[RequiredEnv.OPENAI_API_KEY],
redis: {
host: env[EnvVars.REDIS_HOST],
port: Number(env[EnvVars.REDIS_PORT]),
password: env[EnvVars.REDIS_PASSWORD],
username: env[EnvVars.REDIS_USERNAME],
host: env[OptionalEnv.REDIS_HOST],
port: Number(env[OptionalEnv.REDIS_PORT]),
password: env[OptionalEnv.REDIS_PASSWORD],
username: env[OptionalEnv.REDIS_USERNAME],
},
modelNames: {
gpt_3_5_FT: env[EnvVars.MODEL_GPT_3_5_FT],
gpt_3_5: env[EnvVars.MODEL_GPT_3_5],
gpt_4: env[EnvVars.MODEL_GPT_4],
gpt_3_5_FT: env[OptionalEnv.MODEL_GPT_3_5_FT] ?? 'gpt-3.5-turbo',
gpt_3_5: env[OptionalEnv.MODEL_GPT_3_5] ?? 'gpt-3.5-turbo',
gpt_4: env[OptionalEnv.MODEL_GPT_4] ?? 'gpt-4',
},
} as const;
};
Expand Down
16 changes: 9 additions & 7 deletions src/utils/envChecker.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { env, exit } from 'node:process';
import { EnvVars, logger } from '@/config';
import { logger, RequiredEnv } from '@/config';

export const checkEnvVariables = () => {
Object.values(EnvVars).forEach((variable) => {
if (!env[variable]) {
logger.error(`Environment variable ${variable} is missing!`);
exit(1); // 프로세스 종료
}
});
const missingVars = Object.values(RequiredEnv)
.filter((variable) => !env[variable])
.join(', ');

if (missingVars) {
logger.error(`Environment variable(s) ${missingVars} are missing!`);
exit(1); // 프로세스 종료
}
};

0 comments on commit 7033c9e

Please sign in to comment.