@@ -66,6 +66,7 @@ const genValidator = {
66
66
userEmbeds : 'any?' ,
67
67
} ,
68
68
lines : [ 'string' ] ,
69
+ linesCount : 'number?' ,
69
70
text : 'string?' ,
70
71
settings : 'any?' ,
71
72
lastMessage : 'string?' ,
@@ -247,15 +248,6 @@ export const generateMessageV2 = handle(async (req, res) => {
247
248
} )
248
249
}
249
250
250
- res . json ( {
251
- requestId,
252
- success : true ,
253
- generating : true ,
254
- message : 'Generating message' ,
255
- messageId,
256
- created : userMsg ,
257
- } )
258
-
259
251
const entities = await getResponseEntities ( chat , body . sender . userId , body . settings )
260
252
const schema = entities . gen . jsonSource === 'character' ? replyAs . json : entities . gen . json
261
253
const hydrator = entities . gen . jsonEnabled && schema ? jsonHydrator ( schema ) : undefined
@@ -271,9 +263,10 @@ export const generateMessageV2 = handle(async (req, res) => {
271
263
let probs : any
272
264
273
265
if ( body . response === undefined ) {
274
- const { stream , ... metadata } = await createChatStream (
266
+ const chatStream = await createChatStream (
275
267
{
276
268
...body ,
269
+ linesCount : body . linesCount ,
277
270
chat,
278
271
replyAs,
279
272
impersonate,
@@ -282,7 +275,22 @@ export const generateMessageV2 = handle(async (req, res) => {
282
275
chatSchema : schema ,
283
276
} ,
284
277
log
285
- )
278
+ ) . catch ( ( err ) => ( { err } ) )
279
+
280
+ if ( 'err' in chatStream ) {
281
+ throw chatStream . err
282
+ }
283
+
284
+ res . json ( {
285
+ requestId,
286
+ success : true ,
287
+ generating : true ,
288
+ message : 'Generating message' ,
289
+ messageId,
290
+ created : userMsg ,
291
+ } )
292
+
293
+ const { stream, ...metadata } = chatStream
286
294
287
295
adapter = metadata . adapter
288
296
@@ -584,8 +592,6 @@ async function handleGuestGenerate(body: GenRequest, req: AppRequest, res: Respo
584
592
return { success : true }
585
593
}
586
594
587
- res . json ( { success : true , generating : true , message : 'Generating message' , requestId } )
588
-
589
595
const schema = body . settings . jsonSource === 'character' ? body . char . json : body . settings . json
590
596
const hydrator = body . settings . jsonEnabled && schema ? jsonHydrator ( schema ) : undefined
591
597
let generated = body . response || ''
@@ -597,12 +603,20 @@ async function handleGuestGenerate(body: GenRequest, req: AppRequest, res: Respo
597
603
let jsonPartial : any
598
604
599
605
if ( body . response === undefined ) {
600
- const { stream , ... entities } = await createChatStream (
601
- { ...body , chat, replyAs, requestId, chatSchema : schema } ,
606
+ const chatStream = await createChatStream (
607
+ { ...body , chat, replyAs, requestId, chatSchema : schema , linesCount : body . linesCount } ,
602
608
log ,
603
609
guest
604
610
)
605
611
612
+ if ( 'err' in chatStream ) {
613
+ throw chatStream . err
614
+ }
615
+
616
+ const { stream, ...entities } = chatStream
617
+
618
+ res . json ( { success : true , generating : true , message : 'Generating message' , requestId } )
619
+
606
620
log . setBindings ( { adapter } )
607
621
608
622
adapter = entities . adapter
0 commit comments