File tree Expand file tree Collapse file tree 9 files changed +83
-29
lines changed Expand file tree Collapse file tree 9 files changed +83
-29
lines changed Original file line number Diff line number Diff line change 1+ PORT=3000
2+ IS_DOCKER=false
3+
14LANGCHAIN_API_KEY=
25LANGCHAIN_TRACING_V2=true
36LANGCHAIN_CALLBACKS_BACKGROUND=true
47
5- GOOGLE_GENAI_API_KEY =
8+ LLM_API_KEY =
69
7- REDIS_ENDPOINT_URI=redis://127.0.0.1:6379
10+ REDIS_URL=redis://127.0.0.1:6379
11+ REDIS_URL_DOCKER=redis://redis:6379
12+ REDIS_USER=
813REDIS_PASSWORD=
914
10- DATABASE_URL="postgres://postgres:devPassword@localhost:5432/app_db?schema=public"
15+ DATABASE_URL=postgresql://genaiapp:password@localhost:5432/app_db?schema=public
16+ DATABASE_URL_DOCKER=postgresql://genaiapp:password@postgres:5432/app_db?schema=public
17+
18+ JWT_SECRET=
19+ JWT_EXPIRATION=1h
Original file line number Diff line number Diff line change 44 " dataproviders" ,
55 " gemini" ,
66 " nodenext" ,
7+ " predev" ,
8+ " prestart" ,
79 " usecases"
810 ]
911}
Original file line number Diff line number Diff line change @@ -8,30 +8,37 @@ services:
88 - ' 3000:3000'
99 env_file :
1010 - .env
11+ environment :
12+ IS_DOCKER : true
13+ DATABASE_URL : ${DATABASE_URL_DOCKER}
14+ REDIS_URL : ${REDIS_URL_DOCKER}
1115 volumes :
1216 - ./src:/usr/workspace/app/src
1317 - pnpm_store:/pnpm/.pnpm-store
14- command : sh -c "pnpm install && npx prisma generate && pnpm dev"
18+ command : sh -c "pnpm install && node dynamic-url-config.js && npx prisma generate && pnpm dev"
19+ depends_on :
20+ - postgres
21+ - redis
1522
1623 postgres :
1724 container_name : genai_app_postgres
1825 image : bitnami/postgresql:latest
26+ environment :
27+ POSTGRES_USER : genaiapp
28+ POSTGRES_PASSWORD : password
29+ POSTGRES_DB : genaiapp_db
1930 ports :
2031 - ' 5432:5432'
21- environment :
22- - POSTGRES_USER=genaiapp
23- - POSTGRES_PASSWORD=password
24- - POSTGRES_DB=genaiapp_db
2532 volumes :
2633 - ' genai_app_postgres_data:/bitnami/postgresql'
2734
2835 redis :
2936 container_name : genai_app_redis
3037 image : bitnami/redis:latest
38+ environment :
39+ ALLOW_EMPTY_PASSWORD : yes
3140 ports :
3241 - ' 6379:6379'
33- environment :
34- - ALLOW_EMPTY_PASSWORD=yes
3542 volumes :
3643 - ' genai_app_redis_data:/bitnami/redis/data'
3744
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ RUN mkdir -p $PNPM_HOME
99
1010RUN pnpm config set store-dir "$PNPM_HOME/.pnpm-store" --global
1111
12- COPY package.json pnpm-lock.yaml* ./
12+ COPY package.json pnpm-lock.yaml* dynamic-url-config.js ./
1313RUN pnpm install --frozen-lockfile
1414COPY . .
1515
Original file line number Diff line number Diff line change 1+ const fs = require ( 'fs' )
2+ const dotenv = require ( 'dotenv' )
3+
4+ if ( fs . existsSync ( '.env' ) ) {
5+ dotenv . config ( )
6+ }
7+
8+ const isDocker = process . env . IS_DOCKER === 'true'
9+
10+ const databaseUrl = isDocker
11+ ? process . env . DATABASE_URL_DOCKER
12+ : process . env . DATABASE_URL
13+
14+ const redisUrl = isDocker ? process . env . REDIS_URL_DOCKER : process . env . REDIS_URL
15+
16+ if ( databaseUrl ) {
17+ process . env . DATABASE_URL = databaseUrl
18+ console . log ( `Using DATABASE_URL: ${ databaseUrl } ` )
19+ } else {
20+ console . error (
21+ 'DATABASE_URL is not set. Please check your environment variables.' ,
22+ )
23+
24+ process . exit ( 1 )
25+ }
26+
27+ if ( redisUrl ) {
28+ process . env . REDIS_URL = redisUrl
29+ console . log ( `Using REDIS_URL: ${ redisUrl } ` )
30+ } else {
31+ console . error (
32+ 'REDIS_URL is not set. Please check your environment variables.' ,
33+ )
34+
35+ process . exit ( 1 )
36+ }
Original file line number Diff line number Diff line change 33 "version" : " 1.0.0" ,
44 "description" : " This is an Express service that provides authorization functionality and includes gen-AI features." ,
55 "scripts" : {
6+ "prestart" : " node dynamic-url-config.js" ,
7+ "predev" : " node dynamic-url-config.js" ,
68 "start" : " tsx src/app.ts" ,
79 "dev" : " tsx watch src/app.ts"
810 },
2224 "@langchain/redis" : " ^0.1.0" ,
2325 "@prisma/client" : " 5.20.0" ,
2426 "@types/redis" : " ^4.0.11" ,
25- "dotenv" : " ^16.4.5" ,
2627 "express" : " ^4.21.0" ,
2728 "jsonwebtoken" : " ^9.0.2" ,
2829 "langchain" : " ^0.3.2" ,
3738 "@types/multer" : " ^1.4.12" ,
3839 "@types/node" : " ^22.5.5" ,
3940 "cors" : " ^2.8.5" ,
41+ "dotenv" : " ^16.4.5" ,
4042 "nodemon" : " ^3.1.4" ,
4143 "prisma" : " ^5.20.0" ,
4244 "ts-node" : " ^10.9.2" ,
4547 "typescript" : " ^5.6.2"
4648 },
4749 "packageManager" :
" [email protected] +sha512.0a203ffaed5a3f63242cd064c8fb5892366c103e328079318f78062f24ea8c9d50bc6a47aa3567cabefd824d170e78fa2745ed1f16b132e16436146b7688f19b" 48- }
50+ }
Original file line number Diff line number Diff line change @@ -9,14 +9,14 @@ export class LLMService {
99 get llm ( ) {
1010 return new ChatGoogleGenerativeAI ( {
1111 model : 'gemini-1.5-flash' ,
12- apiKey : process . env [ 'GOOGLE_GENAI_API_KEY ' ] ,
12+ apiKey : process . env [ 'LLM_API_KEY ' ] ,
1313 } )
1414 }
1515
1616 get textEmbedding ( ) {
1717 return new GoogleGenerativeAIEmbeddings ( {
1818 model : 'text-embedding-004' ,
19- apiKey : process . env [ 'GOOGLE_GENAI_API_KEY ' ] ,
19+ apiKey : process . env [ 'LLM_API_KEY ' ] ,
2020 } )
2121 }
2222}
Original file line number Diff line number Diff line change 1- import { UseCase } from '@/common/types'
21import { StringOutputParser } from '@langchain/core/output_parsers'
32import { ChatPromptTemplate } from '@langchain/core/prompts'
4- import { ChatGoogleGenerativeAI } from '@langchain/google-genai'
3+
4+ import { UseCase } from '@/common/types'
5+ import { LLMService } from '@/modules/genai/adapters'
56
67type Params = {
78 text : string
89 language : string
910}
1011
1112export class TranslateTextUseCase implements UseCase < string , Params > {
13+ constructor ( private _llmService : LLMService ) { }
14+
1215 async invoke ( params : { text : string ; language : string } ) : Promise < string > {
1316 const { text, language } = params
1417
15- /// TODO: create a service to implement common LLM components
16- const API_KEY = process . env [ 'GOOGLE_GENAI_API_KEY' ]
17- const aiModel = new ChatGoogleGenerativeAI ( {
18- model : 'gemini-1.5-flash' ,
19- temperature : 0 ,
20- apiKey : API_KEY ,
21- } )
22-
2318 const systemTemplate = 'Translate the following text into {language}:'
2419 const promptTemplate = ChatPromptTemplate . fromMessages ( [
2520 [ 'system' , systemTemplate ] ,
2621 [ 'user' , '{text}' ] ,
2722 ] )
2823
29- const chain = promptTemplate . pipe ( aiModel ) . pipe ( new StringOutputParser ( ) )
24+ const chain = promptTemplate
25+ . pipe ( this . _llmService . llm )
26+ . pipe ( new StringOutputParser ( ) )
27+
3028 return await chain . invoke ( {
3129 language : language ,
3230 text : text ,
You can’t perform that action at this time.
0 commit comments