File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
examples/pipelines/providers Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -165,9 +165,22 @@ def pipe(
165165
166166 def stream_response (self , model_id : str , payload : dict ) -> Generator :
167167 streaming_response = self .bedrock_runtime .converse_stream (** payload )
168+
169+ in_resasoning_context = False
168170 for chunk in streaming_response ["stream" ]:
169- if "contentBlockDelta" in chunk and "text" in chunk ["contentBlockDelta" ]["delta" ]:
170- yield chunk ["contentBlockDelta" ]["delta" ]["text" ]
171+ if in_resasoning_context and "contentBlockStop" in chunk :
172+ in_resasoning_context = False
173+ yield "\n </think> \n \n "
174+ elif "contentBlockDelta" in chunk and "delta" in chunk ["contentBlockDelta" ]:
175+ if "reasoningContent" in chunk ["contentBlockDelta" ]["delta" ]:
176+ if not in_resasoning_context :
177+ yield "<think>"
178+
179+ in_resasoning_context = True
180+ if "text" in chunk ["contentBlockDelta" ]["delta" ]["reasoningContent" ]:
181+ yield chunk ["contentBlockDelta" ]["delta" ]["reasoningContent" ]["text" ]
182+ elif "text" in chunk ["contentBlockDelta" ]["delta" ]:
183+ yield chunk ["contentBlockDelta" ]["delta" ]["text" ]
171184
172185 def get_completion (self , model_id : str , payload : dict ) -> str :
173186 response = self .bedrock_runtime .converse (** payload )
You can’t perform that action at this time.
0 commit comments