testing thinking

This commit is contained in:
jknapp 2025-03-16 18:10:57 -07:00
parent dbf75b48cb
commit 4ec7623c47

View File

@ -151,10 +151,10 @@ class Pipeline:
"inferenceConfig": {"temperature": 1},
"additionalModelRequestFields": reasoning_config
}
# if body.get("stream", False):
# return self.stream_response(model_id, payload)
#else:
return self.get_completion(model_id, payload)
if body.get("stream", False):
return self.stream_response(model_id, payload)
else:
return self.get_completion(model_id, payload)
except Exception as e:
return f"Error: {e}"
@ -175,14 +175,18 @@ class Pipeline:
def stream_response(self, model_id: str, payload: dict) -> Generator:
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-runtime/client/converse_stream.html
if "system" in payload:
del payload["system"]
if "additionalModelRequestFields" in payload:
del payload["additionalModelRequestFields"]
streaming_response = self.bedrock_runtime.converse_stream(**payload)
for chunk in streaming_response["stream"]:
if "contentBlockDelta" in chunk:
yield chunk["contentBlockDelta"]["delta"]["text"]
delta = chunk["contentBlockDelta"]["delta"]
# Handle reasoning content (Chain of Thought)
if "reasoningContent" in delta and "text" in delta["reasoningContent"]:
yield {"type": "reasoning", "content": delta["reasoningContent"]["text"]}
# Handle regular response text
if "text" in delta:
yield {"type": "response", "content": delta["text"]}
def get_completion(self, model_id: str, payload: dict) -> str:
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-runtime/client/converse.html