feat: more err log

このコミットが含まれているのは:
xiang 2023-05-07 20:20:27 +08:00
コミット 5d38348833
2個のファイルの変更6行の追加5行の削除

ファイルの表示

@ -9,8 +9,9 @@ const errorHandler = async (ctx: Context, next: Next) => {
try { try {
await next(); await next();
} catch (err:any) { } catch (err:any) {
ctx.response.status = err.status || 500; console.error(err);
ctx.response.body = err; ctx.body = JSON.stringify(err);
ctx.res.end();
} }
}; };
app.use(errorHandler); app.use(errorHandler);
@ -34,7 +35,7 @@ router.get('/ask', async (ctx) => {
return; return;
} }
const res = await chat.ask({prompt: prompt as string, options}); const res = await chat.ask({prompt: prompt as string, options});
ctx.body = res.text; ctx.body = res?.text;
}); });
router.get('/ask/stream', async (ctx) => { router.get('/ask/stream', async (ctx) => {
@ -54,7 +55,7 @@ router.get('/ask/stream', async (ctx) => {
"Connection": "keep-alive", "Connection": "keep-alive",
}); });
const res = await chat.askStream({prompt: prompt as string, options}); const res = await chat.askStream({prompt: prompt as string, options});
ctx.body = res.text; ctx.body = res?.text;
}) })
app.use(router.routes()); app.use(router.routes());

ファイルの表示

@ -149,7 +149,7 @@ export class Forefront extends Chat {
return; return;
} }
const [{delta: {content}}] = data.choices; const [{delta: {content}}] = data.choices;
cb(null, content); cb(null, content||'');
})) }))
return {text: stream}; return {text: stream};
} catch (e: any) { } catch (e: any) {