Class: LLM::Transport::HTTP Private

Inherits:
LLM::Transport show all
Defined in:
lib/llm/transport/http.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::Transport::HTTP transport is the built-in adapter for Ruby’s Net::HTTP. It manages transient HTTP connections, tracks active requests by owner, and interrupts in-flight requests when needed.

Defined Under Namespace

Classes: Request

Constant Summary collapse

INTERRUPT_ERRORS =

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

[::IOError, ::EOFError, Errno::EBADF].freeze

Instance Method Summary collapse

Methods inherited from LLM::Transport

net_http, net_http_persistent, #set_body_stream

Constructor Details

#initialize(host:, port:, timeout:, ssl:) ⇒ LLM::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)


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

def initialize(host:, port:, timeout:, ssl:)
  @host = host
  @port = port
  @timeout = timeout
  @ssl = ssl
  @base_uri = URI("#{ssl ? "https" : "http"}://#{host}:#{port}/")
  @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)


85
86
87
# File 'lib/llm/transport/http.rb', line 85

def inspect
  "#<#{self.class.name}:0x#{object_id.to_s(16)}>"
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)


50
51
52
53
54
55
56
57
58
# File 'lib/llm/transport/http.rb', line 50

def interrupt!(owner)
  req = request_for(owner) or return
  lock { (@interrupts ||= {})[owner] = true }
  close_socket(req.client)
  req.client.finish if req.client.active?
  owner.stop if owner.respond_to?(:stop)
rescue *interrupt_errors
  nil
end

#interrupt_errorsArray<Class<Exception>>

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:

  • (Array<Class<Exception>>)


42
43
44
# File 'lib/llm/transport/http.rb', line 42

def interrupt_errors
  [*INTERRUPT_ERRORS, *optional_interrupt_errors]
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)


64
65
66
# File 'lib/llm/transport/http.rb', line 64

def interrupted?(owner)
  lock { @interrupts&.delete(owner) }
end

#request(request, owner:, stream: nil) {|response| ... } ⇒ 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)
  • stream (LLM::Object, nil) (defaults to: nil)

Yield Parameters:

Returns:



75
76
77
78
79
80
81
# File 'lib/llm/transport/http.rb', line 75

def request(request, owner:, stream: nil, &b)
  client = client()
  set_request(Request.new(client:), owner)
  perform_request(client, request, stream, &b)
ensure
  clear_request(owner)
end

#request_ownerObject

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:



35
36
37
38
# File 'lib/llm/transport/http.rb', line 35

def request_owner
  return Fiber.current unless defined?(::Async)
  Async::Task.current? ? Async::Task.current : Fiber.current
end