Class: Legion::Extensions::Llm::Vllm::Provider

Inherits:
Provider
  • Object
show all
Includes:
Provider::OpenAICompatible
Defined in:
lib/legion/extensions/llm/vllm/provider.rb

Overview

vLLM provider implementation for the Legion::Extensions::Llm base provider contract.

Defined Under Namespace

Modules: Capabilities

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.registry_publisherObject



23
24
25
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 23

def registry_publisher
  @registry_publisher ||= RegistryPublisher.new
end

Class Method Details

.capabilitiesObject



21
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 21

def capabilities = Capabilities

.configuration_optionsObject



19
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 19

def configuration_options = %i[vllm_api_base vllm_api_key]

.configuration_requirementsObject



20
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 20

def configuration_requirements = []

.local?Boolean

Returns:

  • (Boolean)


18
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 18

def local? = true

.slugObject



17
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 17

def slug = 'vllm'

Instance Method Details

#api_baseObject



50
51
52
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 50

def api_base
  config.vllm_api_base || 'http://localhost:8000'
end

#headersObject



54
55
56
57
58
59
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 54

def headers
  token = config.vllm_api_key
  return {} if token.nil? || token.to_s.empty?

  { 'Authorization' => "Bearer #{token}" }
end

#healthObject



68
69
70
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 68

def health
  connection.get(health_url).body
end

#health_urlObject



61
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 61

def health_url = '/health'

#list_modelsObject



78
79
80
81
82
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 78

def list_models
  super.tap do |models|
    self.class.registry_publisher.publish_models_async(models, readiness: readiness(live: false))
  end
end

#readiness(live: false) ⇒ Object



72
73
74
75
76
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 72

def readiness(live: false)
  super.tap do ||
    self.class.registry_publisher.publish_readiness_async() if live
  end
end

#reset_mm_cacheObject



92
93
94
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 92

def reset_mm_cache
  connection.post(reset_mm_cache_url, {}).body
end

#reset_mm_cache_urlObject



64
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 64

def reset_mm_cache_url = '/reset_mm_cache'

#reset_prefix_cache(reset_running_requests: nil, reset_external: nil) ⇒ Object



88
89
90
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 88

def reset_prefix_cache(reset_running_requests: nil, reset_external: nil)
  connection.post(with_query(reset_prefix_cache_url, reset_running_requests:, reset_external:), {}).body
end

#reset_prefix_cache_urlObject



63
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 63

def reset_prefix_cache_url = '/reset_prefix_cache'

#sleep(level: 1) ⇒ Object



96
97
98
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 96

def sleep(level: 1)
  connection.post(with_query(sleep_url, level:), {}).body
end

#sleep_urlObject



65
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 65

def sleep_url = '/sleep'

#stream_usage_supported?Boolean

Returns:

  • (Boolean)


48
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 48

def stream_usage_supported? = true

#versionObject



84
85
86
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 84

def version
  connection.get(version_url).body
end

#version_urlObject



62
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 62

def version_url = '/version'

#wake_up(tags: nil) ⇒ Object



100
101
102
103
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 100

def wake_up(tags: nil)
  query = Array(tags).map { |tag| ['tags', tag] }
  connection.post(with_query(wake_up_url, query), {}).body
end

#wake_up_urlObject



66
# File 'lib/legion/extensions/llm/vllm/provider.rb', line 66

def wake_up_url = '/wake_up'