Skip to main content

[DEPRECATED] Vellum Python Client

Project description

:no_entry: [DEPRECATED] Active at https://github.com/vellum-ai/vellum-client-python

Vellum Python Library

The Vellum python library provides convenient access to the Vellum Predict API from python applications.

Installation

$ pip install vellum-client

Usage

Setup

You'll need an API key from your Vellum account to use this library. You can create an API key from within your account here. We recommend setting it as an environment variable.

Generating Text

Here's an example of initializing the library with the API key loaded from an environment variable and initiating a generation:

import vellum

vellum.api_key = "<YOUR_API_KEY>"

result = vellum.Generate.run(
    deployment_name="my-deployment",
    requests=[
        vellum.GenerateRequest(
            input_values={"question": "Can I get a refund?"}
        )
    ]
)

print(result.text)

Submitting Actuals

Submitting actuals is how you provide feedback to Vellum about the quality of the generated text. This feedback can be used to measure model quality and improve it over time.

import vellum

vellum.api_key = "<YOUR_API_KEY>"

vellum.SubmitCompletionActuals.run(
    deployment_name="customer-service-demo",
    actuals=[
        vellum.CompletionActual(
            id="<id-returned-from-generate-endpoint>",
            quality=1.0,  # 1.0 is good, 0.0 is bad
            text="Sorry, we do not offer refunds.",
        )
    ]
)

Note: If you don't want to keep track of the ids that Vellum generates, you can include an externalId key in the initial generate request. You can then include this externalId when submitting actuals. If you use this approach, be sure that the ids you provide truly are unique, or you may get unexpected results.

Uploading Documents to Search Across

Documents can be uploaded to Vellum via either the UI or this API. Once uploaded and indexed, Vellum's Search allows you to perform semantic searches against them. Here is an example of how to upload a document from a local file:

import vellum

vellum.api_key = "<YOUR_API_KEY>"


with open("/path/to/your/file.txt", "rb") as file:
    result = vellum.UploadDocument.run(
        # File to upload
        contents=file,
        # Document label
        label="Human-friendly label for your document",
        # The names of indexes that you'd like this document to be added to.
        add_to_index_names=["<your-index-name>"],
        # Optionally include a unique ID from your system to this document later.
        #   Useful if you want to perform updates later
        external_id="<your-index-name>",
        # Optionally include keywords to associate with the document that can be used in hybrid search
        keywords=[],
    )
    
print(result)

Performing a Search

Vellum's Search allows you to upload documents and then perform semantic searches against them. Here is an example of how to perform a search:

import vellum

vellum.api_key = "<YOUR_API_KEY>"

result = vellum.Search.run(
    index_name="help-center-docs",
    query="What is fine tuning?",
    options=vellum.SearchOptions(limit=3),
)

print(result)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vellum-client-0.0.13.tar.gz (8.1 kB view details)

Uploaded Source

File details

Details for the file vellum-client-0.0.13.tar.gz.

File metadata

  • Download URL: vellum-client-0.0.13.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.28.2 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/3.7.9

File hashes

Hashes for vellum-client-0.0.13.tar.gz
Algorithm Hash digest
SHA256 8620e3de9414960490bcd430a3ef463c9fd90a0b9c31794e01261076090123fa
MD5 988c8bc9ff977db30f508895c1a714e3
BLAKE2b-256 66519542331e1e3898528ba8af50820dd8e4f87ab9ab20c2a1e8c518b50b98c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page