@@ -9,7 +9,7 @@ export const whatsappBotHandler = async (
9
9
bot_id : string ,
10
10
hash : string ,
11
11
from : string ,
12
- message : string ,
12
+ message : string
13
13
) => {
14
14
try {
15
15
await prisma . $connect ( ) ;
@@ -45,9 +45,11 @@ export const whatsappBotHandler = async (
45
45
chat_history . splice ( 0 , chat_history . length - 10 ) ;
46
46
}
47
47
48
- let history = chat_history . map ( ( chat ) => {
49
- return `Human: ${ chat . human } \nAssistant: ${ chat . bot } ` ;
50
- } ) . join ( "\n" ) ;
48
+ let history = chat_history
49
+ . map ( ( chat ) => {
50
+ return `Human: ${ chat . human } \nAssistant: ${ chat . bot } ` ;
51
+ } )
52
+ . join ( "\n" ) ;
51
53
52
54
const temperature = bot . temperature ;
53
55
@@ -59,7 +61,7 @@ export const whatsappBotHandler = async (
59
61
{
60
62
botId : bot . id ,
61
63
sourceId : null ,
62
- } ,
64
+ }
63
65
) ;
64
66
65
67
const modelinfo = await prisma . dialoqbaseModels . findFirst ( {
@@ -74,16 +76,18 @@ export const whatsappBotHandler = async (
74
76
return "Unable to find model" ;
75
77
}
76
78
77
- const botConfig = ( modelinfo . config as { } ) || { } ;
79
+ const botConfig : any = ( modelinfo . config as { } ) || { } ;
80
+ if ( bot . provider . toLowerCase ( ) === "openai" ) {
81
+ if ( bot . bot_model_api_key && bot . bot_model_api_key . trim ( ) !== "" ) {
82
+ botConfig . configuration = {
83
+ apiKey : bot . bot_model_api_key ,
84
+ } ;
85
+ }
86
+ }
78
87
79
- const model = chatModelProvider (
80
- bot . provider ,
81
- bot . model ,
82
- temperature ,
83
- {
84
- ...botConfig ,
85
- } ,
86
- ) ;
88
+ const model = chatModelProvider ( bot . provider , bot . model , temperature , {
89
+ ...botConfig ,
90
+ } ) ;
87
91
88
92
const chain = ConversationalRetrievalQAChain . fromLLM (
89
93
model ,
@@ -92,7 +96,7 @@ export const whatsappBotHandler = async (
92
96
qaTemplate : bot . qaPrompt ,
93
97
questionGeneratorTemplate : bot . questionGeneratorPrompt ,
94
98
returnSourceDocuments : true ,
95
- } ,
99
+ }
96
100
) ;
97
101
98
102
const response = await chain . call ( {
@@ -121,12 +125,8 @@ export const whatsappBotHandler = async (
121
125
}
122
126
} ;
123
127
124
- export const clearHistoryWhatsapp = async (
125
- bot_id : string ,
126
- from : string ,
127
- ) => {
128
+ export const clearHistoryWhatsapp = async ( bot_id : string , from : string ) => {
128
129
try {
129
-
130
130
await prisma . $connect ( ) ;
131
131
132
132
const bot = await prisma . bot . findFirst ( {
0 commit comments