Class: Langsmith::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/langsmith/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, api_url: nil) ⇒ Client

Initialize a new LangSmith client

Parameters:

  • api_key (String) (defaults to: nil)

    LangSmith API key

  • api_url (String) (defaults to: nil)

    LangSmith API URL

Raises:



14
15
16
17
18
19
# File 'lib/langsmith/client.rb', line 14

def initialize(api_key: nil, api_url: nil)
  @api_key = api_key || ENV["LANGSMITH_API_KEY"] || Langsmith.api_key
  @api_url = api_url || ENV["LANGSMITH_API_URL"] || Langsmith.api_url || Langsmith::DEFAULT_API_URL
  
  raise Langsmith::Errors::AuthenticationError, "API key is required" unless @api_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



8
9
10
# File 'lib/langsmith/client.rb', line 8

def api_key
  @api_key
end

#api_urlObject (readonly)

Returns the value of attribute api_url.



8
9
10
# File 'lib/langsmith/client.rb', line 8

def api_url
  @api_url
end

Instance Method Details

#bulk_delete_runs(run_ids:) ⇒ Hash

Bulk delete runs

Parameters:

  • run_ids (Array<String>)

    List of run IDs to delete

Returns:

  • (Hash)

    Result of the bulk operation



854
855
856
857
858
859
860
# File 'lib/langsmith/client.rb', line 854

def bulk_delete_runs(run_ids:)
  data = {
    run_ids: run_ids
  }
  
  post("/runs/bulk/delete", data)
end

#bulk_tag_runs(run_ids:, tag_ids:) ⇒ Hash

Bulk tag runs

Parameters:

  • run_ids (Array<String>)

    List of run IDs to tag

  • tag_ids (Array<String>)

    List of tag IDs to apply

Returns:

  • (Hash)

    Result of the bulk operation



827
828
829
830
831
832
833
834
# File 'lib/langsmith/client.rb', line 827

def bulk_tag_runs(run_ids:, tag_ids:)
  data = {
    run_ids: run_ids,
    tag_ids: tag_ids
  }
  
  post("/runs/bulk/tag", data)
end

#bulk_untag_runs(run_ids:, tag_ids:) ⇒ Hash

Bulk untag runs

Parameters:

  • run_ids (Array<String>)

    List of run IDs to untag

  • tag_ids (Array<String>)

    List of tag IDs to remove

Returns:

  • (Hash)

    Result of the bulk operation



841
842
843
844
845
846
847
848
# File 'lib/langsmith/client.rb', line 841

def bulk_untag_runs(run_ids:, tag_ids:)
  data = {
    run_ids: run_ids,
    tag_ids: tag_ids
  }
  
  post("/runs/bulk/untag", data)
end

#cancel_evaluation(id:) ⇒ Langsmith::Evaluation

Cancel an evaluation

Parameters:

  • id (String)

    ID of the evaluation to cancel

Returns:



292
293
294
295
# File 'lib/langsmith/client.rb', line 292

def cancel_evaluation(id:)
  response = post("/evaluations/#{id}/cancel")
  Langsmith::Evaluation.new(self, response)
end

#create_annotation_queue(name:, description: nil, metadata: {}) ⇒ Hash

Create a new annotation queue

Parameters:

  • name (String)

    Name of the annotation queue

  • description (String) (defaults to: nil)

    Description of the annotation queue

  • metadata (Hash) (defaults to: {})

    Additional metadata for the annotation queue

Returns:

  • (Hash)

    The created annotation queue data



564
565
566
567
568
569
570
571
# File 'lib/langsmith/client.rb', line 564

def create_annotation_queue(name:, description: nil, metadata: {})
  data = {
    name: name,
    metadata: 
  }
  data[:description] = description if description
  post("/annotation-queues", data)
end

#create_api_key(name:, expires_at: nil) ⇒ Hash

Create a new API key

Parameters:

  • name (String)

    Name of the API key

  • expires_at (Time, nil) (defaults to: nil)

    Expiration time for the API key (optional)

Returns:

  • (Hash)

    The created API key data



403
404
405
406
407
# File 'lib/langsmith/client.rb', line 403

def create_api_key(name:, expires_at: nil)
  data = { name: name }
  data[:expires_at] = expires_at.iso8601 if expires_at
  post("/api-key", data)
end

#create_dataset(name:, description: nil) ⇒ Langsmith::Dataset

Create a new dataset

Parameters:

  • name (String)

    Name of the dataset

  • description (String) (defaults to: nil)

    Description of the dataset

Returns:



121
122
123
124
125
126
127
# File 'lib/langsmith/client.rb', line 121

def create_dataset(name:, description: nil)
  data = { name: name }
  data[:description] = description if description

  response = post("/datasets", data)
  Langsmith::Dataset.new(self, response)
end

#create_event(name:, data:, metadata: nil) ⇒ Hash

Create an event

Parameters:

  • name (String)

    Event name

  • data (Hash)

    Event data

  • metadata (Hash, nil) (defaults to: nil)

    Additional metadata for the event (optional)

Returns:

  • (Hash)

    The created event data



777
778
779
780
781
782
783
784
785
# File 'lib/langsmith/client.rb', line 777

def create_event(name:, data:, metadata: nil)
  event_data = {
    name: name,
    data: data
  }
  event_data[:metadata] =  if 
  
  post("/events", event_data)
end

#create_examples_batch(dataset_id:, examples:) ⇒ Array<Langsmith::Example>

