Skip to main content

API Client for Tumeryk_Guardrails

Project description

Metadata-Version: 2.1 Name: tumeryk_guardrails Version: 0.2 Summary: API Client for Tumeryk_Guardrails Author: Tumeryk Author-email: support@tumeryk.com Classifier: Programming Language :: Python :: 3 Classifier: Operating System :: OS Independent Requires-Python: >=3.6 Description-Content-Type: text/markdown Requires-Dist: requests

Metadata-Version: 2.1 Name: tumeryk_guardrails Version: 0.1.97 Summary: API Client for Tumeryk_Guardrails Author: Tumeryk Author-email: support@tumeryk.com Classifier: Programming Language :: Python :: 3 Classifier: Operating System :: OS Independent Requires-Python: >=3.6 Description-Content-Type: text/markdown Requires-Dist: requests

Tumeryk Guardrails Client

The Tumeryk Guardrails Client is a Python package that provides an interface to the Tumeryk Guardrails API. The client allows you to easily use the API from your Python code.

Setup

To install the Tumeryk Guardrails Client, use pip:

pip install tumeryk_guardrails

Example .env File

TUMERYK_USERNAME=sample_username
TUMERYK_PASSWORD=sample_password
TUMERYK_POLICY=hr_policy

Simple Usage

You can use the Tumeryk Guardrails Client with minimal setup. The client will automatically load the configuration from the .env file if it exists. Here's an example of simple usage:

from dotenv import load_dotenv
load_dotenv()

import tumeryk_guardrails


messages = [{"role": "user", "content": "hi"}]

response = tumeryk_guardrails.tumeryk_completions(messages=messages)

print(response)

Manual Usage

The Tumeryk Guardrails Client uses chat.tmryk.com as the default base URL. However, you can change this URL if required. Here's how you can set a custom base URL:

import tumeryk_guardrails

# Set a custom base URL
tumeryk_guardrails.set_base_url("https://your-custom-url.com")

Configuration

The Tumeryk Guardrails Client uses environment variables to store credentials and policy. Here's an example of how to use environment variables:

import tumeryk_guardrails
import os
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Retrieve credentials and policy from environment variables
username = os.getenv("TUMERYK_USERNAME")
password = os.getenv("TUMERYK_PASSWORD")
policy = os.getenv("TUMERYK_POLICY")

# Authenticate with Tumeryk Guardrails
tumeryk_guardrails.login(username, password)

# Retrieve available policies
policies = tumeryk_guardrails.get_policies()
print("Available Policies:", policies)

# Set the chosen policy
tumeryk_guardrails.set_policy(policy)

# Prepare a message for the guard service
messages = [{"role": "user", "content": "Example input to guard"}]

# Send a request to the guard service
response = tumeryk_guardrails.tumeryk_completions(messages)
print("Guard Response:")
print(response)

Response Structure

The guard service returns a structured response. Here's an example:

{
  {
  "messages": [
    {
      "role": "assistant",
      "content": "Hello! It's nice to meet you. How can I assist you today?",
      "stats": {
        "total_calls": 1,
        "total_time": 4.82445502281189,
        "total_tokens": 108,
        "total_prompt_tokens": 79,
        "total_completion_tokens": 29,
        "latencies": [2.410598039627075, 2.4138569831848145],
        "llm_process_time": 2.384185791015625e-07
      }
    }
  ],
  "metrics": {
    "violation": false,
    "jailbreak_detection": false,
    "trust_score": 674,
    "model_score": 674,
    "real_time_score": 0,
    "hallucination_score": 0.0,
    "bias_score": {
      "input": 0,
      "output": 0
    },
    "toxicity_scores": {},
    "llama_guard_allowed": {},
    "llama_guard_categories": {},
    "information": {
      "303": "Low Sensitive Information Disclosure Score"
    }
  },
  "log": {
    "general_stats": {
      "total_time": "2.43s",
      "dialog_rails_time": "99.84%",
      "llm_calls": 2,
      "llm_duration": "4.83s",
      "prompt_tokens": 158,
      "completion_tokens": 58,
      "total_tokens": 216
    },
    "detailed_stats": {
      "dialog": {
        "time": "2.43s",
        "intent_generation": {
          "actions": 1,
          "llm_calls": [
            {
              "time": "2.41s"
            },
            {
              "time": "2.41s"
            }
          ]
        }
      }
    }
  }
}

}

Available Methods

The Tumeryk Guardrails Client provides the following methods to interact with the Tumeryk Guardrails API:

  • login(username, password): Authenticate and store access token.
  • get_policies(): Fetch available policies and return a list.
  • set_policy(config_id): Set the configuration/policy to be used by the user.
  • tumeryk_completions(messages): Send user input to the Guard service.
  • get_base_url(): Get the current base URL.
  • set_base_url(base_url): Set a new base URL.

Dependencies

  • requests: Used for making HTTP requests to the API.

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

tumeryk_guardrails-0.2.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

tumeryk_guardrails-0.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file tumeryk_guardrails-0.2.tar.gz.

File metadata

  • Download URL: tumeryk_guardrails-0.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.16

File hashes

Hashes for tumeryk_guardrails-0.2.tar.gz
Algorithm Hash digest
SHA256 d1cad33799fbe85e7a198792e5b25560d49ca8985e5eace75f72cf2a81b1158b
MD5 e0f0449f5bfcfe4af0f683243e4d8f55
BLAKE2b-256 432d36d5526ac4dc9c43cc6c26b3a9bea2247e324efa627ca8ee5cdd0acb3d30

See more details on using hashes here.

File details

Details for the file tumeryk_guardrails-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for tumeryk_guardrails-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2132c54d4bd5e5111ca61acfbe112e710522c23ce98d8c5e8b40dfb746aafc80
MD5 b6895558c53b8833b0010af606480e7d
BLAKE2b-256 714bc43176dbef486864372a1e3d36d8f30f806dbd93f0939ff87625127fca82

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