Class: Vellum::AsyncClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, environment: Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil) ⇒ AsyncClient

Parameters:

  • environment (Environment) (defaults to: Environment::PRODUCTION)
  • max_retries (Long) (defaults to: nil)

    The number of times to retry a failed request, defaults to 2.

  • timeout_in_seconds (Long) (defaults to: nil)
  • api_key (String)


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

def initialize(api_key:, environment: Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil)
  @async_request_client = AsyncRequestClient.new(environment: environment, max_retries: max_retries,
                                                 timeout_in_seconds: timeout_in_seconds, api_key: api_key)
  @deployments = AsyncDeploymentsClient.new(request_client: @async_request_client)
  @document_indexes = AsyncDocumentIndexesClient.new(request_client: @async_request_client)
  @documents = AsyncDocumentsClient.new(request_client: @async_request_client)
  @folder_entities = AsyncFolderEntitiesClient.new(request_client: @async_request_client)
  @model_versions = AsyncModelVersionsClient.new(request_client: @async_request_client)
  @registered_prompts = AsyncRegisteredPromptsClient.new(request_client: @async_request_client)
  @sandboxes = AsyncSandboxesClient.new(request_client: @async_request_client)
  @test_suite_runs = AsyncTestSuiteRunsClient.new(request_client: @async_request_client)
  @test_suites = AsyncTestSuitesClient.new(request_client: @async_request_client)
  @workflow_deployments = AsyncWorkflowDeploymentsClient.new(request_client: @async_request_client)
end

Instance Attribute Details

#deploymentsObject (readonly)

Returns the value of attribute deployments.



255
256
257
# File 'lib/vellum_ai.rb', line 255

def deployments
  @deployments
end

#document_indexesObject (readonly)

Returns the value of attribute document_indexes.



255
256
257
# File 'lib/vellum_ai.rb', line 255

def document_indexes
  @document_indexes
end

#documentsObject (readonly)

Returns the value of attribute documents.



255
256
257
# File 'lib/vellum_ai.rb', line 255

def documents
  @documents
end

#folder_entitiesObject (readonly)

Returns the value of attribute folder_entities.



255
256
257
# File 'lib/vellum_ai.rb', line 255

def folder_entities
  @folder_entities
end

#model_versionsObject (readonly)

Returns the value of attribute model_versions.



255
256
257
# File 'lib/vellum_ai.rb', line 255

def model_versions
  @model_versions
end

#registered_promptsObject (readonly)

Returns the value of attribute registered_prompts.



255
256
257
# File 'lib/vellum_ai.rb', line 255

def registered_prompts
  @registered_prompts
end

#sandboxesObject (readonly)

Returns the value of attribute sandboxes.



255
256
257
# File 'lib/vellum_ai.rb', line 255

def sandboxes
  @sandboxes
end

#test_suite_runsObject (readonly)

Returns the value of attribute test_suite_runs.



255
256
257
# File 'lib/vellum_ai.rb', line 255

def test_suite_runs
  @test_suite_runs
end

#test_suitesObject (readonly)

Returns the value of attribute test_suites.



255
256
257
# File 'lib/vellum_ai.rb', line 255

def test_suites
  @test_suites
end

#workflow_deploymentsObject (readonly)

Returns the value of attribute workflow_deployments.



255
256
257
# File 'lib/vellum_ai.rb', line 255

def workflow_deployments
  @workflow_deployments
end

Instance Method Details

#execute_prompt(inputs:, prompt_deployment_id: nil, prompt_deployment_name: nil, release_tag: nil, external_id: nil, expand_meta: nil, raw_overrides: nil, expand_raw: nil, metadata: nil, request_options: nil) ⇒ ExecutePromptResponse

Executes a deployed Prompt and returns the result.

