Class: Raif::Llms::Anthropic

Inherits:
Raif::Llm
  • Object
show all
Includes:
Concerns::Llms::Anthropic::MessageFormatting, Concerns::Llms::Anthropic::ToolFormatting
Defined in:
app/models/raif/llms/anthropic.rb

Instance Method Summary collapse

Instance Method Details

#perform_model_completion!(model_completion, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/raif/llms/anthropic.rb', line 7

def perform_model_completion!(model_completion, &block)
  params = build_request_parameters(model_completion)
  response = connection.post("messages") do |req|
    req.body = params
    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