Class: Foobara::Ai::AnthropicApi::CreateMessage

Inherits:
BaseCommand show all
Defined in:
foobara-anthropic-api-1.0.5/src/foobara/ai/anthropic_api/create_message.rb

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Method Summary collapse

Methods inherited from BaseCommand

#anthropic_version, #api_token, #api_token_from_env, #build_request_headers, #issue_http_request

Methods inherited from Command

install!

Methods included from TruncatedInspect

#inspect, truncating

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Instance Method Details

#build_request_bodyObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'src/foobara/ai/anthropic_api/create_message.rb', line 20

def build_request_body
  body = { model:, max_tokens:, messages: }

  temp = inputs[:temperature]
  if temp
    body[:temperature] = temp
  end

  sys = inputs[:system]
  if sys
    body[:system] = sys
  end

  self.request_body = body
end

#build_resultObject



36
37
38
# File 'src/foobara/ai/anthropic_api/create_message.rb', line 36

def build_result
  Types::MessageResult.new(response_body, ignore_unexpected_attributes: true)
end