Module: DSPy

Extended by:
Dry::Configurable
Defined in:
lib/dspy.rb,
lib/dspy/lm.rb,
lib/dspy/field.rb,
lib/dspy/tools.rb,
lib/dspy/memory.rb,
lib/dspy/module.rb,
lib/dspy/prompt.rb,
lib/dspy/re_act.rb,
lib/dspy/example.rb,
lib/dspy/predict.rb,
lib/dspy/version.rb,
lib/dspy/code_act.rb,
lib/dspy/evaluate.rb,
lib/dspy/lm/errors.rb,
lib/dspy/signature.rb,
lib/dspy/lm/adapter.rb,
lib/dspy/tools/base.rb,
lib/dspy/lm/response.rb,
lib/dspy/tools/toolset.rb,
lib/dspy/instrumentation.rb,
lib/dspy/schema_adapters.rb,
lib/dspy/chain_of_thought.rb,
lib/dspy/few_shot_example.rb,
lib/dspy/teleprompt/utils.rb,
lib/dspy/lm/adapter_factory.rb,
lib/dspy/memory/memory_store.rb,
lib/dspy/teleprompt/mipro_v2.rb,
lib/dspy/memory/memory_record.rb,
lib/dspy/mixins/type_coercion.rb,
lib/dspy/tools/memory_toolset.rb,
lib/dspy/memory/memory_manager.rb,
lib/dspy/mixins/struct_builder.rb,
lib/dspy/memory/in_memory_store.rb,
lib/dspy/memory/embedding_engine.rb,
lib/dspy/memory/memory_compactor.rb,
lib/dspy/storage/program_storage.rb,
lib/dspy/storage/storage_manager.rb,
lib/dspy/teleprompt/data_handler.rb,
lib/dspy/teleprompt/teleprompter.rb,
lib/dspy/propose/grounded_proposer.rb,
lib/dspy/registry/registry_manager.rb,
lib/dspy/lm/adapters/openai_adapter.rb,
lib/dspy/registry/signature_registry.rb,
lib/dspy/subscribers/otel_subscriber.rb,
lib/dspy/teleprompt/simple_optimizer.rb,
lib/dspy/instrumentation/token_tracker.rb,
lib/dspy/lm/adapters/anthropic_adapter.rb,
lib/dspy/memory/local_embedding_engine.rb,
lib/dspy/subscribers/logger_subscriber.rb,
lib/dspy/tools/text_processing_toolset.rb,
lib/dspy/mixins/instrumentation_helpers.rb,
lib/dspy/subscribers/langfuse_subscriber.rb,
lib/dspy/subscribers/newrelic_subscriber.rb

Defined Under Namespace

Modules: Instrumentation, Memory, Metrics, Mixins, Propose, Registry, SchemaAdapters, Storage, Subscribers, Teleprompt, Tools Classes: ChainOfThought, CodeAct, CodeActHistoryEntry, CodeActNextStep, Evaluate, Example, FewShotExample, HistoryEntry, InputField, LM, Module, NextStep, OutputField, Predict, PredictionInvalidError, Prompt, ReAct, ReActObservation, RubyCodeGeneration, RubyCodeObservation, Signature, Thought, TimestampFormat

Constant Summary collapse

VERSION =
"0.6.2"

Class Method Summary collapse

Class Method Details

.loggerObject



80
81
82
# File 'lib/dspy.rb', line 80

def self.logger
  config.logger
end

.validate_instrumentation!Object

Validation methods for instrumentation configuration

Raises:

  • (ArgumentError)


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/dspy.rb', line 85

def self.validate_instrumentation!
  config = self.config.instrumentation
  
  raise ArgumentError, "Sampling rate must be between 0.0 and 1.0" unless config.sampling_rate.between?(0.0, 1.0)
  raise ArgumentError, "Buffer size must be positive" unless config.buffer_size > 0
  raise ArgumentError, "Flush interval must be positive" unless config.flush_interval > 0
  raise ArgumentError, "Invalid timestamp format" unless config.timestamp_format.is_a?(TimestampFormat)
  
  if config.enabled && config.subscribers.empty?
    raise ArgumentError, "Must specify at least one subscriber when instrumentation is enabled"
  end
  
  # Validate subscribers are valid symbols
  invalid_subscribers = config.subscribers - [:logger, :otel, :newrelic, :langfuse]
  unless invalid_subscribers.empty?
    raise ArgumentError, "Invalid subscribers: #{invalid_subscribers.join(', ')}"
  end
end