Skip to main content

A Python client for the Strongly.AI API

Project description

strongly

Description

Strongly is a powerful and user-friendly Python client for interacting with the Strongly.AI's API. This package simplifies the process of authentication, session management, and making API calls, allowing you to focus on utilizing the data and functionality provided by our service.

Key Features

  • Automatic Authentication: Handles API key authentication and session token management behind the scenes.
  • Session Persistence: Maintains and renews sessions automatically, reducing unnecessary authentication calls.
  • Environment-based Configuration: Easily configure API host and key using environment variables.
  • Intuitive Interface: Provides a clean, Pythonic interface for all API endpoints.
  • Error Handling: Custom exceptions for clearer error management.
  • Flexible: Supports all API methods with a consistent interface.

Use Cases

  • Retrieve data from Strongly.AI with minimal setup.
  • Integrate Strongly.AI functionality into your Python applications, scripts, or data pipelines.
  • Automate tasks and workflows that interact with Strongly.AI.
  • Build custom tools and dashboards on top of Strongly.AI data.

Whether you're a data scientist, software developer, or automation engineer, strongly provides a seamless way to leverage the power of Strongly.AI in your Python projects.

Install instructions

To use this package, users need to:

Install strongly and its dependencies:

pip install strongly

Create a .env file in their project directory with their API host and key:

API_HOST=https://your-api-host.com
API_KEY=their-api-key-here

API Keys are created in the Strongly.AI application.

Usage

The following API logic applies to V1 of the RestAPI.

Fetching Models

To fetch models available to account from the Strongly API:

from strongly import APIClient

client = APIClient()

try:
    models_data = client.get_models()
    print("Models:", models_data['models'])
    print("User ID:", models_data['userId'])
except Exception as e:
    print(f"An error occurred: {str(e)}")

Fetching Applied Filters

To fetch the applied filters from the Strongly API:

from strongly import APIClient

client = APIClient()

try:
    filters_data = client.get_applied_filters()
    print("Applied Filters:", filters_data['filters'])
except Exception as e:
    print(f"An error occurred: {str(e)}")

Creating a New Chat Session

To create a new chat session:

from strongly import APIClient

client = APIClient()

try:
    session_data = client.create_session("My New Chat Session")
    print("Session created successfully!")
    print("Session ID:", session_data['sessionId'])
except Exception as e:
    print(f"An error occurred: {str(e)}")

Deleting An Existing Session

To delete an existing session:

from strongly import APIClient

client = APIClient()

try:
    session_id = "existing-session-id"  # Replace with your actual session ID
    result = client.delete_session(session_id)
    print("Session deleted successfully!")
    print("Message:", result['message'])
except Exception as e:
    print(f"An error occurred: {str(e)}")

Renaming an Existing Chat Session

To rename an existing chat session:

from strongly import APIClient

client = APIClient()

try:
    session_id = "existing-session-id"  # Replace with your actual session ID
    new_name = "My Renamed Chat Session"
    result = client.rename_session(session_id, new_name)
    print("Session renamed successfully!")
    print("Message:", result['message'])
except Exception as e:
    print(f"An error occurred: {str(e)}")

Retrieving Session Messages

To retrieve messages for a specific chat session:

from strongly import APIClient

client = APIClient()

try:
    session_id = "your-session-id"
    messages = client.get_session_messages(session_id)
    print("Session Messages:", messages)
except Exception as e:
    print(f"An error occurred: {str(e)}")

Filtering Text

To filter text using applicable filters:

from strongly import APIClient

client = APIClient()

try:
    text_to_filter = "This is a confidential message containing a sensitive email: info@strongly.ai."
    session_id = "your-session-id"
    result = client.filter_text(text_to_filter, session_id)

    print("Filtered Text:", result['filteredText'])
    print("Prompt Text:", result['promptText'])
    print("Filter:", result['filter'])
    print("Message ID:", result['messageId'])
except Exception as e:
    print(f"An error occurred: {str(e)}")

Submitting a Message to Selected LLM

To submit a message to the selected large language model:

from strongly import APIClient

client = APIClient()

try:
    model = {
        'model': 'gpt-3.5-turbo',
        'modelLabel': 'GPT-3.5 Turbo',
        'messageId': 'unique-message-id',
        'session': {'sessionId': 'your-session-id', 'sessionName': 'Your Session Name'},
        'temperature': 0.7,
        'max_tokens': 1024
    }
    prompt = {
        'system': 'You are a helpful assistant.',
        'assistant': '',
        'contextPrompts': [],
        'message': "What is the capital of France?"
    }
    filter_data = {
        'prompt': {
            'filterCounts': {},
            'alerts': [],
            'alertReasons': [],
            'blocked': [],
            'blockedReasons': [],
            'hashed': [],
            'isBlocked': False
        },
        'response': {
            'filterCounts': {},
            'alerts': [],
            'alertReasons': [],
            'blocked': [],
            'blockedReasons': [],
            'hashed': [],
            'isBlocked': False
        }
    }

    result = client.submit_message(model, prompt, filter_data)
    print("LLM Response:", result['content'])
except Exception as e:
    print(f"An error occurred: {str(e)}")

Checking Token Usage

To check the token usage for the current user:

from strongly import APIClient

client = APIClient()