Create multiple examples in batch

Parameters:

  • dataset_id (String)

    ID of the dataset to add examples to

  • examples (Array<Hash>)

    Array of example data, each containing :inputs and optionally :outputs and :metadata

Returns:



230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/langsmith/client.rb', line 230

def create_examples_batch(dataset_id:, examples:)
  data = examples.map do |example|
    example_data = {
      dataset_id: dataset_id,
      inputs: example[:inputs]
    }
    example_data[:outputs] = example[:outputs] if example[:outputs]
    example_data[:metadata] = example[:metadata] if example[:metadata]
    example_data
  end
  
  response = post("/examples/batch", { examples: data })
  response.map { |example_data| Langsmith::Example.new(self, example_data) }
end

#create_feedback(run_id:, key:, score:, comment: nil) ⇒ Langsmith::Feedback

Create feedback for a run

Parameters:

  • run_id (String)

    ID of the run to provide feedback for

  • key (String)

    Feedback key (e.g., “correctness”, “helpfulness”)

  • score (Float)

    Feedback score (typically 0.0 to 1.0)

  • comment (String) (defaults to: nil)

    Optional comment with the feedback

Returns:



313
314
315
316
317
318
319
320
321
322
323
# File 'lib/langsmith/client.rb', line 313

def create_feedback(run_id:, key:, score:, comment: nil)
  data = {
    run_id: run_id,
    key: key,
    score: score
  }
  data[:comment] = comment if comment

  response = post("/feedback", data)
  Langsmith::Feedback.new(self, response)
end

#create_feedback_config(name:, type:, metadata: {}) ⇒ Hash

Create a new feedback config

Parameters:

  • name (String)

    Name of the feedback config

  • type (String)

    Type of feedback config

  • metadata (Hash) (defaults to: {})

    Additional metadata for the feedback config

Returns:

  • (Hash)

    The created feedback config data



624
625
626
627
628
629
630
631
# File 'lib/langsmith/client.rb', line 624

def create_feedback_config(name:, type:, metadata: {})
  data = {
    name: name,
    type: type,
    metadata: 
  }
  post("/feedback-configs", data)
end

#create_project(name:, description: nil) ⇒ Langsmith::Project

Create a new project

Parameters:

  • name (String)

    Name of the project

  • description (String) (defaults to: nil)

    Description of the project

Returns:



89
90
91
92
93
94
95
# File 'lib/langsmith/client.rb', line 89

def create_project(name:, description: nil)
  data = { name: name }
  data[:description] = description if description

  response = post("/projects", data)
  Langsmith::Project.new(self, response)
end

#create_prompt(name:, prompt_template:, metadata: {}) ⇒ Hash

Create a new prompt

Parameters:

  • name (String)

    Name of the prompt

  • prompt_template (String)

    The prompt template

  • metadata (Hash) (defaults to: {})

    Additional metadata for the prompt

Returns:

  • (Hash)

    The created prompt data



504
505
506
507
508
509
510
511
# File 'lib/langsmith/client.rb', line 504

def create_prompt(name:, prompt_template:, metadata: {})
  data = {
    name: name,
    prompt_template: prompt_template,
    metadata: 
  }
  post("/prompts", data)
end

#create_run(name:, run_type:, project_name: nil, inputs: {}, extra: {}) ⇒ Langsmith::Run

Create a new run

Parameters:

  • name (String)

    Name of the run

  • run_type (String)

    Type of run (e.g., llm, chain, tool)

  • project_name (String) (defaults to: nil)

    Name of the project

  • inputs (Hash) (defaults to: {})

    Input values for the run

  • extra (Hash) (defaults to: {})

    Additional metadata for the run

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/langsmith/client.rb', line 29

def create_run(name:, run_type:, project_name: nil, inputs: {}, extra: {})
  data = {
    name: name,
    run_type: run_type,
    inputs: inputs,
    extra: extra
  }
  data[:project_name] = project_name if project_name

  response = post("/runs", data)
  Langsmith::Run.new(self, response)
end

#create_run_comment(run_id:, comment:, metadata: nil) ⇒ Hash

Create a comment on a run

Parameters:

  • run_id (String)

    ID of the run to comment on

  • comment (String)

    Comment text

  • metadata (Hash, nil) (defaults to: nil)

    Additional metadata for the comment (optional)

Returns:

  • (Hash)

    The created comment data



738
739
740
741
742
743
744
745
# File 'lib/langsmith/client.rb', line 738

def create_run_comment(run_id:, comment:, metadata: nil)
  data = {
    comment: comment
  }
  data[:metadata] =  if 
  
  post("/runs/#{run_id}/comments", data)
end

#create_tag(name:) ⇒ Hash

Create a new tag

Parameters:

  • name (String)

    Name of the tag

Returns:

  • (Hash)

    The created tag data



463
464
465
466
# File 'lib/langsmith/client.rb', line 463

def create_tag(name:)
  data = { name: name }
  post("/tags", data)
end

#create_tenant(name:, config: {}) ⇒ Hash

Create a new tenant

Parameters:

  • name (String)

    Name of the tenant

  • config (Hash) (defaults to: {})

    Configuration for the tenant

Returns:

  • (Hash)

    The created tenant data



438
439
440
441
442
443
444
# File 'lib/langsmith/client.rb', line 438

def create_tenant(name:, config: {})
  data = {
    name: name,
    config: config
  }
  post("/tenant", data)
end

#create_tracer_session(name:, metadata: {}) ⇒ Hash

