Class: RubyLLM::Protocols::GPUStack::Responses

Inherits:
Protocols::Responses
  • Object
show all
Defined in:
lib/ruby_llm/protocols/gpustack/responses.rb

Overview

vLLM Responses with MCP servers configured on the deployment.

Constant Summary collapse

MCP_LABELS =
%w[web_search_preview code_interpreter container].freeze
MCP_ALIASES =
{
  web_search: ['web_search_preview', ['search']],
  web_fetch: ['web_search_preview', ['open']],
  code_execution: ['code_interpreter', nil]
}.freeze
SERVER_TOOL_ALIASES =
MCP_ALIASES.transform_values do |label, tools|
  ->(options) { render_mcp_alias(options, label:, tools:) }
end.merge(mcp: Protocols::Responses::SERVER_TOOL_ALIASES.fetch(:mcp)).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.render_mcp_alias(options, label:, tools:) ⇒ Object

:nodoc:



18
19
20
21
22
23
24
25
26
27
# File 'lib/ruby_llm/protocols/gpustack/responses.rb', line 18

def self.render_mcp_alias(options, label:, tools:) # :nodoc:
  options = Support::Utils.deep_symbolize_keys(options)
  unless (options.keys - [:require_approval]).empty?
    raise ArgumentError, 'GPUStack server tool aliases accept only require_approval; use mcp for custom filters'
  end

  tool = { type: 'mcp', server_label: label, **options }
  tool[:allowed_tools] = tools.dup if tools
  { tool: }
end

Instance Method Details

#format_assistant_items(message) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/ruby_llm/protocols/gpustack/responses.rb', line 43

def format_assistant_items(message)
  super.flat_map do |item|
    data = Support::Utils.deep_symbolize_keys(item)
    next item unless data[:type] && !Protocols::Responses::Chat::CLIENT_OUTPUT_ITEM_TYPES.include?(data[:type])

    format_server_tool_history(data)
  end
end

#merge_server_tool_entries(payload, entries) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/ruby_llm/protocols/gpustack/responses.rb', line 33

def merge_server_tool_entries(payload, entries)
  tools = entries.map { |entry| Support::Utils.deep_symbolize_keys(entry) }
  tools.each do |tool|
    next unless tool[:type] == 'mcp'

    validate_mcp_tool(tool)
  end
  super(payload, merge_mcp_filters(tools))
end

#parse_reasoning_summary(output) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/ruby_llm/protocols/gpustack/responses.rb', line 52

def parse_reasoning_summary(output)
  summary = super
  return summary unless summary.to_s.empty?

  text = output.select { |item| item['type'] == 'reasoning' }.flat_map { |item| item['content'] || [] }
               .filter_map { |part| part['text'] }.join
  text unless text.empty?
end

#server_tool_aliasesObject



29
30
31
# File 'lib/ruby_llm/protocols/gpustack/responses.rb', line 29

def server_tool_aliases
  SERVER_TOOL_ALIASES
end