🧹 chore: address minor issues (#3710)
* refactor(OpenAIClient): improve error handling in chat completion Improve error handling in the chat completion process to handle scenarios where the response has no choices or the message is undefined. This ensures that the intermediate reply is returned in such cases. Also, add logging statements for better debugging. * refactor(Markdown): only show blinking cursor for latest message * refactor: add submitting selector to prevent blinking cursor for empty, non-streaming, non-latest messages
This commit is contained in:
@@ -1250,14 +1250,23 @@ ${convo}
|
||||
throw new Error('Chat completion failed');
|
||||
}
|
||||
|
||||
const { message, finish_reason } = chatCompletion.choices[0];
|
||||
if (chatCompletion) {
|
||||
this.metadata = { finish_reason };
|
||||
const { choices } = chatCompletion;
|
||||
if (!Array.isArray(choices) || choices.length === 0) {
|
||||
logger.warn('[OpenAIClient] Chat completion response has no choices');
|
||||
return intermediateReply;
|
||||
}
|
||||
|
||||
const { message, finish_reason } = choices[0] ?? {};
|
||||
this.metadata = { finish_reason };
|
||||
|
||||
logger.debug('[OpenAIClient] chatCompletion response', chatCompletion);
|
||||
|
||||
if (!message?.content?.trim() && intermediateReply.length) {
|
||||
if (!message) {
|
||||
logger.warn('[OpenAIClient] Message is undefined in chatCompletion response');
|
||||
return intermediateReply;
|
||||
}
|
||||
|
||||
if (typeof message.content !== 'string' || message.content.trim() === '') {
|
||||
logger.debug(
|
||||
'[OpenAIClient] chatCompletion: using intermediateReply due to empty message.content',
|
||||
{ intermediateReply },
|
||||
|
||||
@@ -144,7 +144,7 @@ const Markdown = memo(({ content = '', isEdited, showCursor, isLatestMessage }:
|
||||
return (
|
||||
<div className="absolute">
|
||||
<p className="relative">
|
||||
<span className="result-thinking" />
|
||||
<span className={isLatestMessage ? 'result-thinking' : ''} />
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -77,6 +77,7 @@ const DisplayMessage = ({ text, isCreatedByUser, message, showCursor }: TDisplay
|
||||
<Container message={message}>
|
||||
<div
|
||||
className={cn(
|
||||
isSubmitting ? 'submitting' : '',
|
||||
showCursorState && !!text.length ? 'result-streaming' : '',
|
||||
'markdown prose message-content dark:prose-invert light w-full break-words',
|
||||
isCreatedByUser ? 'whitespace-pre-wrap dark:text-gray-20' : 'dark:text-gray-100',
|
||||
|
||||
@@ -34,6 +34,7 @@ const DisplayMessage = ({ text, isCreatedByUser = false, message, showCursor }:
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
isSubmitting ? 'submitting' : '',
|
||||
showCursorState && !!text.length ? 'result-streaming' : '',
|
||||
'markdown prose message-content dark:prose-invert light w-full break-words',
|
||||
isCreatedByUser ? 'whitespace-pre-wrap dark:text-gray-20' : 'dark:text-gray-70',
|
||||
|
||||
@@ -1742,7 +1742,7 @@ button.scroll-convo {
|
||||
transform: scale3d(1.25, 1.25, 1);
|
||||
}
|
||||
}
|
||||
.result-thinking:empty:last-child:after {
|
||||
.submitting .result-thinking:empty:last-child:after {
|
||||
-webkit-font-smoothing: subpixel-antialiased;
|
||||
-webkit-animation: pulseSize 1.25s ease-in-out infinite;
|
||||
animation: pulseSize 1.25s ease-in-out infinite;
|
||||
|
||||
Reference in New Issue
Block a user