@@ -89,40 +89,56 @@ export default function ConversationView({
8989 ) ;
9090 } ) }
9191 { responses ?. length > 0 &&
92- JSON . parse ( responses ) . map ( ( response : any , i : number ) => {
93- const role =
94- response ?. role ?. toLowerCase ( ) ||
95- response ?. message ?. role ||
96- "Assistant" ;
97- const content = response ?. content
98- ? safeStringify ( response ?. content )
99- : response ?. function_call
100- ? safeStringify ( response ?. function_call )
101- : response ?. message ?. content
102- ? safeStringify ( response ?. message ?. content )
103- : response ?. text
104- ? safeStringify ( response ?. text )
105- : "No output found" ;
106- const vendor = getVendorFromSpan ( span ) ;
107- return (
108- < div className = "flex flex-col gap-2 whitespace-pre-wrap" key = { i } >
109- < div className = "flex gap-2 items-center" >
110- { role === "user" ? (
111- < UserLogo />
112- ) : (
113- < VendorLogo variant = "circular" vendor = { vendor } />
114- ) }
115- < p className = "font-semibold text-md capitalize" > { role } </ p >
92+ ( typeof responses === "string" && responses . startsWith ( "[" ) ? (
93+ JSON . parse ( responses ) . map ( ( response : any , i : number ) => {
94+ const role =
95+ response ?. role ?. toLowerCase ( ) ||
96+ response ?. message ?. role ||
97+ "Assistant" ;
98+ const content = response ?. content
99+ ? safeStringify ( response ?. content )
100+ : response ?. function_call
101+ ? safeStringify ( response ?. function_call )
102+ : response ?. message ?. content
103+ ? safeStringify ( response ?. message ?. content )
104+ : response ?. text
105+ ? safeStringify ( response ?. text )
106+ : "No output found" ;
107+ const vendor = getVendorFromSpan ( span ) ;
108+ return (
109+ < div className = "flex flex-col gap-2 whitespace-pre-wrap" key = { i } >
110+ < div className = "flex gap-2 items-center" >
111+ { role === "user" ? (
112+ < UserLogo />
113+ ) : (
114+ < VendorLogo variant = "circular" vendor = { vendor } />
115+ ) }
116+ < p className = "font-semibold text-md capitalize" > { role } </ p >
117+ </ div >
118+ < div
119+ className = "text-sm bg-muted rounded-md px-2 py-4 break-all whitespace-pre-wrap"
120+ dangerouslySetInnerHTML = { {
121+ __html : content ,
122+ } }
123+ />
116124 </ div >
117- < div
118- className = "text-sm bg-muted rounded-md px-2 py-4 break-all whitespace-pre-wrap"
119- dangerouslySetInnerHTML = { {
120- __html : content ,
121- } }
122- />
125+ ) ;
126+ } )
127+ ) : (
128+ // Handle case where responses is a plain string
129+ < div className = "flex flex-col gap-2 whitespace-pre-wrap" >
130+ < div className = "flex gap-2 items-center" >
131+ < VendorLogo variant = "circular" vendor = { getVendorFromSpan ( span ) } />
132+ < p className = "font-semibold text-md capitalize" > Assistant</ p >
123133 </ div >
124- ) ;
125- } ) }
134+ < div
135+ className = "text-sm bg-muted rounded-md px-2 py-4 break-all whitespace-pre-wrap"
136+ dangerouslySetInnerHTML = { {
137+ __html : safeStringify ( responses ) ,
138+ } }
139+ />
140+ </ div >
141+ ) ) }
126142 </ div >
127143 ) ;
128144}
0 commit comments