Skip to main content

TrueState Python SDK

The TrueState Python SDK is a Python library that allows you to interact with the TrueState API. The SDK provides a convenient way to access the TrueState API from your Python application.

For documentation on the TrueState API, visit the API documentation.

Installation

You can install the TrueState Python SDK using pip:

pip install truestate

Once installed, you must configure the following environment variables:

export TRUESTATE_API_KEY="your-api-key"
export TRUESTATE_ORGANISATION_ID="your-organisation-id"

Inference

The TrueState Python SDK provides a simple way to build and deploy robust natural language AI systems. The inference SDK provides a high-level API for making predictions on your models.

Univesal Classification

Universal classification is an advanced type of NLP classification that can be used to classify any type of text data. The TrueState Python SDK provides a high-level API for making predictions on your universal classification models.

from truestate.inference import classify

sample_text = "You should invest all of your money on the stock market!"

result = classify(sample_text, choices=["the text contains financial advice"])

print(result)
#{'the text contains financial advice': 0.9951813}

Semantic Routing

Semantic routing is a powerful feature that allows you to route incoming messages to the appropriate department or team based on the content of the message. The TrueState Python SDK provides a high-level API for making predictions on your semantic routing models.

from truestate.inference import route

sample_text = "I have a question about my order."


def send_to_order_agent(text: str):
    return f"Sending message to order agent: '{text}'"

def send_to_support_agent(text: str):
    return f"Sending message to support agent: '{text}'"

def send_to_general_agent(text: str):
    return f"Would send message to general agent: '{text}'"

routing_strategies = {
    "the user message is about an order": send_to_order_agent,
    "the user message is about a problem with a product / service": send_to_support_agent,
    "__default__": send_to_general_agent
}

response = route(sample_text, routing_strategies, threshold=0.5)

print(response)
# Sending message to order agent: I have a question about my order....

Natural language search allows you to search for information using natural language queries, offering considerable performance gains above traditional search algorithms. The TrueState Python SDK provides a high-level API for making predictions on your searchable datasets.

To create a searchable dataset, visit the Workflows documentation.

from truestate.inference import search

query = "lightweight camping gear for backpacking"

dataset_id = "1783d3ff-178e-485d-a43b-23759cc6bdf3"

results = search("Com", dataset_id)

print(results)
# [
#     {
#         "id": "UL001",
#         "name": "Featherlight Pro X2 Tent",
#         "description": "Ultra-lightweight 2-person tent weighing 1.75 lbs (794g). Made with Dyneema Composite Fabric for ultimate strength-to-weight ratio. Ideal for thru-hikers on long-distance trails."
#     },
#     {
#         "id": "UL002",
#         "name": "AeroDown Ultralight 5°F Sleeping Bag",
#         "description": "Premium 5°F (-15°C) rated sleeping bag weighing only 1.2 lbs (544g). Features 950+ fill power down with water-repellent treatment. Perfect for long-distance backpacking in varied conditions."
#     },
#     {
#         "id": "UL003",
#         "name": "TitaniumFlame Micro Stove System",
#         "description": "Integrated stove system weighing 5.6 oz (159g) including pot. Boils water in 100 seconds and nests with a fuel canister. Engineered for ultralight long-distance hikers."
#     }
# ]

Hierarchy Classification

In some instances it's necessary to classify text data into a hierarchy of categories. The TrueState Python SDK provides a high-level API for making predictions on your hierarchy classification models.

from truestate.inference import hierarchy_classificaiton

sample_text = "Amazon is a multinational technology company that focuses on e-commerce, cloud computing, digital streaming, and artificial intelligence. The primary business of Amazon.com is the sale of consumer goods and subscriptions."

hierarchy = ClassHierarchy(
    name="company-categorisation",
    choices=[
        Category(
            label="Software company",
            criteria="this text contains a description of a software company",
            subcategories=[
                Category(
                    label="Ecommerce",
                    criteria="this text contains a description of an ecommerce company",
                ),
                Category(
                    label="Blockchain",
                    criteria="this text contains a description of an web3.0 / blockchain company",
                ),
            ],
        ),
    ],
)

result = hierarchy_classificaiton(sample_text, hierarchy)
print(result)
# {
#     "text": "Amazon is a multinational technology company that focuses on e-commerce, cloud computing, digital streaming, and artificial intelligence. The primary business of Amazon.com is the sale of consumer goods and subscriptions.",
#    "categories": {
#       "category_1": "Software company",
#       "category_2": "Ecommerce"
# }

Metadata

Release files for truestate 0.7.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for truestate 0.7.8
File Size Uploaded
truestate-0.7.8.tar.gz 20.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for truestate 0.7.8
File Interpreter ABI Platform
truestate-0.7.8-py3-none-any.whl Python 3 none any Details

Total release size: 52.6 kB

Release files / truestate-0.7.8.tar.gz

Download URL truestate-0.7.8.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8a87ae53f398d7ac0534838badfc881b005c8830dc3e3007ef4823572b74a98a
BLAKE2b-256 checksum
How to use checksums
c7fc912587b9f728a3502ebead3d05abdc6aa33cadcbb07bb10c40a26d424da9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.2

Release files / truestate-0.7.8-py3-none-any.whl

Download URL truestate-0.7.8-py3-none-any.whl
Size 32.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
309b2742362f65e84fa003dfa4f07c0c3339a9e1ba0443c31703f29fb356821b
BLAKE2b-256 checksum
How to use checksums
2cf7b2b6471bc2fd7da31973189314a9daae76fb6ca100567af92ea3d1cee467
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.7.8 This release

2 release files

0.7.7

2 release files

0.5.66

2 release files

0.5.62

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page