Create a new tracer session

Parameters:

  • name (String)

    Name of the tracer session

  • metadata (Hash) (defaults to: {})

    Additional metadata for the tracer session

Returns:

  • (Hash)

    The created tracer session data



340
341
342
343
344
345
346
# File 'lib/langsmith/client.rb', line 340

def create_tracer_session(name:, metadata: {})
  data = {
    name: name,
    metadata: 
  }
  post("/tracer-sessions", data)
end

#create_webhook(url:, event_types:, metadata: nil) ⇒ Hash

Create a webhook

Parameters:

  • url (String)

    Webhook URL

  • event_types (Array<String>)

    List of event types to subscribe to

  • metadata (Hash, nil) (defaults to: nil)

    Additional metadata for the webhook (optional)

Returns:

  • (Hash)

    The created webhook data



868
869
870
871
872
873
874
875
876
# File 'lib/langsmith/client.rb', line 868

def create_webhook(url:, event_types:, metadata: nil)
  data = {
    url: url,
    event_types: event_types
  }
  data[:metadata] =  if 
  
  post("/webhooks", data)
end

#delete(path) ⇒ Object



995
996
997
998
# File 'lib/langsmith/client.rb', line 995

def delete(path)
  response = connection.delete(path)
  handle_response(response)
end

#delete_annotation_queue(id:) ⇒ Boolean

Delete an annotation queue

Parameters:

  • id (String)

    ID of the annotation queue to delete

Returns:

  • (Boolean)

    True if successful



613
614
615
616
# File 'lib/langsmith/client.rb', line 613

def delete_annotation_queue(id:)
  delete("/annotation-queues/#{id}")
  true
end

#delete_api_key(id:) ⇒ Boolean

Delete an API key

Parameters:

  • id (String)

    ID of the API key to delete

Returns:

  • (Boolean)

    True if successful



413
414
415
416
# File 'lib/langsmith/client.rb', line 413

def delete_api_key(id:)
  delete("/api-key/#{id}")
  true
end

#delete_comment(comment_id:) ⇒ Boolean

Delete a comment

Parameters:

  • comment_id (String)

    ID of the comment to delete

Returns:

  • (Boolean)

    True if successful



766
767
768
769
# File 'lib/langsmith/client.rb', line 766

def delete_comment(comment_id:)
  delete("/comments/#{comment_id}")
  true
end

#delete_dataset(id:) ⇒ Boolean

Delete a dataset

Parameters:

  • id (String)

    ID of the dataset to delete

Returns:

  • (Boolean)

    True if successful



185
186
187
188
# File 'lib/langsmith/client.rb', line 185

def delete_dataset(id:)
  delete("/datasets/#{id}")
  true
end

#delete_evaluation(id:) ⇒ Boolean

Delete an evaluation

Parameters:

  • id (String)

    ID of the evaluation to delete

Returns:

  • (Boolean)

    True if successful



301
302
303
304
# File 'lib/langsmith/client.rb', line 301

def delete_evaluation(id:)
  delete("/evaluations/#{id}")
  true
end

#delete_example(id:) ⇒ Boolean

Delete an example

Parameters:

  • id (String)

    ID of the example to delete

Returns:

  • (Boolean)

    True if successful



220
221
222
223
# File 'lib/langsmith/client.rb', line 220

def delete_example(id:)
  delete("/examples/#{id}")
  true
end

#delete_feedback_config(id:) ⇒ Boolean

Delete a feedback config

Parameters:

  • id (String)

    ID of the feedback config to delete

Returns:

  • (Boolean)

    True if successful



673
674
675
676
# File 'lib/langsmith/client.rb', line 673

def delete_feedback_config(id:)
  delete("/feedback-configs/#{id}")
  true
end

#delete_prompt(id:) ⇒ Boolean

Delete a prompt

Parameters:

  • id (String)

    ID of the prompt to delete

Returns:

  • (Boolean)

    True if successful



553
554
555
556
# File 'lib/langsmith/client.rb', line 553

def delete_prompt(id:)
  delete("/prompts/#{id}")
  true
end

#delete_tag(id:) ⇒ Boolean

Delete a tag

Parameters:

  • id (String)

    ID of the tag to delete

Returns:

  • (Boolean)

    True if successful



493
494
495
496
# File 'lib/langsmith/client.rb', line 493

def delete_tag(id:)
  delete("/tags/#{id}")
  true
end

#delete_webhook(id:) ⇒ Boolean

Delete a webhook

Parameters:

  • id (String)

    ID of the webhook to delete

Returns:

  • (Boolean)

    True if successful



922
923
924
925
# File 'lib/langsmith/client.rb', line 922

def delete_webhook(id:)
  delete("/webhooks/#{id}")
  true
end

#get(path, params = {}) ⇒ Object

HTTP request methods



976
977
978
979
# File 'lib/langsmith/client.rb', line 976

def get(path, params = {})
  response = connection.get(path, params)
  handle_response(response)
end

#get_annotation_queue(id:) ⇒ Hash

Get an annotation queue by ID

Parameters:

  • id (String)

    ID of the annotation queue to retrieve

Returns:

  • (Hash)

    The requested annotation queue data



577
578
579
# File 'lib/langsmith/client.rb', line 577

def get_annotation_queue(id:)
  get("/annotation-queues/#{id}")
end

#get_api_infoHash

Get API info

Returns:

  • (Hash)

    API information



688
689
690
# File 'lib/langsmith/client.rb', line 688

