Class: Raif::Llms::BedrockMantle

Inherits:
Raif::Llm
  • Object
show all
Includes:
Concerns::Llms::OpenAiCompletions::Protocol
Defined in:
app/models/raif/llms/bedrock_mantle.rb

Overview

Bedrock Mantle is AWS's OpenAI-compatible Chat Completions endpoint for Bedrock models. It shares the Chat Completions protocol with OpenAiCompletions and XAi but authenticates with SigV4 from the AWS SDK credential chain instead of an API key.

Instance Method Summary collapse

Instance Method Details

#perform_model_completion!(model_completion, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/raif/llms/bedrock_mantle.rb', line 9

def perform_model_completion!(model_completion, &block)
  parameters = build_request_parameters(model_completion)
  response = connection.post("chat/completions") do |req|
    req.body = JSON.generate(parameters)
    req.headers.merge!(request_signer.sign_request(
      http_method: "POST",
      url: connection.build_url(req.path, req.params),
      headers: { "Content-Type" => "application/json" },
      body: req.body
    ).headers)
    req.options.on_data = streaming_chunk_handler(model_completion, &block) if model_completion.stream_response?
  end

  unless model_completion.stream_response?
    update_model_completion(model_completion, response.body)
  end

  model_completion
end