@@ -17,7 +17,8 @@ export const chatRequestHandler = async (
1717 reply : FastifyReply
1818) => {
1919 const { id : bot_id } = request . params ;
20- const { message, history, history_id } = request . body ;
20+ const { message, history_id } = request . body ;
21+ let history = [ ] ;
2122
2223 try {
2324 const prisma = request . server . prisma ;
@@ -33,6 +34,30 @@ export const chatRequestHandler = async (
3334 ) ;
3435 }
3536
37+
38+ if ( history_id ) {
39+ const details = await prisma . botPlayground . findFirst ( {
40+ where : {
41+ id : history_id ,
42+ botId : bot_id ,
43+ } ,
44+ include : {
45+ BotPlaygroundMessage : {
46+ orderBy : {
47+ createdAt : "asc" ,
48+ } ,
49+ } ,
50+ } ,
51+ } ) ;
52+
53+ const botMessages = details ?. BotPlaygroundMessage . map ( ( message ) => ( {
54+ type : message . type ,
55+ text : message . message ,
56+ } ) ) ;
57+
58+ history = botMessages || [ ] ;
59+ }
60+
3661 const embeddingInfo = await getModelInfo ( {
3762 model : bot . embedding ,
3863 prisma,
@@ -117,7 +142,8 @@ export const chatRequestStreamHandler = async (
117142 reply : FastifyReply
118143) => {
119144 const { id : bot_id } = request . params ;
120- const { message, history, history_id } = request . body ;
145+ const { message, history_id } = request . body ;
146+ let history = [ ] ;
121147
122148 try {
123149 const prisma = request . server . prisma ;
@@ -133,6 +159,32 @@ export const chatRequestStreamHandler = async (
133159 ) ;
134160 }
135161
162+
163+ if ( history_id ) {
164+ const details = await prisma . botPlayground . findFirst ( {
165+ where : {
166+ id : history_id ,
167+ botId : bot_id ,
168+ } ,
169+ include : {
170+ BotPlaygroundMessage : {
171+ orderBy : {
172+ createdAt : "asc" ,
173+ } ,
174+ } ,
175+ } ,
176+ } ) ;
177+
178+ const botMessages = details ?. BotPlaygroundMessage . map ( ( message ) => ( {
179+ type : message . type ,
180+ text : message . message ,
181+ } ) ) ;
182+
183+ history = botMessages || [ ] ;
184+ }
185+
186+
187+
136188 const embeddingInfo = await getModelInfo ( {
137189 model : bot . embedding ,
138190 prisma,
@@ -143,7 +195,7 @@ export const chatRequestStreamHandler = async (
143195 return handleErrorResponse (
144196 history ,
145197 message ,
146- "There was an error processing your request. "
198+ "No embedding model found "
147199 ) ;
148200 }
149201
@@ -165,7 +217,7 @@ export const chatRequestStreamHandler = async (
165217 return handleErrorResponse (
166218 history ,
167219 message ,
168- "There was an error processing your request. "
220+ "Not model found "
169221 ) ;
170222 }
171223
@@ -236,11 +288,10 @@ export const chatRequestStreamHandler = async (
236288 await nextTick ( ) ;
237289 return reply . raw . end ( ) ;
238290 } catch ( e ) {
239- console . error ( e ) ;
240291 return handleErrorResponse (
241292 history ,
242293 message ,
243- "There was an error processing your request. "
294+ "Internal Server Error "
244295 ) ;
245296 }
246297} ;
0 commit comments