Class: LLM::Provider::Transport::HTTP Private

Inherits:
Object
  • Object
show all
Includes:
Interruptible
Defined in:
lib/llm/provider/transport/http.rb,
lib/llm/provider/transport/http/execution.rb,
lib/llm/provider/transport/http/interruptible.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The LLM::Provider::Transport::HTTP class manages HTTP connections for LLM::Provider. It handles transient and persistent clients, tracks active requests by owner, and interrupts in-flight requests when needed.

Defined Under Namespace

Modules: Execution, Interruptible

Constant Summary

Constants included from Interruptible

Interruptible::INTERRUPT_ERRORS

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:, timeout:, ssl:, persistent: false) ⇒ LLM::Provider::Transport::HTTP

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • host (String)
  • port (Integer)
  • timeout (Integer)
  • ssl (Boolean)
  • persistent (Boolean) (defaults to: false)


24
25
26
27
28
29
30
31
32
# File 'lib/llm/provider/transport/http.rb', line 24

def initialize(host:, port:, timeout:, ssl:, persistent: false)
  @host = host
  @port = port
  @timeout = timeout
  @ssl = ssl
  @base_uri = URI("#{ssl ? "https" : "http"}://#{host}:#{port}/")
  @persistent_client = persistent ? persistent_client : nil
  @monitor = Monitor.new
end

Instance Method Details

#inspectString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


93
94
95
# File 'lib/llm/provider/transport/http.rb', line 93

def inspect
  "#<#{self.class.name}:0x#{object_id.to_s(16)} @persistent=#{persistent?}>"
end

#interrupt!(owner) ⇒ nil

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Interrupt an active request, if any.

Parameters:

  • owner (Fiber)

Returns:

  • (nil)


38
39
40
# File 'lib/llm/provider/transport/http.rb', line 38

def interrupt!(owner)
  super
end

#interrupted?(owner) ⇒ Boolean?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether an execution owner was interrupted.

Parameters:

  • owner (Fiber)

Returns:

  • (Boolean, nil)


46
47
48
# File 'lib/llm/provider/transport/http.rb', line 46

def interrupted?(owner)
  super
end

#request_ownerFiber

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the current request owner.

Returns:

  • (Fiber)


53
54
55
# File 'lib/llm/provider/transport/http.rb', line 53

def request_owner
  Fiber.current
end

#persist!LLM::Provider::Transport::HTTP Also known as: persistent

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Configures the transport to use a persistent HTTP connection pool.



60
61
62
63
64
65
66
# File 'lib/llm/provider/transport/http.rb', line 60

def persist!
  client = persistent_client
  lock do
    @persistent_client = client
    self
  end
end

#persistent?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


71
72
73
# File 'lib/llm/provider/transport/http.rb', line 71

def persistent?
  !persistent_client.nil?
end

#request(request, owner:) {|http| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Performs a request on the current HTTP transport.

Parameters:

  • request (Net::HTTPRequest)
  • owner (Fiber)

Yield Parameters:

  • http (Net::HTTP)

Returns:



81
82
83
84
85
86
87
88
89
# File 'lib/llm/provider/transport/http.rb', line 81

def request(request, owner:, &)
  if persistent?
    request_persistent(request, owner, &)
  else
    request_transient(request, owner, &)
  end
ensure
  clear_request(owner)
end