Module: LangsmithrbRails::Wrappers::Base
- Defined in:
- lib/langsmithrb_rails/wrappers/base.rb
Overview
Base module for LLM provider wrappers
Class Method Summary collapse
-
.create_run(name, inputs, run_type: "llm", project_name: nil, tags: []) ⇒ Hash
Create a run for a provider operation.
-
.update_run(run_id, outputs, error: nil) ⇒ Hash
Update a run with outputs and end time.
-
.wrap(client, project_name: nil, tags: []) ⇒ Object
Wrap a provider client with LangSmith tracing.
Class Method Details
.create_run(name, inputs, run_type: "llm", project_name: nil, tags: []) ⇒ Hash
Create a run for a provider operation
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/langsmithrb_rails/wrappers/base.rb', line 24 def self.create_run(name, inputs, run_type: "llm", project_name: nil, tags: []) client = LangsmithrbRails::Client.new run_data = { name: name, inputs: inputs, run_type: run_type, start_time: Time.now.utc.iso8601, execution_order: 1, serialized: { name: name }, session_name: project_name, tags: } response = client.create_run(run_data) if response[:status] >= 200 && response[:status] < 300 response[:body] else LangsmithrbRails.logger.error("Failed to create run: #{response[:error] || response[:body]}") nil end end |
.update_run(run_id, outputs, error: nil) ⇒ Hash
Update a run with outputs and end time
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/langsmithrb_rails/wrappers/base.rb', line 53 def self.update_run(run_id, outputs, error: nil) return unless run_id client = LangsmithrbRails::Client.new run_data = { outputs: outputs, end_time: Time.now.utc.iso8601 } if error run_data[:error] = error run_data[:status] = "error" else run_data[:status] = "success" end response = client.update_run(run_id, run_data) if response[:status] >= 200 && response[:status] < 300 response[:body] else LangsmithrbRails.logger.error("Failed to update run: #{response[:error] || response[:body]}") nil end end |
.wrap(client, project_name: nil, tags: []) ⇒ Object
Wrap a provider client with LangSmith tracing
12 13 14 15 |
# File 'lib/langsmithrb_rails/wrappers/base.rb', line 12 def self.wrap(client, project_name: nil, tags: []) # To be implemented by specific provider wrappers raise NotImplementedError, "This method should be implemented by provider-specific wrappers" end |