Class: LLM::Transport
- Inherits:
-
Object
- Object
- LLM::Transport
- Defined in:
- lib/llm/transport.rb,
lib/llm/transport/http.rb,
lib/llm/transport/utils.rb,
lib/llm/transport/response.rb,
lib/llm/transport/execution.rb,
lib/llm/transport/stream_decoder.rb,
lib/llm/transport/persistent_http.rb
Overview
The LLM::Transport class defines the execution interface used by Provider.
Custom transports can subclass this class and override #request to execute provider requests without changing request adapters or response adapters.
Providers currently construct Net::HTTPRequest objects before delegating to a transport. Custom transports are therefore expected to execute those requests directly, or transform them into backend-specific request objects before execution.
Only #request is required. The remaining methods are optional hooks for features such as interruption, request ownership, or persistence, and only need to be implemented when the underlying adapter can support them.
Returned responses should implement the LLM::Transport::Response interface. In practice this can mean adapting another client's response object so existing provider execution, response adapters, and error handlers can rely on one normalized response contract instead of transport-specific classes.
Direct Known Subclasses
Defined Under Namespace
Modules: Execution, Utils Classes: HTTP, PersistentHTTP, Response, StreamDecoder
Class Method Summary collapse
-
.net_http_persistent ⇒ Class
Returns the built-in Net::HTTP::Persistent transport class.
-
.net_http ⇒ Class
Returns the built-in Net::HTTP transport class.
Instance Method Summary collapse
- #set_body_stream(request, io) ⇒ void
-
#request(request, owner:, stream: nil) {|response| ... } ⇒ Object
Performs a request through the transport.
-
#request_owner ⇒ Object
Returns the current request owner.
-
#interrupt_errors ⇒ Array<Class<Exception>>
Returns the exception classes that indicate an interrupted request.
-
#interrupt!(owner) ⇒ nil
Interrupt an active request, if any.
-
#interrupted?(owner) ⇒ Boolean?
Returns whether an execution owner was interrupted.
Class Method Details
.net_http_persistent ⇒ Class
Returns the built-in Net::HTTP::Persistent transport class.
46 47 48 |
# File 'lib/llm/transport.rb', line 46 def self.net_http_persistent PersistentHTTP end |
.net_http ⇒ Class
Returns the built-in Net::HTTP transport class.
39 40 41 |
# File 'lib/llm/transport.rb', line 39 def self.net_http HTTP end |
Instance Method Details
#set_body_stream(request, io) ⇒ void
Custom transports may be able to reuse this helper when they operate on Net::HTTPRequest objects, or implement their own request body preparation path instead.
This method returns an undefined value.
100 101 102 103 |
# File 'lib/llm/transport.rb', line 100 def set_body_stream(request, io) request.body_stream = io request["transfer-encoding"] = "chunked" unless request["content-length"] end |
#request(request, owner:, stream: nil) {|response| ... } ⇒ Object
Performs a request through the transport.
57 58 59 |
# File 'lib/llm/transport.rb', line 57 def request(request, owner:, stream: nil, &) raise NotImplementedError end |
#request_owner ⇒ Object
Returns the current request owner.
64 65 66 67 |
# File 'lib/llm/transport.rb', line 64 def request_owner return Fiber.current unless defined?(::Async) Async::Task.current? ? Async::Task.current : Fiber.current end |
#interrupt_errors ⇒ Array<Class<Exception>>
Returns the exception classes that indicate an interrupted request.
72 73 74 |
# File 'lib/llm/transport.rb', line 72 def interrupt_errors [] end |
#interrupt!(owner) ⇒ nil
Interrupt an active request, if any.
80 81 82 |
# File 'lib/llm/transport.rb', line 80 def interrupt!(owner) raise NotImplementedError end |
#interrupted?(owner) ⇒ Boolean?
Returns whether an execution owner was interrupted.
88 89 90 |
# File 'lib/llm/transport.rb', line 88 def interrupted?(owner) nil end |