Taragolis commented on code in PR #38602:
URL: https://github.com/apache/airflow/pull/38602#discussion_r1544489075


##########
airflow/providers/amazon/aws/operators/bedrock.py:
##########
@@ -0,0 +1,89 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import json
+from typing import TYPE_CHECKING, Any, Sequence
+
+from airflow.providers.amazon.aws.hooks.bedrock import BedrockRuntimeHook
+from airflow.providers.amazon.aws.operators.base_aws import AwsBaseOperator
+from airflow.utils.helpers import prune_dict
+
+if TYPE_CHECKING:
+    from airflow.utils.context import Context
+
+
+DEFAULT_CONN_ID = "aws_default"
+
+
+class BedrockInvokeModelOperator(AwsBaseOperator[BedrockRuntimeHook]):
+    """
+    Invoke the specified Bedrock model to run inference using the input 
provided.
+
+    Use InvokeModel to run inference for text models, image models, and 
embedding models.
+    To see the format and content of the input_data field for different 
models, refer to
+    `Inference parameters docs 
<https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html>`_.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:BedrockInvokeModelOperator`
+
+    :param model_id: The ID of the Bedrock model. (templated)
+    :param input_data: Input data in the format specified in the content-type 
request header. (templated)
+    :param content_type: The MIME type of the input data in the request. 
(templated) Default: application/json
+    :param accept: The desired MIME type of the inference body in the response.
+        (templated) Default: application/json
+
+    :param aws_conn_id: The Airflow connection used for AWS credentials.
+        If this is ``None`` or empty then the default boto3 behaviour is used. 
If
+        running Airflow in a distributed manner and aws_conn_id is None or
+        empty, then default boto3 configuration would be used (and must be
+        maintained on each worker node).
+    :param region_name: AWS region_name. If not specified then the default 
boto3 behaviour is used.

Review Comment:
   Seems like it is implemented by the same way as in Lambda, you only could 
invoke it synchronously 
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-runtime.html
   
   TBH with lambda you can invoke it asynchronously but you can't retrieve any 
result and even status of invocation but that is a different story.
   
   I guess is it also have the same problem as a Lambda, if there is no 
response from the API in more than 60 second it will raise a time out error 
(fixable by increase timeout), if there is no any response for more than 350 
seconds it will raise a connection error (fixable on OS level and adjust keep 
alive). 
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to