Parameters:

  • inputs (Array<Hash>)

    The list of inputs defined in the Prompt’s deployment with their corresponding values.Request of type Array<PromptDeploymentInputRequest>, as a Hash

  • prompt_deployment_id (String) (defaults to: nil)

    The ID of the Prompt Deployment. Must provide either this or prompt_deployment_name.

  • prompt_deployment_name (String) (defaults to: nil)

    The name of the Prompt Deployment. Must provide either this or prompt_deployment_id.

  • release_tag (String) (defaults to: nil)

    Optionally specify a release tag if you want to pin to a specific release of the Prompt Deployment

  • external_id (String) (defaults to: nil)

    “Optionally include a unique identifier for tracking purposes. Must be unique for a given prompt deployment.

  • expand_meta (Hash) (defaults to: nil)

    The name of the Prompt Deployment. Must provide either this or prompt_deployment_id.Request of type PromptDeploymentExpandMetaRequestRequest, as a Hash

    • :model_name (Boolean)

    • :latency (Boolean)

    • :deployment_release_tag (Boolean)

    • :prompt_version_id (Boolean)

    • :finish_reason (Boolean)

  • raw_overrides (Hash) (defaults to: nil)

    Request of type RawPromptExecutionOverridesRequest, as a Hash

    • :body (Hash=> String)

    • :headers (Hash=> String)

    • :url (String)

  • expand_raw (Array<String>) (defaults to: nil)

    Returns the raw API response data sent from the model host. Combined with ‘raw_overrides`, it can be used to access new features from models.

  • metadata (Hash{String => String}) (defaults to: nil)
  • request_options (RequestOptions) (defaults to: nil)

Returns:



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/vellum_ai.rb', line 299

def execute_prompt(inputs:, prompt_deployment_id: nil, prompt_deployment_name: nil, release_tag: nil,
                   external_id: nil, expand_meta: nil, raw_overrides: nil, expand_raw: nil, metadata: nil, request_options: nil)
  response = @async_request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      inputs: inputs,
      prompt_deployment_id: prompt_deployment_id,
      prompt_deployment_name: prompt_deployment_name,
      release_tag: release_tag,
      external_id: external_id,
      expand_meta: expand_meta,
      raw_overrides: raw_overrides,
      expand_raw: expand_raw,
      metadata: 
    }.compact
    req.url "#{@async_request_client.default_environment[:Predict]}/v1/execute-prompt"
  end
  ExecutePromptResponse.from_json(json_object: response.body)
end

#execute_workflow(inputs:, workflow_deployment_id: nil, workflow_deployment_name: nil, release_tag: nil, external_id: nil, request_options: nil) ⇒ ExecuteWorkflowResponse

Executes a deployed Workflow and returns its outputs.

Parameters:

  • inputs (Array<Hash>)

    The list of inputs defined in the Workflow’s Deployment with their corresponding values.Request of type Array<WorkflowRequestInputRequest>, as a Hash

  • workflow_deployment_id (String) (defaults to: nil)

    The ID of the Workflow Deployment. Must provide either this or workflow_deployment_name.

  • workflow_deployment_name (String) (defaults to: nil)

    The name of the Workflow Deployment. Must provide either this or workflow_deployment_id.

  • release_tag (String) (defaults to: nil)

    Optionally specify a release tag if you want to pin to a specific release of the Workflow Deployment

  • external_id (String) (defaults to: nil)

    Optionally include a unique identifier for tracking purposes. Must be unique for a given workflow deployment.

  • request_options (RequestOptions) (defaults to: nil)

Returns:



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/vellum_ai.rb', line 331

def execute_workflow(inputs:, workflow_deployment_id: nil, workflow_deployment_name: nil, release_tag: nil,
                     external_id: nil, request_options: nil)
  response = @async_request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      inputs: inputs,
      workflow_deployment_id: workflow_deployment_id,
      workflow_deployment_name: workflow_deployment_name,
      release_tag: release_tag,
      external_id: external_id
    }.compact
    req.url "#{@async_request_client.default_environment[:Predict]}/v1/execute-workflow"
  end
  ExecuteWorkflowResponse.from_json(json_object: response.body)
end

#generate(requests:, deployment_id: nil, deployment_name: nil, options: nil, request_options: nil) ⇒ GenerateResponse

Generate a completion using a previously defined deployment.

Note: Uses a base url of ‘predict.vellum.ai`.

Parameters:

  • deployment_id (String) (defaults to: nil)

    The ID of the deployment. Must provide either this or deployment_name.

  • deployment_name (String) (defaults to: nil)

    The name of the deployment. Must provide either this or deployment_id.

  • requests (Array<Hash>)

    The generation request to make. Bulk requests are no longer supported, this field must be an array of length 1.Request of type Array<GenerateRequest>, as a Hash

    • :input_values (Hash=> String)

    • :chat_history (Array<ChatMessageRequest>)

    • :external_ids (Array<String>)

  • options (Hash) (defaults to: nil)

    Additional configuration that can be used to control what’s included in the response.Request of type GenerateOptionsRequest, as a Hash

    • :logprobs (LOGPROBS_ENUM)

  • request_options (RequestOptions) (defaults to: nil)