def get_api_info
  get("/info")
end

#get_current_organizationHash

Get current organization information

Returns:

  • (Hash)

    Organization information



372
373
374
# File 'lib/langsmith/client.rb', line 372

def get_current_organization
  get("/orgs/current")
end

#get_dataset(name:) ⇒ Langsmith::Dataset

Get a dataset by name

Parameters:

  • name (String)

    Name of the dataset to retrieve

Returns:



133
134
135
136
# File 'lib/langsmith/client.rb', line 133

def get_dataset(name:)
  response = get("/datasets/#{name}")
  Langsmith::Dataset.new(self, response)
end

#get_dataset_analytics(dataset_id:, start_time: nil, end_time: nil, group_by: nil, metrics: nil, filters: nil) ⇒ Hash

Get analytics for a dataset

Parameters:

  • dataset_id (String)

    ID of the dataset to get analytics for

  • start_time (Time, nil) (defaults to: nil)

    Start time for analytics (optional)

  • end_time (Time, nil) (defaults to: nil)

    End time for analytics (optional)

  • group_by (String, nil) (defaults to: nil)

    Field to group analytics by (optional)

  • metrics (Array<String>, nil) (defaults to: nil)

    Metrics to include (optional)

  • filters (Hash, nil) (defaults to: nil)

    Filters to apply (optional)

Returns:

  • (Hash)

    Analytics data



721
722
723
724
725
726
727
728
729
730
# File 'lib/langsmith/client.rb', line 721

def get_dataset_analytics(dataset_id:, start_time: nil, end_time: nil, group_by: nil, metrics: nil, filters: nil)
  params = {}
  params[:start_time] = start_time.iso8601 if start_time
  params[:end_time] = end_time.iso8601 if end_time
  params[:group_by] = group_by if group_by
  params[:metrics] = metrics if metrics
  params[:filters] = filters if filters
  
  get("/datasets/#{dataset_id}/analytics", params)
end

#get_dataset_by_id(id:) ⇒ Langsmith::Dataset

Get a dataset by ID

Parameters:

  • id (String)

    ID of the dataset to retrieve

Returns:



161
162
163
164
# File 'lib/langsmith/client.rb', line 161

def get_dataset_by_id(id:)
  response = get("/datasets/#{id}")
  Langsmith::Dataset.new(self, response)
end

#get_evaluation(id:) ⇒ Langsmith::Evaluation

Get an evaluation by ID

Parameters:

  • id (String)

    ID of the evaluation to retrieve

Returns:



249
250
251
252
# File 'lib/langsmith/client.rb', line 249

def get_evaluation(id:)
  response = get("/evaluations/#{id}")
  Langsmith::Evaluation.new(self, response)
end

#get_example(id:) ⇒ Langsmith::Example

Get an example by ID

Parameters:

  • id (String)

    ID of the example to retrieve

Returns:



194
195
196
197
# File 'lib/langsmith/client.rb', line 194

def get_example(id:)
  response = get("/examples/#{id}")
  Langsmith::Example.new(self, response)
end

#get_feedback(run_id:) ⇒ Array<Langsmith::Feedback>

Get feedback for a run

Parameters:

  • run_id (String)

    ID of the run to get feedback for

Returns:



329
330
331
332
333
# File 'lib/langsmith/client.rb', line 329

def get_feedback(run_id:)
  params = { run_id: run_id }
  response = get("/feedback", params)
  response.map { |feedback_data| Langsmith::Feedback.new(self, feedback_data) }
end

#get_feedback_config(id:) ⇒ Hash

Get a feedback config by ID

Parameters:

  • id (String)

    ID of the feedback config to retrieve

Returns:

  • (Hash)

    The requested feedback config data



637
638
639
# File 'lib/langsmith/client.rb', line 637

def get_feedback_config(id:)
  get("/feedback-configs/#{id}")
end

#get_organization(id:) ⇒ Hash

Get organization by ID

Parameters:

  • id (String)

    ID of the organization to retrieve

Returns:

  • (Hash)

    The requested organization data



387
388
389
# File 'lib/langsmith/client.rb', line 387

def get_organization(id:)
  get("/orgs/#{id}")
end

#get_project(name:) ⇒ Langsmith::Project

Get a project by name

Parameters:

  • name (String)

    Name of the project to retrieve

Returns:



101
102
103
104
# File 'lib/langsmith/client.rb', line 101

def get_project(name:)
  response = get("/projects/#{name}")
  Langsmith::Project.new(self, response)
end

#get_project_analytics(project_id:, start_time: nil, end_time: nil, group_by: nil, metrics: nil, filters: nil) ⇒ Hash

Get analytics for a project

Parameters:

  • project_id (String)

    ID of the project to get analytics for

  • start_time (Time, nil) (defaults to: nil)

    Start time for analytics (optional)

  • end_time (Time, nil) (defaults to: nil)

    End time for analytics (optional)

  • group_by (String, nil) (defaults to: nil)

    Field to group analytics by (optional)

  • metrics (Array<String>, nil) (defaults to: nil)

    Metrics to include (optional)

  • filters (Hash, nil) (defaults to: nil)

    Filters to apply (optional)

Returns:

  • (Hash)

    Analytics data



701
702
703
704
705
706
707
708
709
710
# File 'lib/langsmith/client.rb', line 701

