Skip to content

Commit e58f614

Browse files
authored
fix(qa): read properly var to fix streaming (#341)
1 parent d9394b5 commit e58f614

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

lambda/aws-qa-appsync-opensearch/question_answering/src/adapters/base/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717

1818
class ModelAdapter:
19-
def __init__(self, callback=None, modality='Text', model_kwargs={}):
19+
def __init__(self, callback=None, modality='Text', model_kwargs={}, streaming=False):
2020
self.model_kwargs = model_kwargs
2121
self.modality = modality
22+
self.streaming = streaming
2223

2324
self.callback_handler = callback
2425

lambda/aws-qa-appsync-opensearch/question_answering/src/adapters/bedrock/claude.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def get_llm(self, model_kwargs={}):
5050
"streaming": False
5151
}
5252

53-
if self.callback_handler:
53+
if self.callback_handler and self.streaming:
5454
kwargs["callbacks"] = self.callback_handler
55-
kwargs["streaming"] = model_kwargs.get("streaming", False)
55+
kwargs["streaming"] = True
5656

5757
return Bedrock(
5858
**kwargs
@@ -104,9 +104,9 @@ def get_llm(self, model_kwargs={}):
104104
"streaming": False
105105
}
106106

107-
if self.callback_handler:
107+
if self.callback_handler and self.streaming:
108108
kwargs["callbacks"] = self.callback_handler
109-
kwargs["streaming"] = model_kwargs.get("streaming", False)
109+
kwargs["streaming"] = True
110110

111111
return BedrockChat(
112112
**kwargs

lambda/aws-qa-appsync-opensearch/question_answering/src/adapters/bedrock/titan.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ def get_llm(self, model_kwargs={}):
4646
"streaming": False
4747
}
4848

49-
if self.callback_handler:
49+
if self.callback_handler and self.streaming:
5050
kwargs["callbacks"] = self.callback_handler
51-
kwargs["streaming"] = model_kwargs.get("streaming", False)
51+
kwargs["streaming"] = True
5252

5353
return Bedrock(
5454
**kwargs

lambda/aws-qa-appsync-opensearch/question_answering/src/qa_agent/doc_qa.py

+3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def run_qa_agent_rag_no_memory(input_params):
8181
callback=callback_manager,
8282
modality=qa_modality,
8383
model_kwargs=qa_model_args,
84+
streaming=streaming
8485
)
8586

8687
# get embeddings model
@@ -104,6 +105,7 @@ def run_qa_agent_rag_no_memory(input_params):
104105
model_id=em_model_id,
105106
modality=qa_modality,
106107
model_kwargs=em_model_args,
108+
streaming=streaming
107109
)
108110

109111
logger.info(decoded_question)
@@ -231,6 +233,7 @@ def run_qa_agent_from_single_document_no_memory(input_params):
231233
callback=callback_manager,
232234
modality=qa_modality,
233235
model_kwargs=qa_model_args,
236+
streaming=streaming
234237
)
235238

236239
# 1 : load the document

src/patterns/gen-ai/aws-qa-appsync-opensearch/README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Mutation call to trigger the question:
189189
jobid: "123",
190190
jobstatus: "",
191191
qa_model:
192-
{
192+
{
193193
provider: "Bedrock",
194194
modality: "Text",
195195
modelId: "anthropic.claude-v2:1",
@@ -299,23 +299,23 @@ Parameters
299299

300300
Question answering
301301

302-
| **Provider** | **Model id** | **Modalities** | **Notes** |
303-
| :----------------------------- | :---- | ----- | --- |
304-
| Bedrock | anthropic.claude-v2 | Text | |
305-
| Bedrock | anthropic.claude-v2:1 | Text | |
306-
| Bedrock | anthropic.claude-3-haiku-20240307-v1:0 | Text, Image | |
307-
| Bedrock | anthropic.claude-3-sonnet-20240229-v1:0 | Text, Image | |
308-
| Bedrock | anthropic.claude-instant-v1 | Text | |
309-
| Bedrock | amazon.titan-text-lite-v1 | Text | |
310-
| Bedrock | amazon.titan-text-express-v1 | Text | |
311-
| SageMaker | idefics | Text, Image | The model is not deployed as part of the construct and requires to be provisioned separately |
302+
| **Provider** | **Model id** | **Modalities** | **Streaming** | **Notes** |
303+
| :----------------------------- | :---- | ----- | --- | --- |
304+
| Bedrock | anthropic.claude-v2 | Text | | |
305+
| Bedrock | anthropic.claude-v2:1 | Text | | Default model is none selected |
306+
| Bedrock | anthropic.claude-3-haiku-20240307-v1:0 | Text, Image | | |
307+
| Bedrock | anthropic.claude-3-sonnet-20240229-v1:0 | Text, Image | | |
308+
| Bedrock | anthropic.claude-instant-v1 | Text | | |
309+
| Bedrock | amazon.titan-text-lite-v1 | Text | |
310+
| Bedrock | amazon.titan-text-express-v1 | Text | |
311+
| SageMaker | idefics | Text, Image | | The model is not deployed as part of the construct and requires to be provisioned separately |
312312

313313
Embeddings
314314

315315
| **Provider** | **Model id** | **Modalities** | **Notes** |
316316
| :----------------------------- | :---- | ----- | --- |
317317
| Bedrock | amazon.titan-embed-image-v1 | Text | |
318-
| Bedrock | amazon.titan-embed-text-v1 | Text | |
318+
| Bedrock | amazon.titan-embed-text-v1 | Text | Default model is none selected |
319319

320320
## Default properties
321321

0 commit comments

Comments
 (0)