Returns:



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/vellum_ai.rb', line 364

def generate(requests:, deployment_id: nil, deployment_name: nil, options: nil, request_options: nil)
  response = @async_request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      deployment_id: deployment_id,
      deployment_name: deployment_name,
      requests: requests,
      options: options
    }.compact
    req.url "#{@async_request_client.default_environment[:Predict]}/v1/generate"
  end
  GenerateResponse.from_json(json_object: response.body)
end

#search(query:, index_id: nil, index_name: nil, options: nil, request_options: nil) ⇒ SearchResponse

Perform a search against a document index.

Note: Uses a base url of ‘predict.vellum.ai`.

Parameters:

  • index_id (String) (defaults to: nil)

    The ID of the index to search against. Must provide either this or index_name.

  • index_name (String) (defaults to: nil)

    The name of the index to search against. Must provide either this or index_id.

  • query (String)

    The query to search for.

  • options (Hash) (defaults to: nil)

    Configuration options for the search.Request of type SearchRequestOptionsRequest, as a Hash

    • :limit (Integer)

    • :weights (Hash)

      • :semantic_similarity (Float)

      • :keywords (Float)

    • :result_merging (Hash)

      • :enabled (Boolean)

    • :filters (Hash)

      • :external_ids (Array<String>)

      • :metadata (Hash)

        • :combinator (METADATA_FILTER_RULE_COMBINATOR)

        • :negated (Boolean)

        • :rules (Array<MetadataFilterRuleRequest>)

        • :field (String)

        • :operator (LOGICAL_OPERATOR)

        • :value (String)

  • request_options (RequestOptions) (defaults to: nil)

Returns:



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/vellum_ai.rb', line 406

def search(query:, index_id: nil, index_name: nil, options: nil, request_options: nil)
  response = @async_request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      index_id: index_id,
      index_name: index_name,
      query: query,
      options: options
    }.compact
    req.url "#{@async_request_client.default_environment[:Predict]}/v1/search"
  end
  SearchResponse.from_json(json_object: response.body)
end

#submit_completion_actuals(actuals:, deployment_id: nil, deployment_name: nil, request_options: nil) ⇒ Void

Used to submit feedback regarding the quality of previously generated completions.

Note: Uses a base url of ‘predict.vellum.ai`.

Parameters:

  • deployment_id (String) (defaults to: nil)

    The ID of the deployment. Must provide either this or deployment_name.

  • deployment_name (String) (defaults to: nil)

    The name of the deployment. Must provide either this or deployment_id.

  • actuals (Array<Hash>)

    Feedback regarding the quality of previously generated completionsRequest of type Array<SubmitCompletionActualRequest>, as a Hash

    • :id (String)

    • :external_id (String)

    • :text (String)

    • :quality (Float)

    • :timestamp (DateTime)

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/vellum_ai.rb', line 437

def submit_completion_actuals(actuals:, deployment_id: nil, deployment_name: nil, request_options: nil)
  @async_request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      deployment_id: deployment_id,
      deployment_name: deployment_name,
      actuals: actuals
    }.compact
    req.url "#{@async_request_client.default_environment[:Predict]}/v1/submit-completion-actuals"
  end
end

#submit_workflow_execution_actuals(actuals:, execution_id: nil, external_id: nil, request_options: nil) ⇒ Void

Used to submit feedback regarding the quality of previous workflow execution and its outputs.

**Note:** Uses a base url of `https://predict.vellum.ai`.

Parameters:

  • actuals (Array<Hash>)

    Feedback regarding the quality of an output on a previously executed workflow.Request of type Array<SubmitWorkflowExecutionActualRequest>, as a Hash

  • execution_id (String) (defaults to: nil)

    The Vellum-generated ID of a previously executed workflow. Must provide either this or external_id.

  • external_id (String) (defaults to: nil)

    The external ID that was originally provided by when executing the workflow, if applicable, that you’d now like to submit actuals for. Must provide either this or execution_id.

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/vellum_ai.rb', line 461

def submit_workflow_execution_actuals(actuals:, execution_id: nil, external_id: nil, request_options: nil)
  @async_request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      actuals: actuals,
      execution_id: execution_id,
      external_id: external_id
    }.compact
    req.url "#{@async_request_client.default_environment[:Predict]}/v1/submit-workflow-execution-actuals"
  end
end