Skip to content

Latest commit

 

History

History
266 lines (190 loc) · 8.63 KB

File metadata and controls

266 lines (190 loc) · 8.63 KB

defendai-wozway



Summary

DefendAI Documentation: Wozway Python SDK

Table of Contents

SDK Installation

The SDK can be installed with either pip package manager.

PIP

pip install defendai-wozway

SDK Example Usage

Simple Getting Started Example

from defendai_wozway import Wozway
import os

with Wozway(
    bearer_auth=os.getenv("WOZWAY_BEARER_AUTH", ""),
) as s:
    res = s.activities.get_activities()
    if res is not None:
        print(rs)
      pass
from defendai_wozway import Wozway
import os

with Wozway(
    bearer_auth=os.getenv("WOZWAY_BEARER_AUTH", ""),
) as s:
    res = s.activities.get_activities(request={
        "search": "Prompt description",
        "filters": "{\"verdicts\":[\"BLOCK\"],\"appNames\":[\"openai-app\"],\"modelNames\":[\"openai\"]}",
    })

    if res is not None:
        # handle response
        pass

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme Environment Variable
bearer_auth https HTTP Bearer WOZWAY_BEARER_AUTH

To authenticate with the API the bearer_auth parameter must be set when initializing the SDK client instance. For example:

Available Resources and Operations

Available methods
  • get_activities - Retrieve paginated activity data with filtering, sorting, and search options.

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.

By default, an API error will raise a models.APIError exception, which has the following properties:

Property Type Description
.status_code int The HTTP status code
.message str The error message
.raw_response httpx.Response The raw HTTP response
.body str The response content

When custom error responses are specified for an operation, the SDK may also raise their associated exceptions. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the delete_api_key_async method may raise the following exceptions:

Error Type Status Code Content Type
models.DeleteAPIKeyAPIKeysResponseBody 400 application/json
models.DeleteAPIKeyAPIKeysResponseResponseBody 500 application/json
models.APIError 4XX, 5XX */*

Example

from defendai_wozway import Wozway, models
import os

with Wozway(
    bearer_auth=os.getenv("WOZWAY_BEARER_AUTH", ""),
) as s:
    res = None
    try:
        res = s.api_keys.delete_api_key(api_key="<value>")

        if res is not None:
            # handle response
            pass

    except models.DeleteAPIKeyAPIKeysResponseBody as e:
        # handle e.data: models.DeleteAPIKeyAPIKeysResponseBodyData
        raise(e)
    except models.DeleteAPIKeyAPIKeysResponseResponseBody as e:
        # handle e.data: models.DeleteAPIKeyAPIKeysResponseResponseBodyData
        raise(e)
    except models.APIError as e:
        # handle exception
        raise(e)

Server Selection

Select Server by Index

You can override the default server globally by passing a server index to the server_idx: int optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

# Server
1 https://api.defendai.tech

Example

from defendai_wozway import Wozway
import os

with Wozway(
    server_idx=1,
    bearer_auth=os.getenv("WOZWAY_BEARER_AUTH", ""),
) as s:
    res = s.activities.get_activities(request={
        "search": "Example text",
        "filters": "{\"verdicts\":[\"BLOCK\"],\"appNames\":[\"app1\",\"app2\"],\"modelNames\":[\"modelA\",\"modelB\"]}",
    })

    if res is not None:
        # handle response
        pass

Override Server URL Per-Client

The default server can also be overridden globally by passing a URL to the server_url: str optional parameter when initializing the SDK client instance. For example:

from defendai_wozway import Wozway
import os

with Wozway(
    server_url="http://playground.defendai.tech",
    bearer_auth=os.getenv("WOZWAY_BEARER_AUTH", ""),
) as s:
    res = s.activities.get_activities(request={
        "search": "Example text",
        "filters": "{\"verdicts\":[\"BLOCK\"],\"appNames\":[\"app1\",\"app2\"],\"modelNames\":[\"modelA\",\"modelB\"]}",
    })

    if res is not None:
        # handle response
        pass

Debugging

You can setup your SDK to emit debug logs for SDK requests and responses.

You can pass your own logger class directly into your SDK.

from defendai_wozway import Wozway
import logging

logging.basicConfig(level=logging.DEBUG)
s = Wozway(debug_logger=logging.getLogger("defendai_wozway"))

You can also enable a default debug logger by setting an environment variable WOZWAY_DEBUG to true.