Module: LangsmithrbRails
- Defined in:
- lib/langsmithrb_rails.rb,
lib/langsmithrb_rails/otel.rb,
lib/langsmithrb_rails/client.rb,
lib/langsmithrb_rails/config.rb,
lib/langsmithrb_rails/railtie.rb,
lib/langsmithrb_rails/version.rb,
lib/langsmithrb_rails/redactor.rb,
lib/langsmithrb_rails/wrappers.rb,
lib/langsmithrb_rails/langsmith.rb,
lib/langsmithrb_rails/run_trees.rb,
lib/langsmithrb_rails/evaluation.rb,
lib/langsmithrb_rails/wrappers/llm.rb,
lib/langsmithrb_rails/otel/exporter.rb,
lib/langsmithrb_rails/wrappers/base.rb,
lib/langsmithrb_rails/wrappers/openai.rb,
lib/langsmithrb_rails/wrappers/anthropic.rb,
lib/langsmithrb_rails/evaluation/evaluator.rb,
lib/langsmithrb_rails/evaluation/llm_evaluator.rb,
lib/generators/langsmithrb_rails/ci/ci_generator.rb,
lib/langsmithrb_rails/evaluation/string_evaluator.rb,
lib/generators/langsmithrb_rails/demo/demo_generator.rb,
lib/generators/langsmithrb_rails/evals/evals_generator.rb,
lib/generators/langsmithrb_rails/buffer/buffer_generator.rb,
lib/generators/langsmithrb_rails/install/install_generator.rb,
lib/generators/langsmithrb_rails/privacy/privacy_generator.rb,
lib/generators/langsmithrb_rails/tracing/tracing_generator.rb,
lib/generators/langsmithrb_rails/evals/templates/targets/http.rb,
lib/generators/langsmithrb_rails/evals/templates/targets/ruby.rb,
lib/generators/langsmithrb_rails/evals/templates/checks/llm_graded.rb,
lib/generators/langsmithrb_rails/privacy/templates/custom_redactor.rb,
lib/generators/langsmithrb_rails/tracing/templates/request_tracing.rb,
lib/generators/langsmithrb_rails/evals/templates/checks/correctness.rb,
lib/langsmithrb_rails/generators/langsmithrb_rails/langsmith_generator.rb
Overview
LangsmithRails provides integration with LangSmith for Rails applications
Defined Under Namespace
Modules: Evals, Evaluation, Generators, LangSmith, OTEL, Wrappers Classes: Client, Config, CustomRedactor, Railtie, Redactor, RequestTracing, RunContext, RunTree
Constant Summary collapse
- VERSION =
"0.3.0"
Class Method Summary collapse
-
.client ⇒ LangsmithrbRails::Client
Get a client instance.
-
.config ⇒ LangsmithrbRails::Config
Get the current configuration.
-
.configure {|config| ... } ⇒ LangsmithrbRails::Config
Configure LangsmithrbRails.
-
.create_evaluator(type, **options) ⇒ Evaluation::Evaluator
Alias for evaluator for better naming consistency.
-
.evaluator(type, **options) ⇒ Evaluation::Evaluator
Create an evaluator.
-
.init_otel(api_key: nil, api_url: nil, service_name: nil, service_version: nil) ⇒ Boolean
Initialize OpenTelemetry with LangSmith exporter.
-
.logger ⇒ Logger
Get the logger.
-
.run(name:, run_type:, inputs:, parent_run_id: nil, project_name: nil, tags: []) {|RunTree| ... } ⇒ Object
Create a run context for hierarchical tracing.
-
.trace(name, attributes: {}, kind: :internal) { ... } ⇒ Object
Create a trace span.
-
.trace_llm(name, inputs: {}, run_type: "llm", project_name: nil, tags: []) { ... } ⇒ Object
Create a trace span for LLM operations.
-
.traceable(object, method_name, run_name: nil, project_name: nil, tags: []) ⇒ Object
Create a traceable decorator for any method.
-
.wrap(client, provider:, project_name: nil, tags: []) ⇒ Object
Wrap an LLM provider client with LangSmith tracing.
Class Method Details
.client ⇒ LangsmithrbRails::Client
Get a client instance
103 104 105 |
# File 'lib/langsmithrb_rails.rb', line 103 def client @client ||= Client.new(api_key: config.api_key, api_url: config.api_url) end |
.config ⇒ LangsmithrbRails::Config
Get the current configuration
34 35 36 |
# File 'lib/langsmithrb_rails.rb', line 34 def config @config ||= Config.instance end |
.configure {|config| ... } ⇒ LangsmithrbRails::Config
Configure LangsmithrbRails
27 28 29 30 |
# File 'lib/langsmithrb_rails.rb', line 27 def configure yield config if block_given? config end |
.create_evaluator(type, **options) ⇒ Evaluation::Evaluator
Alias for evaluator for better naming consistency
97 98 99 |
# File 'lib/langsmithrb_rails.rb', line 97 def create_evaluator(type, **) Evaluation.create(type, **) end |
.evaluator(type, **options) ⇒ Evaluation::Evaluator
Create an evaluator
89 90 91 |
# File 'lib/langsmithrb_rails.rb', line 89 def evaluator(type, **) Evaluation.create(type, **) end |
.init_otel(api_key: nil, api_url: nil, service_name: nil, service_version: nil) ⇒ Boolean
Initialize OpenTelemetry with LangSmith exporter
113 114 115 116 117 118 119 120 |
# File 'lib/langsmithrb_rails.rb', line 113 def init_otel(api_key: nil, api_url: nil, service_name: nil, service_version: nil) OTEL.init( api_key: api_key || config.api_key, api_url: api_url || config.api_url, service_name: service_name || config.otel_service_name, service_version: service_version ) end |
.logger ⇒ Logger
Get the logger
40 41 42 |
# File 'lib/langsmithrb_rails.rb', line 40 def logger config.logger end |
.run(name:, run_type:, inputs:, parent_run_id: nil, project_name: nil, tags: []) {|RunTree| ... } ⇒ Object
Create a run context for hierarchical tracing
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/langsmithrb_rails.rb', line 74 def run(name:, run_type:, inputs:, parent_run_id: nil, project_name: nil, tags: [], &block) RunContext.run( name: name, run_type: run_type, inputs: inputs, project_name: project_name, tags: , &block ) end |
.trace(name, attributes: {}, kind: :internal) { ... } ⇒ Object
Create a trace span
128 129 130 |
# File 'lib/langsmithrb_rails.rb', line 128 def trace(name, attributes: {}, kind: :internal, &block) OTEL.trace(name, attributes: attributes, kind: kind, &block) end |
.trace_llm(name, inputs: {}, run_type: "llm", project_name: nil, tags: []) { ... } ⇒ Object
Create a trace span for LLM operations
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/langsmithrb_rails.rb', line 140 def trace_llm(name, inputs: {}, run_type: "llm", project_name: nil, tags: [], &block) OTEL.trace_llm( name, inputs: inputs, run_type: run_type, project_name: project_name || config.project_name, tags: , &block ) end |
.traceable(object, method_name, run_name: nil, project_name: nil, tags: []) ⇒ Object
Create a traceable decorator for any method
61 62 63 |
# File 'lib/langsmithrb_rails.rb', line 61 def traceable(object, method_name, run_name: nil, project_name: nil, tags: []) Wrappers.traceable(object, method_name, run_name: run_name, project_name: project_name, tags: ) end |
.wrap(client, provider:, project_name: nil, tags: []) ⇒ Object
Wrap an LLM provider client with LangSmith tracing
50 51 52 |
# File 'lib/langsmithrb_rails.rb', line 50 def wrap(client, provider:, project_name: nil, tags: []) Wrappers.wrap(client, provider: provider, project_name: project_name, tags: ) end |