Class: Langsmith::Configuration
- Inherits:
-
Object
- Object
- Langsmith::Configuration
- Defined in:
- lib/langsmith/configuration.rb
Overview
Configuration settings for the Langsmith SDK.
Instance Attribute Summary collapse
-
#api_key ⇒ String?
LangSmith API key (required for tracing).
-
#batch_size ⇒ Integer
Batch size for sending traces.
-
#endpoint ⇒ String
LangSmith API endpoint.
-
#flush_interval ⇒ Float
Flush interval in seconds.
-
#max_pending_entries ⇒ Integer?
Maximum buffered run entries (queue + pending); nil means unlimited.
-
#max_retries ⇒ Integer
Maximum retry attempts for failed requests.
-
#project ⇒ String
Project name for organizing traces.
-
#tenant_id ⇒ String?
Tenant ID for multi-tenant scenarios.
-
#timeout ⇒ Integer
Request timeout in seconds.
-
#tracing_enabled ⇒ Boolean
Enable/disable tracing.
Instance Method Summary collapse
-
#api_key_present? ⇒ Boolean
Returns whether an API key is configured.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#tracing_enabled? ⇒ Boolean
Returns whether tracing is enabled in configuration.
-
#tracing_possible? ⇒ Boolean
Returns whether tracing can actually occur (enabled AND has API key).
-
#validate! ⇒ void
Validates the configuration, raising an error if invalid.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/langsmith/configuration.rb', line 48 def initialize @api_key = ENV.fetch("LANGSMITH_API_KEY", nil) @endpoint = ENV.fetch("LANGSMITH_ENDPOINT", "https://api.smith.langchain.com") @project = ENV.fetch("LANGSMITH_PROJECT", "default") @tracing_enabled = env_boolean("LANGSMITH_TRACING", false) @batch_size = ENV.fetch("LANGSMITH_BATCH_SIZE", 100).to_i @flush_interval = ENV.fetch("LANGSMITH_FLUSH_INTERVAL", 1.0).to_f @timeout = ENV.fetch("LANGSMITH_TIMEOUT", 10).to_i @max_retries = ENV.fetch("LANGSMITH_MAX_RETRIES", 3).to_i @tenant_id = ENV.fetch("LANGSMITH_TENANT_ID", nil) @max_pending_entries = ENV.fetch("LANGSMITH_MAX_PENDING_ENTRIES", nil)&.to_i end |
Instance Attribute Details
#api_key ⇒ String?
Returns LangSmith API key (required for tracing).
19 20 21 |
# File 'lib/langsmith/configuration.rb', line 19 def api_key @api_key end |
#batch_size ⇒ Integer
Returns Batch size for sending traces.
31 32 33 |
# File 'lib/langsmith/configuration.rb', line 31 def batch_size @batch_size end |
#endpoint ⇒ String
Returns LangSmith API endpoint.
22 23 24 |
# File 'lib/langsmith/configuration.rb', line 22 def endpoint @endpoint end |
#flush_interval ⇒ Float
Returns Flush interval in seconds.
34 35 36 |
# File 'lib/langsmith/configuration.rb', line 34 def flush_interval @flush_interval end |
#max_pending_entries ⇒ Integer?
Returns Maximum buffered run entries (queue + pending); nil means unlimited.
46 47 48 |
# File 'lib/langsmith/configuration.rb', line 46 def max_pending_entries @max_pending_entries end |
#max_retries ⇒ Integer
Returns Maximum retry attempts for failed requests.
40 41 42 |
# File 'lib/langsmith/configuration.rb', line 40 def max_retries @max_retries end |
#project ⇒ String
Returns Project name for organizing traces.
25 26 27 |
# File 'lib/langsmith/configuration.rb', line 25 def project @project end |
#tenant_id ⇒ String?
Returns Tenant ID for multi-tenant scenarios.
43 44 45 |
# File 'lib/langsmith/configuration.rb', line 43 def tenant_id @tenant_id end |
#timeout ⇒ Integer
Returns Request timeout in seconds.
37 38 39 |
# File 'lib/langsmith/configuration.rb', line 37 def timeout @timeout end |
#tracing_enabled ⇒ Boolean
Returns Enable/disable tracing.
28 29 30 |
# File 'lib/langsmith/configuration.rb', line 28 def tracing_enabled @tracing_enabled end |
Instance Method Details
#api_key_present? ⇒ Boolean
Returns whether an API key is configured.
78 79 80 |
# File 'lib/langsmith/configuration.rb', line 78 def api_key_present? !@api_key.nil? && !@api_key.empty? end |
#tracing_enabled? ⇒ Boolean
Returns whether tracing is enabled in configuration. Note: This only checks the configuration flag, not whether tracing can actually occur.
65 66 67 |
# File 'lib/langsmith/configuration.rb', line 65 def tracing_enabled? @tracing_enabled end |
#tracing_possible? ⇒ Boolean
Returns whether tracing can actually occur (enabled AND has API key). Use this to check if traces will be sent.
72 73 74 |
# File 'lib/langsmith/configuration.rb', line 72 def tracing_possible? @tracing_enabled && api_key_present? end |
#validate! ⇒ void
This method returns an undefined value.
Validates the configuration, raising an error if invalid.
85 86 87 88 89 |
# File 'lib/langsmith/configuration.rb', line 85 def validate! return unless @tracing_enabled raise ConfigurationError, "LANGSMITH_API_KEY is required when tracing is enabled" unless api_key_present? end |