Class: Vellum::Client

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) ⇒ Client

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)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vellum_ai.rb', line 40

def initialize(api_key:, environment: Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil)
  @request_client = RequestClient.new(environment: environment, max_retries: max_retries,
                                      timeout_in_seconds: timeout_in_seconds, api_key: api_key)
  @deployments = DeploymentsClient.new(request_client: @request_client)
  @document_indexes = DocumentIndexesClient.new(request_client: @request_client)
  @documents = DocumentsClient.new(request_client: @request_client)
  @folder_entities = FolderEntitiesClient.new(request_client: @request_client)
  @model_versions = ModelVersionsClient.new(request_client: @request_client)
  @registered_prompts = RegisteredPromptsClient.new(request_client: @request_client)
  @sandboxes = SandboxesClient.new(request_client: @request_client)
  @test_suite_runs = TestSuiteRunsClient.new(request_client: @request_client)
  @test_suites = TestSuitesClient.new(request_client: @request_client)
  @workflow_deployments = WorkflowDeploymentsClient.new(request_client: @request_client)
end

Instance Attribute Details

#deploymentsObject (readonly)

Returns the value of attribute deployments.



32
33
34
# File 'lib/vellum_ai.rb', line 32

def deployments
  @deployments
end

#document_indexesObject (readonly)

Returns the value of attribute document_indexes.



32
33
34
# File 'lib/vellum_ai.rb', line 32

def document_indexes
  @document_indexes
end

#documentsObject (readonly)

Returns the value of attribute documents.



32
33
34
# File 'lib/vellum_ai.rb', line 32

def documents
  @documents
end

#folder_entitiesObject (readonly)

Returns the value of attribute folder_entities.



32
33
34
# File 'lib/vellum_ai.rb', line 32

def folder_entities
  @folder_entities
end

#model_versionsObject (readonly)

Returns the value of attribute model_versions.



32
33
34
# File 'lib/vellum_ai.rb', line 32

def model_versions
  @model_versions
end

#registered_promptsObject (readonly)

Returns the value of attribute registered_prompts.



32
33
34
# File 'lib/vellum_ai.rb', line 32

def registered_prompts
  @registered_prompts
end

#sandboxesObject (readonly)

Returns the value of attribute sandboxes.



32
33
34
# File 'lib/vellum_ai.rb', line 32

def sandboxes
  @sandboxes
end

#test_suite_runsObject (readonly)

Returns the value of attribute test_suite_runs.



32
33
34
# File 'lib/vellum_ai.rb', line 32

def test_suite_runs
  @test_suite_runs
end

#test_suitesObject (readonly)

Returns the value of attribute test_suites.



32
33
34
# File 'lib/vellum_ai.rb', line 32

def test_suites
  @test_suites
end

#workflow_deploymentsObject (readonly)

Returns the value of attribute workflow_deployments.



32
33
34
# File 'lib/vellum_ai.rb', line 32

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:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/vellum_ai.rb', line 76

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 = @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 "#{@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:



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/vellum_ai.rb', line 108

def execute_workflow(inputs:, workflow_deployment_id: nil, workflow_deployment_name: nil, release_tag: nil,
                     external_id: nil, request_options: nil)
  response = @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 "#{@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:



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/vellum_ai.rb', line 141

def generate(requests:, deployment_id: nil, deployment_name: nil, options: nil, request_options: nil)
  response = @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 "#{@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:



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/vellum_ai.rb', line 183

def search(query:, index_id: nil, index_name: nil, options: nil, request_options: nil)
  response = @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 "#{@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)


214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/vellum_ai.rb', line 214

def submit_completion_actuals(actuals:, deployment_id: nil, deployment_name: nil, request_options: nil)
  @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 "#{@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)


238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/vellum_ai.rb', line 238

def submit_workflow_execution_actuals(actuals:, execution_id: nil, external_id: nil, request_options: nil)
  @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 "#{@request_client.default_environment[:Predict]}/v1/submit-workflow-execution-actuals"
  end
end