Skip to main content

SDK for truthsystems.ai, a hallucination detection API

Project description

Truth Systems SDK

This is the Python SDK for the Truth Systems API. It allows you to easily interact with the API to judge the veracity of claims based on provided sources.

To use it, you must first have access to the Truth Systems API. See our website for more information.

Quickstart

from truthsys import (
    Client,  # or AsyncClient if you like
    TextInfluence,
    TextSource,
    Verdict,
)


client = Client.from_url("YOUR_BASE_URL")  # or Client.from_httpx

ruling = client.judge(
    claim="Sally is a pretty cat",
    sources=[
        TextSource.from_text("I have a cat"),
        TextSource.from_text("I only have one pet"),
        TextSource.from_text("My pet is called Sally"),
    ],
)

# ruling.verdict is an overall judgement of the claim's truthfulness
if ruling.verdict is Verdict.SUPPORTS:
    print("Sally really is a pretty cat!")

for statement in ruling.statements:
    # in this case, there are two statements: "Sally is a cat" and "Sally is pretty"
    print(f'The statement "{statement.text}" has been judged as {statement.verdict}')

    for influence in statement.influences:
        print(f"This is because {influence.source} says: {influence.text}")

        if isinstance(influence, TextInfluence):  # currently always true
            print(f"The character IDs are {influence.span[0]} to {influence.span[1]}")

Types

All types are available to import from truthsys. These are:

  • Client and AsyncClient for interacting with the API
  • Influence and TextInfluence - a statement made in a source
  • Ruling - the top-level object returned by the SDK
  • Source and TextSource - a source that could support or refute a claim, e.g. a document
  • Statement - a single statement in a claim
  • Verdict - an enum representing the possible assessments of a claim

Errors

All error types raised by the SDK are available to import from truthsys.errors. Please report unexpected errors.

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

truthsys-0.1.2.dev0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

truthsys-0.1.2.dev0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file truthsys-0.1.2.dev0.tar.gz.

File metadata

  • Download URL: truthsys-0.1.2.dev0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for truthsys-0.1.2.dev0.tar.gz
Algorithm Hash digest
SHA256 79e590f8db8c7173bdadb6adbb8b311d4965e2ce5c52a30d4e7ee79883e09882
MD5 ef89456323d9af443279512aa25dcb4c
BLAKE2b-256 60932cb9715a8e775fe7c422fc5f04c3372a1e51e1251b5f1213457585d35116

See more details on using hashes here.

File details

Details for the file truthsys-0.1.2.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for truthsys-0.1.2.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 d56dfdddce6f4936c817ceb411e4c244906632023fc76a41a34319f3ef8edfc5
MD5 7a3472f73144563c93e55a037a5792b6
BLAKE2b-256 db740c46ee119070e7f43998cfa33450d0c6bc023f3e7dea2cf2cf820ec7fb22

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