Class: Ollama::Plugins

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama/plugins.rb

Overview

Plugin system for the Ollama client. Allows registering plugins that can add middleware, configure defaults, etc.

Instance Method Summary collapse

Constructor Details

#initializePlugins

Returns a new instance of Plugins.



8
9
10
# File 'lib/ollama/plugins.rb', line 8

def initialize
  @plugins = []
end

Instance Method Details

#apply_all(client) ⇒ Ollama::Plugins

Apply all registered plugins to a client

Parameters:

Returns:



24
25
26
27
28
29
30
31
# File 'lib/ollama/plugins.rb', line 24

def apply_all(client)
  @plugins.each do |p|
    plugin = p[:plugin]
    config = p[:config]
    plugin.apply(client, config) if plugin.respond_to?(:apply)
  end
  self
end

#apply_plugin?(plugin, client, config = {}) ⇒ Boolean

Apply a specific plugin to a client

Parameters:

  • plugin (Module, Class)

    Plugin to apply

  • client (Ollama::Client)

    Client instance

  • config (Hash) (defaults to: {})

    Configuration

Returns:

  • (Boolean)

    True if plugin was found and applied



38
39
40
41
42
43
44
# File 'lib/ollama/plugins.rb', line 38

def apply_plugin?(plugin, client, config = {})
  entry = @plugins.find { |p| p[:plugin] == plugin }
  return false unless entry

  plugin.apply(client, config) if plugin.respond_to?(:apply)
  true
end

#listArray<Module, Class>

List registered plugins

Returns:

  • (Array<Module, Class>)

    List of plugin classes/modules



48
49
50
# File 'lib/ollama/plugins.rb', line 48

def list
  @plugins.map { |p| p[:plugin] }
end

#register(plugin, config: {}) ⇒ Ollama::Plugins

Register a plugin

Parameters:

  • plugin (Module, Class)

    Plugin module/class

  • config (Hash) (defaults to: {})

    Configuration for the plugin

Returns:



16
17
18
19
# File 'lib/ollama/plugins.rb', line 16

def register(plugin, config: {})
  @plugins << { plugin: plugin, config: config }
  self
end

#registered?(plugin) ⇒ Boolean

Check if a plugin is registered

Parameters:

  • plugin (Module, Class)

    Plugin to check

Returns:

  • (Boolean)


55
56
57
# File 'lib/ollama/plugins.rb', line 55

def registered?(plugin)
  @plugins.any? { |p| p[:plugin] == plugin }
end