File tree Expand file tree Collapse file tree 8 files changed +50
-52
lines changed
Expand file tree Collapse file tree 8 files changed +50
-52
lines changed Original file line number Diff line number Diff line change 1- // Set which model you want to use
2- ENABLED_MODEL="HUGGINGFACEHUB "
1+ // Set which model provider you want to use, HUGGING_FACE or OPEN_AI
2+ ENABLED_MODEL_STORE="HUGGING_FACE "
33
44// Hugging Face API Key
55HUGGINGFACEHUB_API_KEY=""
Original file line number Diff line number Diff line change 88 "start" : " vite" ,
99 "preview" : " vite preview" ,
1010 "build" : " vite build" ,
11- "start-server" : " node ./server/index.js"
11+ "start-server" : " nodemon ./server/index.js"
1212 },
1313 "dependencies" : {
1414 "@emotion/react" : " ^11.11.0" ,
1515 "@emotion/styled" : " ^11.11.0" ,
16+ "@huggingface/inference" : " ^2.5.0" ,
1617 "@koa/cors" : " ^4.0.0" ,
1718 "@koa/router" : " ^12.0.0" ,
1819 "@mui/icons-material" : " ^5.11.16" ,
Original file line number Diff line number Diff line change 1+ import { HuggingFaceService } from '../services/hf.js'
2+ import { OpenAiService } from '../services/openai.js'
3+
4+ export const MODEL_STORES = {
5+ 'HUGGING_FACE' : HuggingFaceService ,
6+ 'OPEN_AI' : OpenAiService ,
7+ } ;
8+
9+ export const { ENABLED_MODEL_STORE } = process . env ;
10+ export const DEFAULT_ENABLED_MODEL_STORE = 'HUGGING_FACE' ;
11+
12+ export const enabledModel = ENABLED_MODEL_STORE || DEFAULT_ENABLED_MODEL_STORE ;
Original file line number Diff line number Diff line change 1- import { HuggingFaceService } from '../services/model_hf.js' ;
2- import { OpenAiService } from '../services/model_openai.js' ;
3-
4- const { ENABLED_MODEL } = process . env ;
1+ import { MODEL_STORES , enabledModel } from '../config/model_store_constants.js' ;
52
63class ChatService {
74 constructor ( ) {
8- }
9-
10- async selectModelService ( ) {
11- let model ;
12- switch ( ENABLED_MODEL ) {
13- case 'HUGGINGFACEHUB' :
14- const huggingFaceService = new HuggingFaceService ( ) ;
15- model = huggingFaceService ;
16- break ;
17- case 'OPENAI' :
18- const openAiService = new OpenAiService ( ) ;
19- model = openAiService ;
20- break ;
21- default :
22- break ;
23- }
24- return model ;
5+ this . model = new MODEL_STORES [ enabledModel ]
256 }
267
278 async startChat ( data ) {
289 const { body : { userInput } } = data ;
29- const model = this . selectModelService ( ) ;
30- console . log ( 'model ' , model . OpenAiService ) ;
10+ const model = this . model ;
3111 const response = await model . call ( userInput ) ;
3212
3313 return response ;
Original file line number Diff line number Diff line change 1+ import { HfInference } from "@huggingface/inference" ;
2+
3+ const { HUGGINGFACEHUB_API_KEY } = process . env ;
4+
5+ class HuggingFaceService {
6+ constructor ( ) {
7+ this . modelName = 'microsoft/DialoGPT-large' ;
8+ this . model = new HfInference ( HUGGINGFACEHUB_API_KEY ) ;
9+ }
10+
11+ async call ( userInput ) {
12+ // TO DO: pass in past_user_inputs for context
13+ const response = await this . model . conversational ( {
14+ model : this . modelName ,
15+ temperature : 0 ,
16+ inputs : {
17+ text : userInput ,
18+ }
19+ } ) ;
20+
21+ return { response : response && response . generated_text } ;
22+ }
23+ }
24+
25+ export { HuggingFaceService }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ class OpenAiService {
3131 const response = await chain . call ( {
3232 input : userInput ,
3333 } ) ;
34+ console . log ( 'response ' , response ) ;
3435 return response ;
3536 }
3637}
Original file line number Diff line number Diff line change 520520 resolved "https://registry.yarnpkg.com/@fortaine/fetch-event-source/-/fetch-event-source-3.0.6.tgz#b8552a2ca2c5202f5699b93a92be0188d422b06e"
521521 integrity sha512-621GAuLMvKtyZQ3IA6nlDWhV1V/7PGOTNIGLUifxt0KzM+dZIweJ6F3XvQF3QnqeNfS1N7WQ0Kil1Di/lhChEw==
522522
523+ " @huggingface/inference@^2.5.0 " :
524+ version "2.5.0"
525+ resolved "https://registry.yarnpkg.com/@huggingface/inference/-/inference-2.5.0.tgz#8e14ee6696e91aecb132c90d3b07be8373e70338"
526+ integrity sha512-X3NSdrWAKNTLAsEKabH48Wc+Osys+S7ilRcH1bf9trSDmJlzPVXDseXMRBHCFPCYd5AAAIakhENO4zCqstVg8g==
527+
523528" @jridgewell/gen-mapping@^0.3.0" , "@jridgewell/gen-mapping@^0.3.2":
524529 version "0.3.3"
525530 resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz#7e02e6eb5df901aaedb08514203b096614024098"
You can’t perform that action at this time.
0 commit comments