def get_project_analytics(project_id:, start_time: nil, end_time: nil, group_by: nil, metrics: nil, filters: nil)
  params = {}
  params[:start_time] = start_time.iso8601 if start_time
  params[:end_time] = end_time.iso8601 if end_time
  params[:group_by] = group_by if group_by
  params[:metrics] = metrics if metrics
  params[:filters] = filters if filters
  
  get("/projects/#{project_id}/analytics", params)
end

#get_prompt(id:) ⇒ Hash

Get a prompt by ID

Parameters:

  • id (String)

    ID of the prompt to retrieve

Returns:

  • (Hash)

    The requested prompt data



517
518
519
# File 'lib/langsmith/client.rb', line 517

def get_prompt(id:)
  get("/prompts/#{id}")
end

#get_run(run_id:) ⇒ Langsmith::Run

Get a run by ID

Parameters:

  • run_id (String)

    ID of the run to retrieve

Returns:



63
64
65
66
# File 'lib/langsmith/client.rb', line 63

def get_run(run_id:)
  response = get("/runs/#{run_id}")
  Langsmith::Run.new(self, response)
end

#get_settingsHash

Get settings

Returns:

  • (Hash)

    Settings data



810
811
812
# File 'lib/langsmith/client.rb', line 810

def get_settings
  get("/settings")
end

#get_tag(id:) ⇒ Hash

Get a tag by ID

Parameters:

  • id (String)

    ID of the tag to retrieve

Returns:

  • (Hash)

    The requested tag data



472
473
474
# File 'lib/langsmith/client.rb', line 472

def get_tag(id:)
  get("/tags/#{id}")
end

#get_tenant(id:) ⇒ Hash

Get tenant information

Parameters:

  • id (String)

    ID of the tenant to retrieve

Returns:

  • (Hash)

    The requested tenant data



422
423
424
# File 'lib/langsmith/client.rb', line 422

def get_tenant(id:)
  get("/tenant/#{id}")
end

#get_tracer_session(id:) ⇒ Hash

Get a tracer session by ID

Parameters:

  • id (String)

    ID of the tracer session to retrieve

Returns:

  • (Hash)

    The requested tracer session data



352
353
354
# File 'lib/langsmith/client.rb', line 352

def get_tracer_session(id:)
  get("/tracer-sessions/#{id}")
end

#get_usage_limitsHash

Get usage limits

Returns:

  • (Hash)

    Usage limits information



681
682
683
# File 'lib/langsmith/client.rb', line 681

def get_usage_limits
  get("/usage-limits")
end

#get_webhook(id:) ⇒ Hash

Get a webhook by ID

Parameters:

  • id (String)

    ID of the webhook to retrieve

Returns:

  • (Hash)

    The requested webhook data



882
883
884
# File 'lib/langsmith/client.rb', line 882

def get_webhook(id:)
  get("/webhooks/#{id}")
end

#invite_team_member(email:, role:, organization_id: nil) ⇒ Hash

Invite a team member

Parameters:

  • email (String)

    Email of the person to invite

  • role (String)

    Role to assign to the new member

  • organization_id (String, nil) (defaults to: nil)

    Organization ID (optional, defaults to current organization)

Returns:

  • (Hash)

    The created invitation data



949
950
951
952
953
954
955
956
957
# File 'lib/langsmith/client.rb', line 949

def invite_team_member(email:, role:, organization_id: nil)
  data = {
    email: email,
    role: role
  }
  data[:organization_id] = organization_id if organization_id
  
  post("/team/invite", data)
end

#list_annotation_queues(limit: 100, offset: 0) ⇒ Array<Hash>

List annotation queues

Parameters:

  • limit (Integer) (defaults to: 100)

    Maximum number of annotation queues to return

  • offset (Integer) (defaults to: 0)

    Number of annotation queues to skip

Returns:

  • (Array<Hash>)

    List of annotation queues



586
587
588
589
590
591
592
# File 'lib/langsmith/client.rb', line 586

def list_annotation_queues(limit: 100, offset: 0)
  params = {
    limit: limit,
    offset: offset
  }
  get("/annotation-queues", params)
end

#list_api_keysArray<Hash>

List API keys

Returns:

  • (Array<Hash>)

    List of API keys



394
395
396
# File 'lib/langsmith/client.rb', line 394

def list_api_keys
  get("/api-key")
end

#list_datasets(limit: 100, offset: 0, name: nil, name_contains: nil) ⇒ Array<Langsmith::Dataset>

List datasets

Parameters:

  • limit (Integer) (defaults to: 100)

    Maximum number of datasets to return

  • offset (Integer) (defaults to: 0)

    Number of datasets to skip

  • name (String, nil) (defaults to: nil)

    Filter by dataset name (optional)

  • name_contains (String, nil) (defaults to: nil)

    Filter by dataset name containing string (optional)

Returns:



145
146
147
148
149
150
151
152
153
154
155
# File 'lib/langsmith/client.rb', line 145

def list_datasets(limit: 100, offset: 0, name: nil, name_contains: nil)
  params = { 
    limit: limit,
    offset: offset
  }
  params[:name] = name if name
  params[:name_contains] = name_contains if name_contains
  
  response = get("/datasets", params)
  response.map { |dataset_data| Langsmith::Dataset.new(self, dataset_data) }
end

#list_evaluations(dataset_id: nil, evaluator_name: nil, run_id: nil, status: nil, limit: 100, offset: 0) ⇒ Array<Langsmith::Evaluation>

List evaluations with optional filters

