File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
src/App/src/components/Chat Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -568,8 +568,16 @@ const Chat: React.FC<ChatProps> = ({
568568 chartResponse = parsedChartResponse ?. choices [ 0 ] ?. messages [ 0 ] ?. content ;
569569 }
570570
571- if ( typeof chartResponse === 'object' && chartResponse ?. answer ) {
572- chartResponse = chartResponse . answer ;
571+ if ( typeof chartResponse === 'object' && 'answer' in chartResponse ) {
572+ if (
573+ chartResponse . answer === "" ||
574+ chartResponse . answer === undefined ||
575+ ( typeof chartResponse . answer === "object" && Object . keys ( chartResponse . answer ) . length === 0 )
576+ ) {
577+ chartResponse = "Chart can't be generated, please try again." ;
578+ } else {
579+ chartResponse = chartResponse . answer ;
580+ }
573581 }
574582
575583 if (
@@ -619,6 +627,16 @@ const Chat: React.FC<ChatProps> = ({
619627 parsedChartResponse ?. error ||
620628 parsedChartResponse ?. choices [ 0 ] ?. messages [ 0 ] ?. content
621629 ) {
630+ let content = parsedChartResponse ?. choices [ 0 ] ?. messages [ 0 ] ?. content ;
631+ let displayContent = content ;
632+ try {
633+ const parsed = typeof content === "string" ? JSON . parse ( content ) : content ;
634+ if ( parsed && typeof parsed === "object" && "answer" in parsed ) {
635+ displayContent = parsed . answer ;
636+ }
637+ } catch {
638+ displayContent = content ;
639+ }
622640 const errorMsg =
623641 parsedChartResponse ?. error ||
624642 parsedChartResponse ?. choices [ 0 ] ?. messages [ 0 ] ?. content
You can’t perform that action at this time.
0 commit comments