Skip to content

Commit c5af48c

Browse files
committed
Add support for outputting reasoning process in DeepSeek
- Modified `stream_response` method to handle reasoning content blocks. - Added logic to yield "<think>" and "</think>" tags around reasoning content.
1 parent 9ec3640 commit c5af48c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

examples/pipelines/providers/aws_bedrock_deepseek_pipeline.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)