Parameters:

  • dataset_id (String, nil) (defaults to: nil)

    Filter by dataset ID (optional)

  • evaluator_name (String, nil) (defaults to: nil)

    Filter by evaluator name (optional)

  • run_id (String, nil) (defaults to: nil)

    Filter by run ID (optional)

  • status (String, nil) (defaults to: nil)

    Filter by status (optional)

  • limit (Integer) (defaults to: 100)

    Maximum number of evaluations to return

  • offset (Integer) (defaults to: 0)

    Number of evaluations to skip

Returns:



263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/langsmith/client.rb', line 263

def list_evaluations(dataset_id: nil, evaluator_name: nil, run_id: nil, status: nil, limit: 100, offset: 0)
  params = {
    limit: limit,
    offset: offset
  }
  params[:dataset_id] = dataset_id if dataset_id
  params[:evaluator_name] = evaluator_name if evaluator_name
  params[:run_id] = run_id if run_id
  params[:status] = status if status
  
  response = get("/evaluations", params)
  response.map { |eval_data| Langsmith::Evaluation.new(self, eval_data) }
end

#list_events(name: nil, start_time: nil, end_time: nil, limit: 100, offset: 0) ⇒ Array<Hash>

List events

Parameters:

  • name (String, nil) (defaults to: nil)

    Filter by event name (optional)

  • start_time (Time, nil) (defaults to: nil)

    Start time for events (optional)

  • end_time (Time, nil) (defaults to: nil)

    End time for events (optional)

  • limit (Integer) (defaults to: 100)

    Maximum number of events to return

  • offset (Integer) (defaults to: 0)

    Number of events to skip

Returns:

  • (Array<Hash>)

    List of events



795
796
797
798
799
800
801
802
803
804
805
# File 'lib/langsmith/client.rb', line 795

def list_events(name: nil, start_time: nil, end_time: nil, limit: 100, offset: 0)
  params = {
    limit: limit,
    offset: offset
  }
  params[:name] = name if name
  params[:start_time] = start_time.iso8601 if start_time
  params[:end_time] = end_time.iso8601 if end_time
  
  get("/events", params)
end

#list_feedback_configs(limit: 100, offset: 0) ⇒ Array<Hash>

List feedback configs

Parameters:

  • limit (Integer) (defaults to: 100)

    Maximum number of feedback configs to return

  • offset (Integer) (defaults to: 0)

    Number of feedback configs to skip

Returns:

  • (Array<Hash>)

    List of feedback configs



646
647
648
649
650
651
652
# File 'lib/langsmith/client.rb', line 646

def list_feedback_configs(limit: 100, offset: 0)
  params = {
    limit: limit,
    offset: offset
  }
  get("/feedback-configs", params)
end

#list_organizationsArray<Hash>

List organizations the user belongs to

Returns:

  • (Array<Hash>)

    List of organizations



379
380
381
# File 'lib/langsmith/client.rb', line 379

def list_organizations
  get("/orgs")
end

#list_projects(limit: 100) ⇒ Array<Langsmith::Project>

List projects

Parameters:

  • limit (Integer) (defaults to: 100)

    Maximum number of projects to return

Returns:



110
111
112
113
114
# File 'lib/langsmith/client.rb', line 110

def list_projects(limit: 100)
  params = { limit: limit }
  response = get("/projects", params)
  response.map { |project_data| Langsmith::Project.new(self, project_data) }
end

#list_prompts(limit: 100, offset: 0) ⇒ Array<Hash>

List prompts

Parameters:

  • limit (Integer) (defaults to: 100)

    Maximum number of prompts to return

  • offset (Integer) (defaults to: 0)

    Number of prompts to skip

Returns:

  • (Array<Hash>)

    List of prompts



526
527
528
529
530
531
532
# File 'lib/langsmith/client.rb', line 526

def list_prompts(limit: 100, offset: 0)
  params = {
    limit: limit,
    offset: offset
  }
  get("/prompts", params)
end

#list_run_comments(run_id:, limit: 100, offset: 0) ⇒ Array<Hash>

List comments on a run

Parameters:

  • run_id (String)

    ID of the run to list comments for

  • limit (Integer) (defaults to: 100)

    Maximum number of comments to return

  • offset (Integer) (defaults to: 0)

    Number of comments to skip

Returns:

  • (Array<Hash>)

    List of comments



753
754
755
756
757
758
759
760
# File 'lib/langsmith/client.rb', line 753

def list_run_comments(run_id:, limit: 100, offset: 0)
  params = {
    limit: limit,
    offset: offset
  }
  
  get("/runs/#{run_id}/comments", params)
end

#list_runs(project_name: nil, run_type: nil, limit: 100) ⇒ Array<Langsmith::Run>

List runs with optional filters

Parameters:

  • project_name (String) (defaults to: nil)

    Filter by project name

  • run_type (String) (defaults to: nil)

    Filter by run type

  • limit (Integer) (defaults to: 100)

    Maximum number of runs to return

Returns:



74
75
76
77
78
79
80
81
82
# File 'lib/langsmith/client.rb', line 74

def list_runs(project_name: nil, run_type: nil, limit: 100)
  params = {}
  params[:project_name] = project_name if project_name
  params[:run_type] = run_type if run_type
  params[:limit] = limit

  response = get("/runs", params)
  response.map { |run_data| Langsmith::Run.new(self, run_data) }
end

#list_tags(limit: 100, offset: 0) ⇒ Array<Hash>

List tags

