Class: Aws::BedrockRuntime::Client
- Inherits:
-
Seahorse::Client::Base
- Object
- Seahorse::Client::Base
- Aws::BedrockRuntime::Client
- Includes:
- ClientStubs
- Defined in:
- lib/aws-sdk-bedrockruntime/client.rb
Overview
An API client for BedrockRuntime. To construct a client, you need to configure a ‘:region` and `:credentials`.
client = Aws::BedrockRuntime::Client.new(
region: region_name,
credentials: credentials,
# ...
)
For details on configuring region and credentials see the [developer guide](/sdk-for-ruby/v3/developer-guide/setup-config.html).
See #initialize for a full list of supported configuration options.
Class Attribute Summary collapse
- .identifier ⇒ Object readonly private
API Operations collapse
-
#converse(params = {}) ⇒ Types::ConverseResponse
Sends messages to the specified Amazon Bedrock model.
-
#converse_stream(params = {}) ⇒ Types::ConverseStreamResponse
Sends messages to the specified Amazon Bedrock model and returns the response in a stream.
-
#invoke_model(params = {}) ⇒ Types::InvokeModelResponse
Invokes the specified Amazon Bedrock model to run inference using the prompt and inference parameters provided in the request body.
-
#invoke_model_with_response_stream(params = {}) ⇒ Types::InvokeModelWithResponseStreamResponse
Invoke the specified Amazon Bedrock model to run inference using the prompt and inference parameters provided in the request body.
Class Method Summary collapse
- .errors_module ⇒ Object private
Instance Method Summary collapse
- #build_request(operation_name, params = {}) ⇒ Object private
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #waiter_names ⇒ Object deprecated private Deprecated.
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
421 422 423 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 421 def initialize(*args) super end |
Class Attribute Details
.identifier ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1480 1481 1482 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1480 def identifier @identifier end |
Class Method Details
.errors_module ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1483 1484 1485 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1483 def errors_module Errors end |
Instance Method Details
#build_request(operation_name, params = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1458 def build_request(operation_name, params = {}) handlers = @handlers.for(operation_name) context = Seahorse::Client::RequestContext.new( operation_name: operation_name, operation: config.api.operation(operation_name), client: self, params: params, config: config) context[:gem_name] = 'aws-sdk-bedrockruntime' context[:gem_version] = '1.10.0' Seahorse::Client::Request.new(handlers, context) end |
#converse(params = {}) ⇒ Types::ConverseResponse
Sends messages to the specified Amazon Bedrock model. ‘Converse` provides a consistent interface that works with all models that support messages. This allows you to write code once and use it with different models. Should a model have unique inference parameters, you can also pass those unique parameters to the model. For more information, see [Run inference] in the Bedrock User Guide.
This operation requires permission for the ‘bedrock:InvokeModel` action.
[1]: docs.aws.amazon.com/bedrock/latest/userguide/api-methods-run.html
636 637 638 639 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 636 def converse(params = {}, = {}) req = build_request(:converse, params) req.send_request() end |
#converse_stream(params = {}) ⇒ Types::ConverseStreamResponse
Sends messages to the specified Amazon Bedrock model and returns the response in a stream. ‘ConverseStream` provides a consistent API that works with all Amazon Bedrock models that support messages. This allows you to write code once and use it with different models. Should a model have unique inference parameters, you can also pass those unique parameters to the model. For more information, see [Run inference] in the Bedrock User Guide.
To find out if a model supports streaming, call
- GetFoundationModel][2
-
and check the ‘responseStreamingSupported`
field in the response.
For example code, see *Invoke model with streaming code example* in the *Amazon Bedrock User Guide*.
This operation requires permission for the ‘bedrock:InvokeModelWithResponseStream` action.
[1]: docs.aws.amazon.com/bedrock/latest/userguide/api-methods-run.html [2]: docs.aws.amazon.com/bedrock/latest/APIReference/API_GetFoundationModel.html
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1037 def converse_stream(params = {}, = {}, &block) params = params.dup event_stream_handler = case handler = params.delete(:event_stream_handler) when EventStreams::ConverseStreamOutput then handler when Proc then EventStreams::ConverseStreamOutput.new.tap(&handler) when nil then EventStreams::ConverseStreamOutput.new else msg = "expected :event_stream_handler to be a block or "\ "instance of Aws::BedrockRuntime::EventStreams::ConverseStreamOutput"\ ", got `#{handler.inspect}` instead" raise ArgumentError, msg end yield(event_stream_handler) if block_given? req = build_request(:converse_stream, params) req.context[:event_stream_handler] = event_stream_handler req.handlers.add(Aws::Binary::DecodeHandler, priority: 95) req.send_request(, &block) end |
#invoke_model(params = {}) ⇒ Types::InvokeModelResponse
Invokes the specified Amazon Bedrock model to run inference using the prompt and inference parameters provided in the request body. You use model inference to generate text, images, and embeddings.
For example code, see *Invoke model code examples* in the *Amazon Bedrock User Guide*.
This operation requires permission for the ‘bedrock:InvokeModel` action.
1162 1163 1164 1165 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1162 def invoke_model(params = {}, = {}) req = build_request(:invoke_model, params) req.send_request() end |
#invoke_model_with_response_stream(params = {}) ⇒ Types::InvokeModelWithResponseStreamResponse
Invoke the specified Amazon Bedrock model to run inference using the prompt and inference parameters provided in the request body. The response is returned in a stream.
To see if a model supports streaming, call [GetFoundationModel] and check the ‘responseStreamingSupported` field in the response.
<note markdown=“1”> The CLI doesn’t support ‘InvokeModelWithResponseStream`.
</note>
For example code, see *Invoke model with streaming code example* in the *Amazon Bedrock User Guide*.
This operation requires permissions to perform the ‘bedrock:InvokeModelWithResponseStream` action.
[1]: docs.aws.amazon.com/bedrock/latest/APIReference/API_GetFoundationModel.html
1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1431 def invoke_model_with_response_stream(params = {}, = {}, &block) params = params.dup event_stream_handler = case handler = params.delete(:event_stream_handler) when EventStreams::ResponseStream then handler when Proc then EventStreams::ResponseStream.new.tap(&handler) when nil then EventStreams::ResponseStream.new else msg = "expected :event_stream_handler to be a block or "\ "instance of Aws::BedrockRuntime::EventStreams::ResponseStream"\ ", got `#{handler.inspect}` instead" raise ArgumentError, msg end yield(event_stream_handler) if block_given? req = build_request(:invoke_model_with_response_stream, params) req.context[:event_stream_handler] = event_stream_handler req.handlers.add(Aws::Binary::DecodeHandler, priority: 95) req.send_request(, &block) end |
#waiter_names ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1473 1474 1475 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1473 def waiter_names [] end |