Skip to main content

A Python library for NeuralTrust API

Project description

NeuralTrust Python SDK

The NeuralTrust Python SDK provides a convenient way to interact with the NeuralTrust API for tracing, evaluation sets, knowledge bases, and testsets.

Installation

You can install the NeuralTrust Python SDK using pip:

pip install neuraltrust

Usage

To use the NeuralTrust Python SDK, you need to initialize the client with your API key:

from neuraltrust import NeuralTrust

# Initialize the client with your API key
client = NeuralTrust(api_key="your_api_key_here")

# Optionally, you can specify a custom base URL and SDK version
client = NeuralTrust(api_key="your_api_key_here", base_url="https://custom.api.url", sdk_version="v2")

Tracing

# Create a trace
trace = client.trace(conversation_id="conv123", session_id="sess456")

# Add events to the trace
trace.human("What's the weather like today?")
trace.ai("The weather today is sunny with a high of 75°F.")

# Submit the trace
trace.submit()

Evaluation Sets

# Create an evaluation set
eval_set = client.create_evaluation_set(name="My Eval Set", description="A test evaluation set")

# Get an evaluation set
eval_set = client.get_evaluation_set(id="eval_set_id")

# Delete an evaluation set
client.delete_evaluation_set(id="eval_set_id")

Knowledge Bases

# Create a knowledge base
kb = client.create_knowledge_base(type="document", credentials={"api_key": "your_doc_api_key"})

# Get a knowledge base
kb = client.get_knowledge_base(id="kb_id")

# Delete a knowledge base
client.delete_knowledge_base(id="kb_id")

Testsets

# Create a testset
testset = client.create_testset(name="My Testset", type="adversarial", evaluation_set_id="eval_set_id", knowledge_base_id="kb_id", num_questions=10)

# Get a testset
testset = client.get_testset(id="testset_id")

# Delete a testset
client.delete_testset(id="testset_id")

Configuration

You can configure the SDK using environment variables:

  • NEURALTRUST_API_KEY: Your NeuralTrust API key
  • NEURALTRUST_BASE_URL: Custom base URL for the API (optional)

Advanced Usage

Custom Metadata and User Information

from neuraltrust import User, Metadata

user = User(id="user123", name="John Doe")
metadata = Metadata(app_version="1.0.0", platform="web")

trace = client.trace(user=user, metadata=metadata)

Asynchronous Tracing

The SDK uses a ThreadPoolExecutor for asynchronous tracing. You can adjust the number of workers:

client = NeuralTrust(api_key="your_api_key_here", max_workers=10)

Error Handling

The SDK will raise exceptions for API errors. Make sure to handle these appropriately in your application.

Contributing

Contributions to the NeuralTrust Python SDK are welcome! Please refer to the contribution guidelines for more information.

License

This SDK is distributed under the MIT License.

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

neuraltrust-1.1.2.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

neuraltrust-1.1.2-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

Details for the file neuraltrust-1.1.2.tar.gz.

File metadata

  • Download URL: neuraltrust-1.1.2.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.1 Darwin/24.0.0

File hashes

Hashes for neuraltrust-1.1.2.tar.gz
Algorithm Hash digest
SHA256 23176781ba75496e63787e69545b602a0e4b90be78ac89ae20d0a2f192b0f4f2
MD5 7273fecd91419da5999126fcb6c93b8d
BLAKE2b-256 4272c5c7b655675d52a6f5f6f0ef2288f6aa4046134b0d33e507f1f87e4e18d8

See more details on using hashes here.

File details

Details for the file neuraltrust-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: neuraltrust-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 39.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.1 Darwin/24.0.0

File hashes

Hashes for neuraltrust-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b0808c993026a37c4d99e68a8ca4c1546c91d7b120967267c82fed9f97898cf4
MD5 1ac3e776a02d622e089ba6fd8066fef4
BLAKE2b-256 97dcb19ff87ad3894f2731548f520bc5abb763b61ee12f95a2f23ebc6e3fa24d

See more details on using hashes here.

Supported by

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