Module: Langsmith
- Defined in:
- lib/langsmith.rb,
lib/langsmith/run.rb,
lib/langsmith/client.rb,
lib/langsmith/errors.rb,
lib/langsmith/context.rb,
lib/langsmith/railtie.rb,
lib/langsmith/version.rb,
lib/langsmith/run_tree.rb,
lib/langsmith/evaluation.rb,
lib/langsmith/configuration.rb,
lib/langsmith/batch_processor.rb,
lib/langsmith/evaluation/experiment_runner.rb
Defined Under Namespace
Modules: Context, Evaluation Classes: BatchProcessor, Client, Configuration, ConfigurationError, Error, Railtie, Run, RunTree, TracingError
Constant Summary collapse
- VERSION =
"0.4.0"
Class Method Summary collapse
-
.batch_processor ⇒ BatchProcessor
Returns the batch processor (lazily initialized).
-
.client ⇒ Client
Returns the HTTP client (lazily initialized).
-
.configuration ⇒ Configuration
Returns the current configuration.
-
.configure {|Configuration| ... } ⇒ void
Configure Langsmith with a block.
-
.current_run ⇒ Run?
Get the current run from context (if any).
-
.flush ⇒ void
Flush all pending traces (blocking).
-
.reset_configuration! ⇒ void
Reset configuration (useful for testing).
-
.shutdown ⇒ void
Shutdown the batch processor gracefully.
-
.trace(name, run_type: "chain", inputs: nil, metadata: nil, tags: nil, extra: nil, tenant_id: nil, project: nil) {|Run| ... } ⇒ Object
Main tracing API - execute a block within a traced context.
-
.tracing? ⇒ Boolean
Check if we're currently inside a trace.
-
.tracing_enabled? ⇒ Boolean
Check if tracing is enabled and possible (has API key).
Class Method Details
.batch_processor ⇒ BatchProcessor
Returns the batch processor (lazily initialized).
53 54 55 |
# File 'lib/langsmith.rb', line 53 def batch_processor @batch_processor ||= BatchProcessor.new end |
.client ⇒ Client
Returns the HTTP client (lazily initialized).
59 60 61 |
# File 'lib/langsmith.rb', line 59 def client @client ||= Client.new end |
.configuration ⇒ Configuration
Returns the current configuration.
17 18 19 |
# File 'lib/langsmith.rb', line 17 def configuration @configuration ||= Configuration.new end |
.configure {|Configuration| ... } ⇒ void
This method returns an undefined value.
Configure Langsmith with a block.
32 33 34 35 |
# File 'lib/langsmith.rb', line 32 def configure yield(configuration) configuration.validate! end |
.current_run ⇒ Run?
Get the current run from context (if any).
131 132 133 |
# File 'lib/langsmith.rb', line 131 def current_run Context.current_run end |
.flush ⇒ void
This method returns an undefined value.
Flush all pending traces (blocking). Useful before application shutdown or in tests.
119 120 121 |
# File 'lib/langsmith.rb', line 119 def flush batch_processor.flush end |
.reset_configuration! ⇒ void
This method returns an undefined value.
Reset configuration (useful for testing).
39 40 41 42 43 |
# File 'lib/langsmith.rb', line 39 def reset_configuration! @configuration = Configuration.new @batch_processor = nil @client = nil end |
.shutdown ⇒ void
This method returns an undefined value.
Shutdown the batch processor gracefully.
125 126 127 |
# File 'lib/langsmith.rb', line 125 def shutdown batch_processor.shutdown end |
.trace(name, run_type: "chain", inputs: nil, metadata: nil, tags: nil, extra: nil, tenant_id: nil, project: nil) {|Run| ... } ⇒ Object
Main tracing API - execute a block within a traced context.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/langsmith.rb', line 100 def trace(name, run_type: "chain", inputs: nil, metadata: nil, tags: nil, extra: nil, tenant_id: nil, project: nil, &block) run_tree = RunTree.new( name: name, run_type: run_type, inputs: inputs, metadata: , tags: , extra: extra, tenant_id: tenant_id, project: project ) run_tree.execute(&block) end |
.tracing? ⇒ Boolean
Check if we're currently inside a trace.
137 138 139 |
# File 'lib/langsmith.rb', line 137 def tracing? Context.active? end |
.tracing_enabled? ⇒ Boolean
Check if tracing is enabled and possible (has API key).
47 48 49 |
# File 'lib/langsmith.rb', line 47 def tracing_enabled? configuration.tracing_possible? end |