@@ -534,52 +534,3 @@ Consuming the Stream
534534 elif event_type == " error" :
535535 print (f " Error: { data[' msg' ]} " )
536536 event_type = None
537-
538- **JavaScript (using EventSource or fetch): **
539-
540- .. code-block :: javascript
541-
542- const response = await fetch (
543- ` https://api.robusta.dev/api/holmes/${ accountId} /chat` ,
544- {
545- method: " POST" ,
546- headers: {
547- " Content-Type" : " application/json" ,
548- Authorization: ` Bearer ${ apiKey} ` ,
549- },
550- body: JSON .stringify ({ ask: " Which pods are failing prod-us?" , stream: true }),
551- }
552- );
553-
554- const reader = response .body .getReader ();
555- const decoder = new TextDecoder ();
556- let eventType = null ;
557-
558- while (true ) {
559- const { done , value } = await reader .read ();
560- if (done) break ;
561-
562- const text = decoder .decode (value);
563- for (const line of text .split (" \n " )) {
564- if (line .startsWith (" event: " )) {
565- eventType = line .slice (7 );
566- } else if (line .startsWith (" data: " ) && eventType) {
567- const data = JSON .parse (line .slice (6 ));
568- switch (eventType) {
569- case " ai_answer_end" :
570- console .log (" Final analysis:" , data .analysis );
571- break ;
572- case " ai_message" :
573- console .log (" AI:" , data .content );
574- break ;
575- case " start_tool_calling" :
576- console .log (" Running tool:" , data .tool_name );
577- break ;
578- case " error" :
579- console .error (" Error:" , data .msg );
580- break ;
581- }
582- eventType = null ;
583- }
584- }
585- }
0 commit comments