Class: Relay::Routes::Websocket::Stream

Inherits:
LLM::Stream
  • Object
show all
Defined in:
app/routes/websocket/stream.rb

Instance Method Summary collapse

Constructor Details

#initialize(conn, sock) ⇒ Stream

Returns a new instance of Stream.

Parameters:

  • conn (Async::WebSocket::Adapters::Rack)

    The WebSocket connection object

  • sock (Relay::Routes::Websocket)

    The websocket route object



10
11
12
13
# File 'app/routes/websocket/stream.rb', line 10

def initialize(conn, sock)
  @conn = conn
  @sock = sock
end

Instance Method Details

#on_compaction(ctx, compactor) ⇒ void

This method returns an undefined value.

Reports compaction start in the chat status bar.



35
36
37
# File 'app/routes/websocket/stream.rb', line 35

def on_compaction(ctx, compactor)
  @sock.write(@conn, @sock.fragment(:status, @sock.status_bar(status: "Compacting...", ctx:)))
end

#on_compaction_finish(ctx, compactor) ⇒ void

This method returns an undefined value.

Reports compaction completion with refreshed usage details.



42
43
44
# File 'app/routes/websocket/stream.rb', line 42

def on_compaction_finish(ctx, compactor)
  @sock.write(@conn, @sock.fragment(:status, @sock.status_bar(status: "Compaction finished", ctx:)))
end

#on_content(chunk) ⇒ void

This method returns an undefined value.

Writes a streamed text chunk

Parameters:

  • chunk (String)

    The streamed text chunk



20
21
22
# File 'app/routes/websocket/stream.rb', line 20

def on_content(chunk)
  @sock.stream(@conn, chunk.to_s)
end

#on_tool_call(tool, error) ⇒ void

This method returns an undefined value.

On tool call



27
28
29
30
# File 'app/routes/websocket/stream.rb', line 27

def on_tool_call(tool, error)
  @sock.report_tool_status(@conn, tool)
  queue << (error || tool.spawn(:task))
end