Module: PromptCanary

Extended by:
Deployment
Defined in:
lib/prompt_canary.rb,
lib/prompt_canary.rb,
lib/prompt_canary/cli.rb,
lib/prompt_canary/engine.rb,
lib/prompt_canary/prompt.rb,
lib/prompt_canary/result.rb,
lib/prompt_canary/router.rb,
lib/prompt_canary/monitor.rb,
lib/prompt_canary/railtie.rb,
lib/prompt_canary/version.rb,
lib/prompt_canary/recorder.rb,
lib/prompt_canary/deployment.rb,
lib/prompt_canary/promptable.rb,
lib/prompt_canary/monitor_job.rb,
lib/prompt_canary/adapters/base.rb,
lib/prompt_canary/configuration.rb,
lib/prompt_canary/rollback_rule.rb,
lib/prompt_canary/storage/memory.rb,
lib/prompt_canary/storage/sqlite.rb,
lib/prompt_canary/version_object.rb,
lib/prompt_canary/adapter_factory.rb,
lib/prompt_canary/prompt_executor.rb,
lib/prompt_canary/storage_factory.rb,
lib/prompt_canary/version_builder.rb,
lib/prompt_canary/adapters/anthropic.rb,
lib/prompt_canary/cli/commands/status.rb,
lib/prompt_canary/cli/commands/history.rb,
lib/generators/prompt_canary/install_generator.rb,
lib/prompt_canary/storage/active_record_adapter.rb,
app/controllers/prompt_canary/application_controller.rb,
app/controllers/prompt_canary/dashboard/prompts_controller.rb

Defined Under Namespace

Modules: Adapters, Dashboard, Deployment, Generators, Promptable, Storage Classes: AdapterFactory, ApplicationController, CLI, Call, CannotDemotePrimaryError, Configuration, ConfigurationError, DemotedVersionError, DuplicateVersionError, Engine, Error, Monitor, MonitorJob, NoPrimaryVersionError, PrimaryOverride, Prompt, PromptEvent, PromptExecutor, Railtie, Recorder, Result, RollbackRule, RolloutOverride, Router, StorageFactory, UnknownVersionError, Version, VersionBuilder

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Methods included from Deployment

demote, promote, restore, set_canary

Class Method Details

.check_storage_config!(logger) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/prompt_canary.rb', line 47

def check_storage_config!(logger)
  return unless configuration.storage == :sqlite

  logger.warn(
    "[PromptCanary] storage: :sqlite is not recommended for multi-process Rails deployments. " \
    "Run `rails generate prompt_canary:install && rails db:migrate` " \
    "and set `storage: :active_record`."
  )
end

.configurationObject



24
25
26
# File 'lib/prompt_canary.rb', line 24

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



19
20
21
22
# File 'lib/prompt_canary.rb', line 19

def configure
  yield configuration
  configuration.validate!
end

.load_prompt_classes(path, loader: method(:require)) ⇒ Object



41
42
43
44
45
# File 'lib/prompt_canary.rb', line 41

def load_prompt_classes(path, loader: method(:require))
  return unless File.directory?(path)

  Dir[File.join(path, "**", "*.rb")].sort.each { |f| loader.call(f) }
end

.register_prompt(klass) ⇒ Object



28
29
30
# File 'lib/prompt_canary.rb', line 28

def register_prompt(klass)
  registered_prompts << klass
end

.registered_promptsObject



32
33
34
# File 'lib/prompt_canary.rb', line 32

def registered_prompts
  @registered_prompts ||= []
end

.reset_configuration!Object



36
37
38
39
# File 'lib/prompt_canary.rb', line 36

def reset_configuration!
  @configuration = nil
  @registered_prompts = nil
end

.reset_subscribers!Object



66
67
68
# File 'lib/prompt_canary.rb', line 66

def reset_subscribers!
  @subscribers = nil
end

.stats(prompt_class, version_name, over: 100) ⇒ Object



57
58
59
60
# File 'lib/prompt_canary.rb', line 57

def stats(prompt_class, version_name, over: 100)
  recorder = Recorder.new(storage: StorageFactory.build(configuration.storage))
  recorder.stats(prompt: prompt_class.name, version: version_name, over: over)
end

.subscribe(event, &block) ⇒ Object



62
63
64
# File 'lib/prompt_canary.rb', line 62

def subscribe(event, &block)
  subscribers[event] << block
end