-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from romantech/faeture/langchain-update
- Loading branch information
Showing
15 changed files
with
758 additions
and
819 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
# Deployment Environment Ports | ||
PORT=3001 | ||
NODE_ENV=development # koyeb 환경 변수 설정이랑 맞추기 위해 추가 | ||
# Added to match koyeb environment variable settings | ||
NODE_ENV=development | ||
# Specify which origins to allow, separated by commas, e.g. https://google.com,http://localhost:3000 | ||
CORS_ORIGIN= | ||
|
||
OPENAI_API_KEY= | ||
|
||
REDIS_HOST= | ||
REDIS_PORT= | ||
REDIS_USERNAME= | ||
REDIS_PASSWORD= | ||
CORS_ORIGIN= | ||
FINE_TUNED_ID= | ||
|
||
MODEL_GPT_3_5_FT=gpt-3.5-turbo | ||
MODEL_GPT_3_5=gpt-3.5-turbo | ||
MODEL_GPT_4=gpt-4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"name": "project-server", | ||
"version": "1.0.0", | ||
"description": "Personal project server that provides a RESTful API", | ||
"packageManager": "[email protected]", | ||
"main": "server.ts", | ||
"_moduleAliases": { | ||
"@": "dist" | ||
|
@@ -20,6 +21,7 @@ | |
"author": "Romantech", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@langchain/openai": "^0.0.26", | ||
"@types/request-ip": "^0.0.41", | ||
"compression": "^1.7.4", | ||
"cookie-parser": "^1.4.6", | ||
|
@@ -28,14 +30,14 @@ | |
"express-validator": "^7.0.1", | ||
"helmet": "^7.1.0", | ||
"ioredis": "^5.3.2", | ||
"langchain": "^0.0.209", | ||
"langchain": "^0.1.31", | ||
"module-alias": "^2.2.3", | ||
"morgan": "^1.10.0", | ||
"node-schedule": "^2.1.1", | ||
"openai": "^4.23.0", | ||
"openai": "^4.33.0", | ||
"request-ip": "^3.3.0", | ||
"winston": "^3.11.0", | ||
"winston-daily-rotate-file": "^4.7.1" | ||
"winston-daily-rotate-file": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/compression": "^1.7.5", | ||
|
@@ -45,10 +47,10 @@ | |
"@types/express-serve-static-core": "^4.17.41", | ||
"@types/module-alias": "^2.0.4", | ||
"@types/morgan": "^1.9.9", | ||
"@types/node": "^20.10.5", | ||
"@types/node": "^20.12.5", | ||
"@types/node-schedule": "^2.1.5", | ||
"@typescript-eslint/eslint-plugin": "^6.15.0", | ||
"@typescript-eslint/parser": "^6.15.0", | ||
"@typescript-eslint/eslint-plugin": "^7.5.0", | ||
"@typescript-eslint/parser": "^7.5.0", | ||
"dotenv": "^16.3.1", | ||
"eslint": "^8.56.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,50 @@ | ||
/** | ||
* 웹스톰에서 alias 설정을 위해 tsconfig.json 파일의 baseUrl 속성을 설정하면 | ||
* process.env 참조시 해결되지 않은 변수로 나오는 문제 있음 | ||
* import { env } from 'node:process' 구문으로 임포트해서 사용해서 임시 해결 | ||
* */ | ||
import { env } from 'node:process'; | ||
|
||
export enum EnvVars { | ||
export enum RequiredEnv { // Required Environment Variables | ||
PORT = 'PORT', | ||
NODE_ENV = 'NODE_ENV', | ||
OPENAI_API_KEY = 'OPENAI_API_KEY', | ||
} | ||
|
||
export enum OptionalEnv { // Optional Environment Variables | ||
CORS_ORIGIN = 'CORS_ORIGIN', | ||
|
||
REDIS_HOST = 'REDIS_HOST', | ||
REDIS_PORT = 'REDIS_PORT', | ||
REDIS_PASSWORD = 'REDIS_PASSWORD', | ||
REDIS_USERNAME = 'REDIS_USERNAME', | ||
CORS_ORIGIN = 'CORS_ORIGIN', | ||
FINE_TUNED_ID = 'FINE_TUNED_ID', | ||
|
||
MODEL_GPT_3_5_FT = 'MODEL_GPT_3_5_FT', | ||
MODEL_GPT_3_5 = 'MODEL_GPT_3_5', | ||
MODEL_GPT_4 = 'MODEL_GPT_4', | ||
} | ||
|
||
/** | ||
* 웹스톰에서 alias 설정을 위해 tsconfig.json 파일의 baseUrl 속성을 설정하면 | ||
* process.env 참조시 해결되지 않은 변수로 나오는 문제 있음 | ||
* import { env } from 'node:process' 구문으로 임포트해서 사용해서 임시 해결 | ||
* */ | ||
export const isProd = () => env[EnvVars.NODE_ENV] === 'production'; | ||
export const PORT = isProd() ? env[EnvVars.PORT] : 3001; | ||
export const REDIS_HOST = env[EnvVars.REDIS_HOST]; | ||
export const REDIS_PORT = Number(env[EnvVars.REDIS_PORT]); | ||
export const REDIS_PASSWORD = env[EnvVars.REDIS_PASSWORD]; | ||
export const REDIS_USERNAME = env[EnvVars.REDIS_USERNAME]; | ||
export const OPENAI_API_KEY = env[EnvVars.OPENAI_API_KEY]; | ||
export const CORS_ORIGIN = env[EnvVars.CORS_ORIGIN]?.split(',') ?? []; | ||
export const FINE_TUNED_ID = env[EnvVars.FINE_TUNED_ID]; | ||
const loadEnvironment = () => { | ||
const isProd = env[RequiredEnv.NODE_ENV] === 'production'; | ||
const DEFAULT_SERVER_PORT = 3001; | ||
|
||
return { | ||
isProd, | ||
port: isProd ? Number(env[RequiredEnv.PORT]) : DEFAULT_SERVER_PORT, | ||
corsOrigins: env[OptionalEnv.CORS_ORIGIN]?.split(',') ?? [], | ||
openAIKey: env[RequiredEnv.OPENAI_API_KEY], | ||
redis: { | ||
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[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; | ||
}; | ||
|
||
export const envConfig = loadEnvironment(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,34 @@ | ||
import { FINE_TUNED_ID } from '@/config'; | ||
import { envConfig } from '@/config'; | ||
import { ANALYZER_REDIS_SCHEMA } from '@/services/redis'; | ||
|
||
const { FIELDS } = ANALYZER_REDIS_SCHEMA; | ||
|
||
const FINE_TUNE_SUFFIX = '_fine_tuned'; | ||
|
||
export enum GPTModel { | ||
GPT_3 = 'gpt-3.5-turbo', | ||
export enum AIModelKey { | ||
GPT_3_5 = 'gpt-3.5', | ||
GPT_3_5_FT = 'gpt-3.5-ft', | ||
GPT_4 = 'gpt-4', | ||
} | ||
|
||
export const GPT_MODEL_LIST = Object.values(GPTModel); | ||
export const AI_MODEL = { | ||
[AIModelKey.GPT_3_5]: envConfig.modelNames.gpt_3_5, | ||
[AIModelKey.GPT_3_5_FT]: envConfig.modelNames.gpt_3_5_FT, | ||
[AIModelKey.GPT_4]: envConfig.modelNames.gpt_4, | ||
}; | ||
|
||
export const ANALYSIS_MODEL_OPTIONS = { | ||
[GPTModel.GPT_3]: { | ||
export const ANALYSIS_MODEL_OPTION = { | ||
[AIModelKey.GPT_3_5_FT]: { | ||
promptField: FIELDS.ANALYSIS + FINE_TUNE_SUFFIX, | ||
temperature: 0.6, | ||
modelName: FINE_TUNED_ID ?? GPTModel.GPT_3, | ||
modelName: AI_MODEL[AIModelKey.GPT_3_5_FT], | ||
}, | ||
[GPTModel.GPT_4]: { | ||
[AIModelKey.GPT_4]: { | ||
promptField: FIELDS.ANALYSIS, | ||
temperature: 0.4, | ||
modelName: GPTModel.GPT_4, | ||
modelName: AI_MODEL[AIModelKey.GPT_4], | ||
}, | ||
} as const; | ||
}; | ||
|
||
export const ANALYSIS_MODEL = Object.keys(ANALYSIS_MODEL_OPTION); | ||
export type AnalysisModel = keyof typeof ANALYSIS_MODEL_OPTION; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.