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'])
    print("User ID:", filters_data['userId'])
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."
    result = client.filter_text(text_to_filter)

    print("Filtered Text:", result['filteredText'])
    print("Filter Counts:", result['filterCounts'])
    print("Hash Map:", result['hashMap'])
except Exception as e:
    print(f"An error occurred: {str(e)}")

Submitting a Prompt to Selected LLM

To submit a prompt to the selected large language model:

from strongly import APIClient

client = APIClient()

try:
    session = {
        'sessionId': 'your-session-id',
        'sessionName': 'Your Session Name'
    }
    message = "What is the capital of France?"
    model = "gpt-3.5-turbo"

    result = client.submit_prompt(session, message, model)

    # The structure of the result may vary depending on the API response
    print("LLM Response:", result)

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)}")

Creating a New Chat Session

To create a new chat session using the Strongly API:

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 using the Strongly API:

from strongly import APIClient

client = APIClient()

try:
    session_id = "existing-session-id"  # Replace with your actual session ID

    # Delete chat session created
    session_data = client.delete_session(session_id)
    print("Session deleted successfully!")
except Exception as e:
    print(f"An error occurred: {str(e)}")

Renaming an Existing Chat Session

To rename an existing chat session using the Strongly API:

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)}")

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.1.tar.gz (8.2 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.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for strongly-0.1.tar.gz
Algorithm Hash digest
SHA256 005342f34375ba6f6efc79c0af1e2075ae467b5159fc5cfffec67880c1004c36
MD5 b6af0ae45371cd5f726ce364a440672c
BLAKE2b-256 5c86a3dc2a529250c14ece4e75286e2ae899fd4c3bbefc1187b1e5d51a47b852

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for strongly-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb615d7a24470c0b09e8c6a16fa3b79553e187252d52f49d1b4b7859c6d67a74
MD5 91c4d77658dacee6c251e119181c6bb2
BLAKE2b-256 59ab55a11b361dac0b8ae9e561e84eb5ddf3c359402d1b3e0a68b5404721fddd

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