try:
    token_usage = client.check_token_usage()
    print("Token Usage Information:")
    print(f"Is Over Limit: {token_usage['isOverLimit']}")
    print(f"Is Restricted: {token_usage['isRestricted']}")
    print(f"User Token Usage: {token_usage['userTokenUsage']}")
    print(f"Plan Token Limit: {token_usage['planTokenLimit']}")
    print(f"Company Tokens Available: {token_usage['companyTokensAvailable']}")
    print(f"Purchased Tokens: {token_usage['purchasedTokens']}")
except Exception as e:
    print(f"An error occurred: {str(e)}")

Retrieving Sessions

To retrieve sessions within a specified time range:

from strongly import APIClient

client = APIClient()

try:
    start_time = "2023-01-01T00:00:00Z"
    end_time = "2023-12-31T23:59:59Z"
    sessions = client.get_sessions(start_time, end_time)
    print("Sessions:", sessions['sessions'])
    print("Is Admin:", sessions['isAdmin'])
except Exception as e:
    print(f"An error occurred: {str(e)}")

User Authentication

Login with Email and Password

To login with email and password:

from strongly import APIClient

client = APIClient()

try:
    result = client.login("user@example.com", "password123")
    print("User ID:", result['userId'])
    print("Auth Token:", result['authToken'])
except Exception as e:
    print(f"An error occurred: {str(e)}")

Login with Google SSO

To login with Google SSO:

from strongly import APIClient

client = APIClient()

try:
    result = client.login_with_google("google-access-token")
    print("User ID:", result['userId'])
    print("Auth Token:", result['authToken'])
except Exception as e:
    print(f"An error occurred: {str(e)}")

Register a New User

To register a new user:

from strongly import APIClient

client = APIClient()

try:
    result = client.register("newuser@example.com", "password123", {"name": "New User"})
    print("User ID:", result['userId'])
    print("Auth Token:", result['authToken'])
except Exception as e:
    print(f"An error occurred: {str(e)}")

Logout

To logout the current user:

from strongly import APIClient

client = APIClient()

try:
    result = client.logout()
    print("Logout Message:", result['message'])
except Exception as e:
    print(f"An error occurred: {str(e)}")

Testing

We strive to maintain high code quality and reliability in this package. To this end, we've included a comprehensive test suite. Here's how you can run the tests and contribute to maintaining the package's quality.

Prerequisites

Before running the tests, make sure you have the required testing dependencies installed. You can install them using pip:

pip install pytest pytest-cov

Running the Tests

To run the entire test suite, follow these steps:

Open a terminal or command prompt. Navigate to the root directory of the package. Run the following command:

pytest

This command will discover and run all the tests in the tests/ directory.

Understanding Test Output

The test output will show you:

  • Which tests passed (marked with . or PASSED)
  • Which tests failed (marked with F or FAILED)
  • The overall test summary
  • Code coverage report

Running Specific Tests

If you want to run a specific test file or test function, you can do so by specifying the path:

# Run tests in a specific file
pytest tests/strongly.py

# Run a specific test function
pytest tests/strongly.py::test_authenticate_success

Code Coverage

Our pytest.ini file is configured to run coverage reports automatically. After running the tests, you'll see a coverage report in the console output. For a more detailed report, you can run:

pytest --cov-report=html

This will generate an HTML coverage report in the htmlcov/ directory. Open htmlcov/index.html in a web browser to view it.

Continuous Integration

We use GitHub Actions for continuous integration. Every pull request is automatically tested to ensure that new changes don't break existing functionality.

Contributing to Tests

If you're adding new features or fixing bugs, please consider adding appropriate tests. This helps maintain the package's reliability and makes it easier for others to understand and verify your changes.

If you have any questions about testing or need help interpreting test results, please don't hesitate to reach out to our support team.

Need Help? We're Here for You!

We're thrilled you're using our package and want to ensure you have the best experience possible. If you have any questions, run into any issues, or just want to share your feedback, we'd love to hear from you!

📧 Contact us at: info@strongly.ai

Whether you're a coding wizard or just getting started, our team is always happy to assist. Don't hesitate to reach out – your input helps us improve and grow!

Thank you for being part of our community. We truly appreciate your support and look forward to hearing from you!

Happy coding! 🚀✨

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

strongly-0.4.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

strongly-0.4-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file strongly-0.4.tar.gz.

File metadata

  • Download URL: strongly-0.4.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for strongly-0.4.tar.gz
Algorithm Hash digest
SHA256 a8dba1a88566ff63f6d760f57ebea3c66ef447cf964c2ff0c0d78a2d5f332b41
MD5 6090b43f89c66b5f0c4bed0318fef4ca
BLAKE2b-256 df66e5aba036a52c5240a05addc929e023fc70586434bb5491e1416e0047879a

See more details on using hashes here.

File details

Details for the file strongly-0.4-py3-none-any.whl.

File metadata

  • Download URL: strongly-0.4-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for strongly-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 993426cd0cd92fe3629fec69416fe25b81a7248cee5cb8c215ddc7aad0261feb
MD5 8ec674e1666eaa525517c5f04d0894cf
BLAKE2b-256 8c437e819000ffa11397d9e16b9b7442135629e44beb2c3b9e86ef50e717b9df

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