55# the root directory of this source tree.
66from typing import Generator
77from termcolor import cprint
8- from llama_stack_client .types import ChatCompletionResponseStreamChunk , ChatCompletionChunk
8+ from llama_stack_client .types import ChatCompletionChunk
99
1010
1111class InferenceStreamPrintableEvent :
@@ -28,35 +28,11 @@ def __init__(self):
2828 self .is_thinking = False
2929
3030 def yield_printable_events (
31- self , chunk : ChatCompletionResponseStreamChunk | ChatCompletionChunk
31+ self , chunk : ChatCompletionChunk
3232 ) -> Generator [InferenceStreamPrintableEvent , None , None ]:
33- # Check if the chunk has event attribute (ChatCompletionResponseStreamChunk)
34- if hasattr (chunk , "event" ):
35- yield from self ._handle_inference_stream_chunk (chunk )
36- # Check if the chunk has choices attribute (ChatCompletionChunk)
37- elif hasattr (chunk , "choices" ) and len (chunk .choices ) > 0 :
33+ if hasattr (chunk , "choices" ) and len (chunk .choices ) > 0 :
3834 yield from self ._handle_chat_completion_chunk (chunk )
3935
40- def _handle_inference_stream_chunk (
41- self , chunk : ChatCompletionResponseStreamChunk
42- ) -> Generator [InferenceStreamPrintableEvent , None , None ]:
43- event = chunk .event
44- if event .event_type == "start" :
45- yield InferenceStreamPrintableEvent ("Assistant> " , color = "cyan" , end = "" )
46- elif event .event_type == "progress" :
47- if event .delta .type == "reasoning" :
48- if not self .is_thinking :
49- yield InferenceStreamPrintableEvent ("<thinking> " , color = "magenta" , end = "" )
50- self .is_thinking = True
51- yield InferenceStreamPrintableEvent (event .delta .reasoning , color = "magenta" , end = "" )
52- else :
53- if self .is_thinking :
54- yield InferenceStreamPrintableEvent ("</thinking>" , color = "magenta" , end = "" )
55- self .is_thinking = False
56- yield InferenceStreamPrintableEvent (event .delta .text , color = "yellow" , end = "" )
57- elif event .event_type == "complete" :
58- yield InferenceStreamPrintableEvent ("" )
59-
6036 def _handle_chat_completion_chunk (
6137 self , chunk : ChatCompletionChunk
6238 ) -> Generator [InferenceStreamPrintableEvent , None , None ]:
0 commit comments