Parameters:

  • limit (Integer) (defaults to: 100)

    Maximum number of tags to return

  • offset (Integer) (defaults to: 0)

    Number of tags to skip

Returns:

  • (Array<Hash>)

    List of tags



481
482
483
484
485
486
487
# File 'lib/langsmith/client.rb', line 481

def list_tags(limit: 100, offset: 0)
  params = {
    limit: limit,
    offset: offset
  }
  get("/tags", params)
end

#list_team_members(organization_id: nil, limit: 100, offset: 0) ⇒ Array<Hash>

List team members

Parameters:

  • organization_id (String, nil) (defaults to: nil)

    Organization ID (optional, defaults to current organization)

  • limit (Integer) (defaults to: 100)

    Maximum number of members to return

  • offset (Integer) (defaults to: 0)

    Number of members to skip

Returns:

  • (Array<Hash>)

    List of team members



933
934
935
936
937
938
939
940
941
# File 'lib/langsmith/client.rb', line 933

def list_team_members(organization_id: nil, limit: 100, offset: 0)
  params = {
    limit: limit,
    offset: offset
  }
  params[:organization_id] = organization_id if organization_id
  
  get("/team/members", params)
end

#list_tenantsArray<Hash>

List tenants

Returns:

  • (Array<Hash>)

    List of tenants



429
430
431
# File 'lib/langsmith/client.rb', line 429

def list_tenants
  get("/tenant")
end

#list_tracer_sessions(limit: 100, offset: 0) ⇒ Array<Hash>

List tracer sessions with optional filters

Parameters:

  • limit (Integer) (defaults to: 100)

    Maximum number of tracer sessions to return

  • offset (Integer) (defaults to: 0)

    Number of tracer sessions to skip

Returns:

  • (Array<Hash>)

    List of tracer sessions



361
362
363
364
365
366
367
# File 'lib/langsmith/client.rb', line 361

def list_tracer_sessions(limit: 100, offset: 0)
  params = {
    limit: limit,
    offset: offset
  }
  get("/tracer-sessions", params)
end

#list_webhooks(limit: 100, offset: 0) ⇒ Array<Hash>

List webhooks

Parameters:

  • limit (Integer) (defaults to: 100)

    Maximum number of webhooks to return

  • offset (Integer) (defaults to: 0)

    Number of webhooks to skip

Returns:

  • (Array<Hash>)

    List of webhooks



891
892
893
894
895
896
897
898
# File 'lib/langsmith/client.rb', line 891

def list_webhooks(limit: 100, offset: 0)
  params = {
    limit: limit,
    offset: offset
  }
  
  get("/webhooks", params)
end

#patch(path, data = {}) ⇒ Object



988
989
990
991
992
993
# File 'lib/langsmith/client.rb', line 988

def patch(path, data = {})
  response = connection.patch(path) do |req|
    req.body = JSON.generate(data)
  end
  handle_response(response)
end

#post(path, data = {}) ⇒ Object



981
982
983
984
985
986
# File 'lib/langsmith/client.rb', line 981

def post(path, data = {})
  response = connection.post(path) do |req|
    req.body = JSON.generate(data)
  end
  handle_response(response)
end

#remove_team_member(user_id:, organization_id: nil) ⇒ Boolean

Remove a team member

Parameters:

  • user_id (String)

    ID of the user to remove

  • organization_id (String, nil) (defaults to: nil)

    Organization ID (optional, defaults to current organization)

Returns:

  • (Boolean)

    True if successful



964
965
966
967
968
969
970
971
972
# File 'lib/langsmith/client.rb', line 964

def remove_team_member(user_id:, organization_id: nil)
  data = {
    user_id: user_id
  }
  data[:organization_id] = organization_id if organization_id
  
  post("/team/remove", data)
  true
end

#update_annotation_queue(id:, name: nil, description: nil, metadata: nil) ⇒ Hash

Update an annotation queue

Parameters:

  • id (String)

    ID of the annotation queue to update

  • name (String, nil) (defaults to: nil)

    New name for the annotation queue (optional)

  • description (String, nil) (defaults to: nil)

    New description for the annotation queue (optional)

  • metadata (Hash, nil) (defaults to: nil)

    New metadata for the annotation queue (optional)

Returns:

  • (Hash)

    The updated annotation queue data



601
602
603
604
605
606
607
# File 'lib/langsmith/client.rb', line 601

def update_annotation_queue(id:, name: nil, description: nil, metadata: nil)
  data = {}
  data[:name] = name if name
  data[:description] = description if description
  data[:metadata] =  if 
  patch("/annotation-queues/#{id}", data)
end

#update_dataset(id:, name: nil, description: nil) ⇒ Langsmith::Dataset

Update a dataset

Parameters:

  • id (String)

    ID of the dataset to update

  • name (String, nil) (defaults to: nil)

    New name for the dataset (optional)

  • description (String, nil) (defaults to: nil)

    New description for the dataset (optional)

Returns:



172
173
174
175
176
177
178
179
# File 'lib/langsmith/client.rb', line 172

def update_dataset(id:, name: nil, description: nil)
  data = {}
  data[:name] = name if name
  data[:description] = description if description
  
  response = patch("/datasets/#{id}", data)
  Langsmith::Dataset.new(self, response)
end

#update_evaluation_metadata(id:, metadata:) ⇒ Langsmith::Evaluation

Update an evaluation’s metadata

Parameters:

  • id (String)

    ID of the evaluation to update

  • metadata (Hash)

    New metadata for the evaluation

Returns:



