6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/models/raif/llms/bedrock_claude.rb', line 6
def perform_model_completion!(model_completion)
if Raif.config.aws_bedrock_model_name_prefix.present?
model_completion.model_api_name = "#{Raif.config.aws_bedrock_model_name_prefix}.#{model_completion.model_api_name}"
end
params = build_request_parameters(model_completion)
resp = bedrock_client.converse(params)
model_completion.raw_response = if model_completion.response_format_json?
(resp)
else
(resp)
end
model_completion.completion_tokens = resp.usage.output_tokens
model_completion.prompt_tokens = resp.usage.input_tokens
model_completion.total_tokens = resp.usage.total_tokens
model_completion.save!
model_completion
end
|