Class: Net::Llm::Claude

Inherits:
Object
  • Object
show all
Defined in:
lib/net/llm/claude.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint:, headers:, http:, model: nil, anthropic_version: nil) ⇒ Claude

Returns a new instance of Claude.



8
9
10
11
12
13
14
# File 'lib/net/llm/claude.rb', line 8

def initialize(endpoint:, headers:, http:, model: nil, anthropic_version: nil)
  @endpoint = endpoint
  @headers_source = headers
  @model = model
  @http = http
  @anthropic_version = anthropic_version
end

Instance Attribute Details

#anthropic_version ⇒ Object (readonly)

Returns the value of attribute anthropic_version.



6
7
8
# File 'lib/net/llm/claude.rb', line 6

def anthropic_version
  @anthropic_version
end

#endpoint ⇒ Object (readonly)

Returns the value of attribute endpoint.



6
7
8
# File 'lib/net/llm/claude.rb', line 6

def endpoint
  @endpoint
end

#headers ⇒ Object (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/net/llm/claude.rb', line 6

def headers
  @headers
end

#http ⇒ Object (readonly)

Returns the value of attribute http.



6
7
8
# File 'lib/net/llm/claude.rb', line 6

def http
  @http
end

#model ⇒ Object (readonly)

Returns the value of attribute model.



6
7
8
# File 'lib/net/llm/claude.rb', line 6

def model
  @model
end

Instance Method Details

#fetch(messages, tools = [], &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/net/llm/claude.rb', line 30

def fetch(messages, tools = [], &block)
  system_message, user_messages = extract_system_message(messages)
  anthropic_tools = tools.empty? ? nil : tools.map { |t| normalize_tool_for_anthropic(t) }

  if block_given?
    fetch_streaming(user_messages, anthropic_tools, system: system_message, &block)
  else
    fetch_non_streaming(user_messages, anthropic_tools, system: system_message)
  end
end

#messages(messages, system: nil, max_tokens: 64000, tools: nil, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/net/llm/claude.rb', line 20

def messages(messages, system: nil, max_tokens: 64000, tools: nil, &block)
  payload = build_payload(messages, system, max_tokens, tools, block_given?)

  if block_given?
    stream_request(payload, &block)
  else
    post_request(payload)
  end
end