282
283
284
285
286
# File 'lib/langsmith/client.rb', line 282

def (id:, metadata:)
  data = { metadata:  }
  response = patch("/evaluations/#{id}", data)
  Langsmith::Evaluation.new(self, response)
end

#update_example(id:, inputs: nil, outputs: nil, metadata: nil) ⇒ Langsmith::Example

Update an example

Parameters:

  • id (String)

    ID of the example to update

  • inputs (Hash, nil) (defaults to: nil)

    New input values (optional)

  • outputs (Hash, nil) (defaults to: nil)

    New output values (optional)

  • metadata (Hash, nil) (defaults to: nil)

    New metadata (optional)

Returns:



206
207
208
209
210
211
212
213
214
# File 'lib/langsmith/client.rb', line 206

def update_example(id:, inputs: nil, outputs: nil, metadata: nil)
  data = {}
  data[:inputs] = inputs if inputs
  data[:outputs] = outputs if outputs
  data[:metadata] =  if 
  
  response = patch("/examples/#{id}", data)
  Langsmith::Example.new(self, response)
end

#update_feedback_config(id:, name: nil, type: nil, metadata: nil) ⇒ Hash

Update a feedback config

Parameters:

  • id (String)

    ID of the feedback config to update

  • name (String, nil) (defaults to: nil)

    New name for the feedback config (optional)

  • type (String, nil) (defaults to: nil)

    New type for the feedback config (optional)

  • metadata (Hash, nil) (defaults to: nil)

    New metadata for the feedback config (optional)

Returns:

  • (Hash)

    The updated feedback config data



661
662
663
664
665
666
667
# File 'lib/langsmith/client.rb', line 661

def update_feedback_config(id:, name: nil, type: nil, metadata: nil)
  data = {}
  data[:name] = name if name
  data[:type] = type if type
  data[:metadata] =  if 
  patch("/feedback-configs/#{id}", data)
end

#update_prompt(id:, name: nil, prompt_template: nil, metadata: nil) ⇒ Hash

Update a prompt

Parameters:

  • id (String)

    ID of the prompt to update

  • name (String, nil) (defaults to: nil)

    New name for the prompt (optional)

  • prompt_template (String, nil) (defaults to: nil)

    New prompt template (optional)

  • metadata (Hash, nil) (defaults to: nil)

    New metadata for the prompt (optional)

Returns:

  • (Hash)

    The updated prompt data



541
542
543
544
545
546
547
# File 'lib/langsmith/client.rb', line 541

def update_prompt(id:, name: nil, prompt_template: nil, metadata: nil)
  data = {}
  data[:name] = name if name
  data[:prompt_template] = prompt_template if prompt_template
  data[:metadata] =  if 
  patch("/prompts/#{id}", data)
end

#update_run(run_id:, outputs: nil, end_time: nil, error: nil) ⇒ Langsmith::Run

Update a run

Parameters:

  • run_id (String)

    ID of the run to update

  • outputs (Hash) (defaults to: nil)

    Output values from the run

  • end_time (Time) (defaults to: nil)

    End time of the run

  • error (String) (defaults to: nil)

    Error message if the run failed

Returns:



49
50
51
52
53
54
55
56
57
# File 'lib/langsmith/client.rb', line 49

def update_run(run_id:, outputs: nil, end_time: nil, error: nil)
  data = {}
  data[:outputs] = outputs if outputs
  data[:end_time] = end_time.iso8601 if end_time
  data[:error] = error if error

  response = patch("/runs/#{run_id}", data)
  Langsmith::Run.new(self, response)
end

#update_settings(settings:) ⇒ Hash

Update settings

Parameters:

  • settings (Hash)

    Settings to update

Returns:

  • (Hash)

    Updated settings data



818
819
820
# File 'lib/langsmith/client.rb', line 818

def update_settings(settings:)
  patch("/settings", settings)
end

#update_tenant(id:, name: nil, config: nil) ⇒ Hash

Update a tenant

Parameters:

  • id (String)

    ID of the tenant to update

  • name (String, nil) (defaults to: nil)

    New name for the tenant (optional)

  • config (Hash, nil) (defaults to: nil)

    New configuration for the tenant (optional)

Returns:

  • (Hash)

    The updated tenant data



452
453
454
455
456
457
# File 'lib/langsmith/client.rb', line 452

def update_tenant(id:, name: nil, config: nil)
  data = {}
  data[:name] = name if name
  data[:config] = config if config
  patch("/tenant/#{id}", data)
end

#update_webhook(id:, url: nil, event_types: nil, metadata: nil, active: nil) ⇒ Hash

Update a webhook

Parameters:

  • id (String)

    ID of the webhook to update

  • url (String, nil) (defaults to: nil)

    New webhook URL (optional)

  • event_types (Array<String>, nil) (defaults to: nil)

    New list of event types (optional)

  • metadata (Hash, nil) (defaults to: nil)

    New metadata for the webhook (optional)

  • active (Boolean, nil) (defaults to: nil)

    Whether the webhook is active (optional)

Returns:

  • (Hash)

    The updated webhook data



908
909
910
911
912
913
914
915
916
# File 'lib/langsmith/client.rb', line 908

def update_webhook(id:, url: nil, event_types: nil, metadata: nil, active: nil)
  data = {}
  data[:url] = url if url
  data[:event_types] = event_types if event_types
  data[:metadata] =  if 
  data[:active] = active unless active.nil?
  
  patch("/webhooks/#{id}", data)
end