### Complete Migration Example: After TrustwiseClient Source: https://trustwiseai.github.io/trustwise/_sources/sdk_migration.rst.txt Shows the equivalent setup and usage with TrustwiseClient, including accessing other platform features. ```python import os from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.platform import TrustwiseClient config = TrustwiseConfig(api_key=os.environ["TW_API_KEY"]) client = TrustwiseClient(config) result = client.metrics.faithfulness( query="What is the capital of France?", response="The capital of France is Paris.", context=[{"chunk_text": "Paris is the capital of France.", "chunk_id": "1"}], ) print(result.score) # Plus: access agents, policies, guardrails, evaluations, etc. agents = client.agents.list(limit=5) ``` -------------------------------- ### Complete Migration Example: Before TrustwiseSDK Source: https://trustwiseai.github.io/trustwise/_sources/sdk_migration.rst.txt Illustrates the complete setup and usage of TrustwiseSDK for evaluating metric faithfulness. ```python import os from trustwise.sdk import TrustwiseSDK from trustwise.sdk.config import TrustwiseConfig config = TrustwiseConfig(api_key=os.environ["TW_API_KEY"]) sdk = TrustwiseSDK(config) result = sdk.metrics.faithfulness.evaluate( query="What is the capital of France?", response="The capital of France is Paris.", context=[{"chunk_text": "Paris is the capital of France.", "chunk_id": "1"}], ) print(result.score) ``` -------------------------------- ### Install Trustwise SDK using pip Source: https://trustwiseai.github.io/trustwise/_sources/installation.rst.txt Use this command to install the Trustwise SDK and its dependencies. ```bash pip install trustwise ``` -------------------------------- ### TrustwiseClient Quickstart Source: https://trustwiseai.github.io/trustwise/_sources/platform.rst.txt Demonstrates basic usage of TrustwiseClient for listing agents and evaluating metrics. ```APIDOC ## Quickstart .. code-block:: python import os from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.platform import TrustwiseClient config = TrustwiseConfig(api_key=os.environ["TW_API_KEY"]) client = TrustwiseClient(config) # List agents within a project agents = client.agents.list("my-project-id", limit=5) # Evaluate faithfulness result = client.metrics.faithfulness( query="What is the capital of France?", response="The capital of France is Paris.", context=[{"chunk_text": "Paris is the capital.", "chunk_id": "1"}], ) ``` -------------------------------- ### Quickstart: Initialize Client and List Agents Source: https://trustwiseai.github.io/trustwise/platform.html Initialize the TrustwiseClient with configuration and list agents within a project. Requires TW_API_KEY environment variable. ```python import os from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.platform import TrustwiseClient config = TrustwiseConfig(api_key=os.environ["TW_API_KEY"]) client = TrustwiseClient(config) # List agents within a project agents = client.agents.list("my-project-id", limit=5) # Evaluate faithfulness result = client.metrics.faithfulness( query="What is the capital of France?", response="The capital of France is Paris.", context=[{"chunk_text": "Paris is the capital.", "chunk_id": "1"}], ) ``` -------------------------------- ### Initialize Legacy TrustwiseSDK Source: https://trustwiseai.github.io/trustwise/_sources/usage.rst.txt The TrustwiseSDK is deprecated. Use TrustwiseClient instead. This example shows the legacy initialization process. ```python import os from trustwise.sdk import TrustwiseSDK from trustwise.sdk.config import TrustwiseConfig # Configure using environment variables os.environ["TW_API_KEY"] = "your-api-key" os.environ["TW_BASE_URL"] = "https://api.trustwise.ai" config = TrustwiseConfig() # Or configure directly # config = TrustwiseConfig( # api_key="your-api-key", # base_url="https://api.trustwise.ai" # ) # Initialize the SDK trustwise = TrustwiseSDK(config) ``` -------------------------------- ### Initialize TrustwiseClient and List Agents Source: https://trustwiseai.github.io/trustwise/_sources/platform.rst.txt Initialize the TrustwiseConfig with an API key and create a TrustwiseClient instance. This example demonstrates listing agents within a specified project. ```python import os from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.platform import TrustwiseClient config = TrustwiseConfig(api_key=os.environ["TW_API_KEY"]) client = TrustwiseClient(config) # List agents within a project agents = client.agents.list("my-project-id", limit=5) ``` -------------------------------- ### Complete Migration Example: Before TrustwiseSDK Source: https://trustwiseai.github.io/trustwise/sdk_migration.html This code block demonstrates the usage of the deprecated TrustwiseSDK for evaluating faithfulness metrics. ```python import os from trustwise.sdk import TrustwiseSDK from trustwise.sdk.config import TrustwiseConfig config = TrustwiseConfig(api_key=os.environ["TW_API_KEY"]) sdk = TrustwiseSDK(config) result = sdk.metrics.faithfulness.evaluate( query="What is the capital of France?", response="The capital of France is Paris.", context=[{"chunk_text": "Paris is the capital of France.", "chunk_id": "1"}], ) print(result.score) ``` -------------------------------- ### Policies Source: https://trustwiseai.github.io/trustwise/_sources/platform.rst.txt Evaluate policies in batch or get recommendations based on tags. ```APIDOC ## Evaluate Policies in Batch ### Description Evaluates an input against multiple policies simultaneously. ### Method `client.policies.evaluate_batch ### Parameters - **policy_ids** (list[str]) - Required - A list of policy IDs to evaluate against. - **input** (dict) - Required - The input data for evaluation, typically containing a 'text' field. ### Request Example ```python results = client.policies.evaluate_batch( policy_ids=["policy-1", "policy-2"], input={"text": "test input"}, ) ``` ## Get Policy Recommendations ### Description Retrieves policy recommendations based on specified tags. ### Method `client.policies.recommend ### Parameters - **tags** (list[str]) - Required - A list of tags to filter recommendations. ### Request Example ```python recs = client.policies.recommend(tags=["safety", "pii"]) ``` ``` -------------------------------- ### List Supported Auth Schemas Source: https://trustwiseai.github.io/trustwise/_sources/platform.rst.txt Get a list of supported authentication schemas for runtime providers. This helps in configuring secure agent deployments. ```python # List supported auth schemas schemas = client.runtime_providers.auth_schemas() ``` -------------------------------- ### Manage Policies: List, Evaluate, and Recommend Source: https://trustwiseai.github.io/trustwise/platform.html List policies, evaluate content against single or multiple policies, and get policy recommendations based on tags. Requires `policy_id` for evaluation. ```python # List policies policies = client.policies.list() # Evaluate content against a policy result = client.policies.evaluate(policy_id, input="test input") # Evaluate against multiple policies in one call results = client.policies.evaluate_batch( policy_ids=["policy-1", "policy-2"], input={"text": "test input"}, ) # Get policy recommendations based on tags recs = client.policies.recommend(tags=["safety", "pii"]) ``` -------------------------------- ### Get Available API Versions Source: https://trustwiseai.github.io/trustwise/versioning.html Retrieve a list of all available API versions supported by the SDK. Ensure TrustwiseSDK and TrustwiseConfig are imported and initialized. ```python from trustwise.sdk import TrustwiseSDK from trustwise.sdk.config import TrustwiseConfig config = TrustwiseConfig(api_key="your-api-key") trustwise = TrustwiseSDK(config) # Get available versions versions = trustwise.get_versions() ``` -------------------------------- ### Accessing Agents with TrustwiseClient Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/client.html Demonstrates how to interact with the agents sub-client to retrieve and list agents within a specific project. The `get` method fetches a single agent, while `list` retrieves multiple agents, supporting search and limiting results. By default, methods return the inner data model. ```python # Agents are now project-scoped agent = client.agents.get("project-id", "agent-id") print(agent.name) agents = client.agents.list("project-id", search="my-bot", limit=5) for a in agents: print(a.name) ``` -------------------------------- ### Get Available API Versions Source: https://trustwiseai.github.io/trustwise/_sources/versioning.rst.txt Retrieve a list of all available API versions supported by the Trustwise SDK. Ensure TrustwiseSDK and TrustwiseConfig are imported and the SDK is initialized with your API key. ```python from trustwise.sdk import TrustwiseSDK from trustwise.sdk.config import TrustwiseConfig config = TrustwiseConfig(api_key="your-api-key") trustwise = TrustwiseSDK(config) # Get available versions versions = trustwise.get_versions() ``` -------------------------------- ### Deploy Agent to AI Gateway and Get Status History Source: https://trustwiseai.github.io/trustwise/_sources/platform.rst.txt Deploy an agent to the AI Gateway with specified models and retrieve its status history. Both actions are project-scoped. ```python # Deploy to AI Gateway deploy = client.agents.deploy_gateway(project_id, agent["id"], models=["gpt-4.1-nano"]) # Status history history = client.agents.status_history(project_id, agent["id"]) ``` -------------------------------- ### Carbon Footprint Evaluation Example Response Source: https://trustwiseai.github.io/trustwise/v4_metrics.html An example of the JSON response structure detailing the carbon footprint, including total and component breakdowns. ```json { "carbon": { "value": 0.0011949989480068127, "unit": "kg_co2e" }, "components": [ { "component": "operational_gpu", "carbon": { "value": 0.0, "unit": "kg_co2e" } }, { "component": "operational_cpu", "carbon": { "value": 0.00021294669026962343, "unit": "kg_co2e" } }, { "component": "embodied_cpu", "carbon": { "value": 0.0009820522577371892, "unit": "kg_co2e" } } ] } ``` -------------------------------- ### PlatformHTTP GET Method Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/_http.html Performs an HTTP GET request to the specified path with optional query parameters. It utilizes the internal _request method for execution. ```python def get(self, path: str, **params: Any) -> dict[str, Any]: return self._request("GET", path, params=params or None) ``` -------------------------------- ### TrustwiseClient Initialization and Usage Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/client.html Demonstrates how to initialize the TrustwiseClient with configuration and access various platform resources like agents, gateway, guardrails, and more. It also shows how to retrieve agents by project and agent ID, list agents with search parameters, and access raw API responses. ```APIDOC ## TrustwiseClient ### Description User-friendly client for the Trustwise Harmony Platform API. Provides access to all platform resources through sub-clients: ``agents``, ``gateway``, ``guardrails``, ``policies``, ``evaluations``, ``evaluators``, ``organizations``, ``projects``, ``risk_engine``, ``generation``, ``metrics``, ``events``, ``subscriptions``, and ``runtime_providers``. ### Example ```python from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.platform import TrustwiseClient config = TrustwiseConfig(api_key="tw-...") client = TrustwiseClient(config) # Agents are now project-scoped agent = client.agents.get("project-id", "agent-id") print(agent.name) agents = client.agents.list("project-id", search="my-bot", limit=5) for a in agents: print(a.name) # Raw — returns the full API envelope resp = client.agents.get("project-id", "agent-id", raw=True) print(resp["success"], resp["data"]["name"]) ``` ### Parameters - **config** (TrustwiseConfig) - Trustwise configuration instance. - **timeout** (int, optional) - HTTP request timeout in seconds. Defaults to 30. ``` -------------------------------- ### Get Agent Status History Source: https://trustwiseai.github.io/trustwise/api.html Retrieve the status history for an agent. Supports filtering and pagination through `kwargs`. Set `raw=True` to get the full API envelope. ```python status_history = client.agents.status_history(project_id="project-id", agent_id="agent-id") ``` -------------------------------- ### Initialize TrustwiseSDK and Evaluate Faithfulness (Sync) Source: https://trustwiseai.github.io/trustwise/_sources/v4_metrics.rst.txt Demonstrates initializing the TrustwiseSDK with configuration and evaluating the faithfulness metric using synchronous calls. Ensure you have your API key and necessary types imported. ```python from trustwise.sdk import TrustwiseSDK from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.metrics.v4.types import ContextChunk config = TrustwiseConfig(api_key="your-api-key") trustwise = TrustwiseSDK(config) # v4 context format context = [ ContextChunk(chunk_text="Paris is the capital of France.", chunk_id="doc:idx:1") ] # v4 metric calls (now default) result = trustwise.metrics.faithfulness.evaluate( query="What is the capital of France?", response="The capital of France is Paris.", context=context ) ``` -------------------------------- ### get() method Source: https://trustwiseai.github.io/trustwise/genindex.html The generic get() method is available across multiple resource classes for retrieving specific items. It is used in AgentResource, EvaluationResource, EventResource, GuardrailResource, OrganizationResource, PolicyResource, ProjectResource, RuntimeProviderResource, and SubscriptionResource. ```APIDOC ## GET ### Description Retrieves a specific resource. ### Method GET ### Endpoint Not specified, depends on the resource. ### Parameters None explicitly defined in the source. ### Request Example None provided. ### Response None explicitly defined. ``` -------------------------------- ### Initialize Trustwise SDK Async Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/async_sdk.html Initialize the Trustwise SDK asynchronously with configuration. This sets up the HTTP client and metrics access. ```python from trustwise.sdk.async_sdk import TrustwiseSDKAsync from trustwise.config import TrustwiseConfig config = TrustwiseConfig(api_key="YOUR_API_KEY") sdk = TrustwiseSDKAsync(config) ``` -------------------------------- ### Get Organization Logo Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/client.html Retrieves the logo for a specific organization. ```APIDOC ## Get Organization Logo ### Description Get the logo for an organization. ### Method GET ### Endpoint /v1/organizations/{org_id}/logo ### Parameters #### Path Parameters - **org_id** (str) - Required - Unique organization identifier. #### Query Parameters - **raw** (bool) - Optional - Return the full API envelope. ### Response #### Success Response (200) - **data** (LogoResponse) - The logo details if raw=False. - **envelope** (dict) - The full API envelope if raw=True. ``` -------------------------------- ### Get Guardrail Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/client.html Retrieves a single guardrail by its unique identifier. ```APIDOC ## Get Guardrail ### Description Get a single guardrail by ID. ### Method GET ### Endpoint /v1/guardrails/{guardrail_id} ### Parameters #### Path Parameters - **guardrail_id** (str) - Required - Unique guardrail identifier. #### Query Parameters - **raw** (bool) - Optional - Return the full API envelope. ### Response #### Success Response (200) - **guardrail** (dict) - The guardrail object. - **raw** (dict) - Full API envelope if raw=True. ``` -------------------------------- ### TrustwiseClient Initialization and Basic Usage Source: https://trustwiseai.github.io/trustwise/platform.html Initialize the TrustwiseClient with configuration and demonstrate listing agents and evaluating faithfulness. ```APIDOC ## Initialization and Basic Usage ### Description Initialize the `TrustwiseClient` and demonstrate common operations like listing agents and evaluating metrics. ### Code Example ```python import os from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.platform import TrustwiseClient config = TrustwiseConfig(api_key=os.environ["TW_API_KEY"]) client = TrustwiseClient(config) # List agents within a project agents = client.agents.list("my-project-id", limit=5) # Evaluate faithfulness result = client.metrics.faithfulness( query="What is the capital of France?", response="The capital of France is Paris.", context=[{"chunk_text": "Paris is the capital.", "chunk_id": "1"}], ) ``` ``` -------------------------------- ### Initialize and Use TrustwiseClient Source: https://trustwiseai.github.io/trustwise/api.html Demonstrates how to initialize the TrustwiseClient with configuration and access agents within a project. Use this client for all new development to interact with the Trustwise Platform API. ```python from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.platform import TrustwiseClient config = TrustwiseConfig(api_key="tw-...") client = TrustwiseClient(config) # Agents are now project-scoped agent = client.agents.get("project-id", "agent-id") print(agent.name) agents = client.agents.list("project-id", search="my-bot", limit=5) for a in agents: print(a.name) ``` -------------------------------- ### Get Provider Schemas Source: https://trustwiseai.github.io/trustwise/api.html Fetches the configuration schemas for all guardrail providers. ```APIDOC ## provider_schemas ### Description Get the configuration schemas for all guardrail providers. ### Return Type `dict`[`str`, `Any`] ### Returns Configuration schemas for all guardrail providers. ``` -------------------------------- ### Get Policy by ID Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/client.html Retrieves a single policy by its unique identifier. ```APIDOC ## Get Policy by ID ### Description Get a single policy by ID. ### Method GET ### Endpoint /v1/policies/{policy_id} ### Parameters #### Path Parameters - **policy_id** (str) - Required - Unique policy identifier. #### Query Parameters - **raw** (bool) - Optional - Return the full API envelope. ``` -------------------------------- ### Initialize TrustwiseClient Source: https://trustwiseai.github.io/trustwise/_sources/usage.rst.txt Use TrustwiseClient for new development to access all platform APIs. Configure using environment variables or directly with API key and base URL. ```python import os from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.platform import TrustwiseClient # Configure using environment variables config = TrustwiseConfig(api_key=os.environ["TW_API_KEY"]) # Or configure directly # config = TrustwiseConfig( # api_key="your-api-key", # base_url="https://api.trustwise.ai" # ) client = TrustwiseClient(config) # Evaluate a metric result = client.metrics.faithfulness( query="What is the capital of France?", response="The capital of France is Paris.", context=[{"chunk_text": "Paris is the capital of France.", "chunk_id": "doc:idx:1"}], ) # Manage agents agents = client.agents.list(limit=5) # Manage guardrails guardrails = client.guardrails.list() ``` -------------------------------- ### Get Guardrail Provider Schemas Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/client.html Retrieves the configuration schemas for all guardrail providers. ```APIDOC ## Get Guardrail Provider Schemas ### Description Get the configuration schemas for all guardrail providers. ### Method GET ### Endpoint /v1/guardrail-provider-schemas ### Response #### Success Response (200) - **schemas** (dict) - A dictionary containing configuration schemas for each provider. ``` -------------------------------- ### Get Guardrail Evaluation Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/client.html Retrieves a specific guardrail evaluation result by its IDs. ```APIDOC ## Get Guardrail Evaluation ### Description Get a specific guardrail evaluation result. ### Method GET ### Endpoint /v1/guardrails/{guardrail_id}/evaluations/{evaluation_id} ### Parameters #### Path Parameters - **guardrail_id** (str) - Required - Unique guardrail identifier. - **evaluation_id** (str) - Required - Unique evaluation identifier. #### Query Parameters - **raw** (bool) - Optional - Return the full API envelope. ### Response #### Success Response (200) - **result** (GuardrailEvaluationResult) - The guardrail evaluation result. - **raw** (dict) - Full API envelope if raw=True. ``` -------------------------------- ### Run First Evaluation and List Agents with Trustwise SDK Source: https://trustwiseai.github.io/trustwise/_sources/index.rst.txt Set up the Trustwise client with your API key and run your first evaluation for faithfulness. This snippet also shows how to list agents. Ensure the TW_API_KEY environment variable is set. ```python import os from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.platform import TrustwiseClient config = TrustwiseConfig(api_key=os.environ["TW_API_KEY"]) client = TrustwiseClient(config) # Evaluate faithfulness result = client.metrics.faithfulness( query="What is the capital of France?", response="The capital of France is Paris.", context=[{"chunk_text": "Paris is the capital of France.", "chunk_id": "doc:idx:1"}], ) print(result.score) # List agents agents = client.agents.list(limit=5) ``` -------------------------------- ### Initialize TrustwiseConfig with Environment Variables Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/config.html Instantiate TrustwiseConfig without arguments to automatically load API key and base URL from environment variables TW_API_KEY and TW_BASE_URL. Defaults to 'https://api.trustwise.ai' if TW_BASE_URL is not set. ```python >>> from trustwise.sdk.config import TrustwiseConfig >>> # Using environment variables >>> config = TrustwiseConfig() ``` -------------------------------- ### Get Agent Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/client.html Retrieves a single agent by its unique identifier within a project. ```APIDOC ## get ### Description Get a single agent by ID. ### Method GET ### Endpoint /projects/{project_id}/agents/{agent_id} ### Parameters #### Path Parameters - **project_id** (str) - Required - Project identifier. - **agent_id** (str) - Required - Unique agent identifier. #### Query Parameters - **raw** (bool) - Optional - Return the full API envelope. ### Response #### Success Response (200) - **agent** (dict[str, Any]) - Dictionary representing the agent. - **envelope** (dict[str, Any]) - The raw API envelope if *raw* is True. ``` -------------------------------- ### Get Classification Results Source: https://trustwiseai.github.io/trustwise/api.html Retrieves the classification results for a specific evaluation within a project. ```APIDOC ## classification ### Description Get classification results for an evaluation. ### Parameters * **project_id** (str) - Project identifier. * **evaluation_id** (str) - Unique evaluation identifier. ### Return Type `dict`[`str`, `Any`] ``` -------------------------------- ### Initialize TrustwiseSDK Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/sdk.html Initializes the Trustwise SDK with a configuration object. This class is deprecated; use TrustwiseClient instead. ```python import warnings from trustwise.sdk.client import TrustwiseHTTPClient from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.metrics import Metrics [docs] class TrustwiseSDK: """ Main SDK class for Trustwise API access. Provides access to all metrics through version-specific paths. .. deprecated:: Use :class:`trustwise.sdk.platform.client.TrustwiseClient` instead. ``TrustwiseClient`` is a superset of this SDK and covers all metrics, guardrails, policies, and platform APIs. """ [docs] def __init__(self, config: TrustwiseConfig) -> None: """ Initialize the Trustwise SDK with path-based versioning support. Args: config: Trustwise configuration instance. """ warnings.warn( "TrustwiseSDK is deprecated and will be removed in a future version. " "Please migrate to TrustwiseClient for continued support and enhanced features. " "See the migration guide for more details: " "https://trustwiseai.github.io/trustwise/sdk_migration.html", FutureWarning, stacklevel=2, ) self.client = TrustwiseHTTPClient(config) self.metrics = Metrics(self.client) ``` -------------------------------- ### Initialize TrustwiseSDKAsync and Evaluate Faithfulness (Async) Source: https://trustwiseai.github.io/trustwise/_sources/v4_metrics.rst.txt Shows how to set up the asynchronous TrustwiseSDK and evaluate the faithfulness metric using await. This is suitable for non-blocking operations in async applications. ```python import asyncio from trustwise.sdk import TrustwiseSDKAsync from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.metrics.v4.types import ContextChunk async def main(): config = TrustwiseConfig(api_key="your-api-key") trustwise = TrustwiseSDKAsync(config) context = [ ContextChunk(chunk_text="Paris is the capital of France.", chunk_id="doc:idx:1") ] result = await trustwise.metrics.faithfulness.evaluate( query="What is the capital of France?", response="The capital of France is Paris.", context=context ) asyncio.run(main()) ``` -------------------------------- ### Get Agent Status History Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/client.html Retrieves the historical status records for a specific agent. ```APIDOC ## GET /projects/{project_id}/agents/{agent_id}/status ### Description Get the status history for an agent. ### Method GET ### Endpoint /projects/{project_id}/agents/{agent_id}/status ### Parameters #### Path Parameters - **project_id** (str) - Required - Project identifier. - **agent_id** (str) - Required - Unique agent identifier. #### Query Parameters - **limit** (int) - Optional - Maximum number of records to return. - **offset** (int) - Optional - Number of records to skip. ### Response #### Success Response (200) - **AgentStatusHistory** (object) - Parsed agent status history. #### Response Example ```json { "history": [ { "timestamp": "2023-10-27T10:00:00Z", "status": "online", "reason": "" } ], "total": 1 } ``` ``` -------------------------------- ### Use Server-Side Guardrails with TrustwiseClient Source: https://trustwiseai.github.io/trustwise/_sources/sdk_migration.rst.txt Demonstrates how to create and evaluate against platform-managed guardrails using TrustwiseClient, replacing the old local guardrail system. ```python # Create a guardrail on the platform (once) guardrail = client.guardrails.create( name="My Guardrail", evaluators=[ {"evaluator": "faithfulness", "threshold": 0.8}, {"evaluator": "toxicity", "threshold": 0.3}, ], ) # Evaluate against it result = client.guardrails.evaluate( guardrail["id"], input="user message", output="assistant reply" ) ``` -------------------------------- ### Risk Engine Source: https://trustwiseai.github.io/trustwise/_sources/platform.rst.txt Interact with the risk engine to get questionnaire scaffolds and classify risk. ```APIDOC ## Get Risk Engine Scaffold ### Description Retrieves the questionnaire scaffold for a specified risk engine version. ### Method `client.risk_engine.scaffold ### Parameters - **version** (str) - Required - The version of the risk engine (e.g., "arc-v3"). ### Request Example ```python scaffold = client.risk_engine.scaffold("arc-v3") ``` ## Classify Risk ### Description Classifies risk based on provided answers for a given risk engine version. ### Method `client.risk_engine.classify ### Parameters - **version** (str) - Required - The version of the risk engine (e.g., "arc-v3"). - **answers** (dict) - Required - A dictionary of answers to the questionnaire. ### Request Example ```python result = client.risk_engine.classify("arc-v3", answers={...}) ``` ``` -------------------------------- ### Get Specific Event Source: https://trustwiseai.github.io/trustwise/_sources/platform.rst.txt Retrieve details for a single event using its unique ID. ```python # Get a specific event event = client.events.get("event-id") ``` -------------------------------- ### PlatformHTTP Initialization Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/_http.html Initializes the PlatformHTTP client with configuration and sets up the requests session with necessary headers for authentication and content negotiation. ```python def __init__(self, config: TrustwiseConfig, *, timeout: int = 30) -> None: self._base = config.base_url.rstrip("/") self._timeout = timeout self._session = requests.Session() self._session.headers.update({ "Authorization": f"Bearer {config.api_key}", "Content-Type": "application/json", "Accept": "application/json", }) logger.debug("Initialized PlatformHTTP with base URL: %s", self._base) ``` -------------------------------- ### TrustwiseClient Initialization and Usage Source: https://trustwiseai.github.io/trustwise/api.html The TrustwiseClient is the recommended client for new development, offering a unified interface to platform resources. It provides access to agents, gateway, guardrails, policies, evaluations, and more through sub-clients. You can initialize the client with a configuration object and use its sub-clients to interact with specific resources. ```APIDOC ## TrustwiseClient ### Description User-friendly client for the Trustwise Harmony Platform API. Provides access to all platform resources through sub-clients: `agents`, `gateway`, `guardrails`, `policies`, `evaluations`, `evaluators`, `organizations`, `projects`, `risk_engine`, `generation`, `metrics`, `events`, `subscriptions`, and `runtime_providers`. ### Initialization ```python from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.platform import TrustwiseClient config = TrustwiseConfig(api_key="tw-...") client = TrustwiseClient(config) ``` ### Usage Examples #### Agents ```python # Agents are now project-scoped agent = client.agents.get("project-id", "agent-id") print(agent.name) agents = client.agents.list("project-id", search="my-bot", limit=5) for a in agents: print(a.name) ``` ### Parameters - **config** (_TrustwiseConfig_): Configuration object for the client. - **\*\*kwargs**: Additional keyword arguments. - **timeout** (_int_): Request timeout in seconds. Defaults to 30. ``` -------------------------------- ### trustwise.sdk.platform.client.SubscriptionResource.get Source: https://trustwiseai.github.io/trustwise/api.html Get a single event subscription by its ID. Accepts 'subscription_id' and optional 'raw' boolean. ```APIDOC ## get ### Description Get a single event subscription. ### Parameters * **subscription_id** (`str`) – Unique subscription identifier. * **raw** (`bool`) – Return the full API envelope. ``` -------------------------------- ### trustwise.sdk.platform.client.EventResource.get Source: https://trustwiseai.github.io/trustwise/api.html Get a single event notification by its ID. Accepts 'event_id' and optional 'raw' boolean. ```APIDOC ## get ### Description Get a single event notification. ### Parameters * **event_id** (`str`) – Unique event identifier. * **raw** (`bool`) – Return the full API envelope. ``` -------------------------------- ### Initialize TrustwiseClient Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/client.html Instantiate the TrustwiseClient with a TrustwiseConfig object. The client provides access to various platform resources via sub-clients. You can optionally set an HTTP request timeout. ```python from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.platform import TrustwiseClient config = TrustwiseConfig(api_key="tw-...") client = TrustwiseClient(config) ``` -------------------------------- ### Get Organization by ID Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/client.html Retrieves a single organization's details using its unique identifier. ```APIDOC ## Get Organization by ID ### Description Get a single organization by ID. ### Method GET ### Endpoint /v1/organizations/{org_id} ### Parameters #### Path Parameters - **org_id** (str) - Required - Unique organization identifier. #### Query Parameters - **raw** (bool) - Optional - Return the full API envelope. ### Response #### Success Response (200) - **data** (OrganizationResponse) - The organization object if raw=False. - **envelope** (dict) - The full API envelope if raw=True. ``` -------------------------------- ### Initialize TrustwiseConfig with Direct Values Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/config.html Instantiate TrustwiseConfig by providing the API key and base URL directly as arguments. This overrides any environment variable settings. ```python >>> # Using direct initialization >>> config = TrustwiseConfig(api_key="your-api-key", base_url="https://api.trustwise.ai") ``` -------------------------------- ### Get Current Default Version Source: https://trustwiseai.github.io/trustwise/versioning.html Accesses the current default API version being used by the SDK. ```APIDOC ## Get Current Default Version ### Description Accesses the current default API version being used by the SDK for metrics. ### Method `trustwise.metrics.version` ### Parameters None ### Response - `version` (string): The current default version string. ``` -------------------------------- ### TrustwiseSDK Initialization Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/sdk.html Initializes the Trustwise SDK with a configuration object. This class is deprecated and users should migrate to TrustwiseClient. ```APIDOC ## __init__ TrustwiseSDK ### Description Initialize the Trustwise SDK with path-based versioning support. ### Args - **config** (TrustwiseConfig) - Required - Trustwise configuration instance. ### Deprecation Warning This class is deprecated. Use :class:`trustwise.sdk.platform.client.TrustwiseClient` instead. ``` -------------------------------- ### Replace Client Instantiation: TrustwiseSDK to TrustwiseClient Source: https://trustwiseai.github.io/trustwise/_sources/sdk_migration.rst.txt Update how the SDK or client is instantiated, changing from TrustwiseSDK to TrustwiseClient. ```diff - sdk = TrustwiseSDK(config) + client = TrustwiseClient(config) ``` -------------------------------- ### Get Field Description Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/types.html Retrieves the description for a given field from its Pydantic field information, if available. ```python def _get_field_description(self, field_name: str, field_info: object | None = None) -> str: """Get the description for a field from its field info.""" if field_info and hasattr(field_info, "description") and field_info.description: ``` -------------------------------- ### Get Available API Versions Source: https://trustwiseai.github.io/trustwise/versioning.html Retrieves a list of all available API versions supported by the Trustwise SDK. ```APIDOC ## Get Available API Versions ### Description Retrieves a list of all available API versions supported by the Trustwise SDK. ### Method `trustwise.get_versions()` ### Parameters None ### Response - `versions` (list): A list of available API version strings. ``` -------------------------------- ### List All Runtime Providers Source: https://trustwiseai.github.io/trustwise/platform.html Retrieve a list of all available runtime providers, which define connector types for agent deployment. This is useful for understanding deployment options. ```python providers = client.runtime_providers.list() ``` -------------------------------- ### Create a Webhook Subscription Source: https://trustwiseai.github.io/trustwise/platform.html Set up a new subscription to forward event notifications to a specified webhook URL. Filter events by type and severity. ```python sub = client.subscriptions.create( name="My Webhook", event_type_filter=["evaluation.completed", "evaluation.failed"], severity_filter=["critical", "warning"], handler_type="webhook", handler_config={"url": "https://my-service.example.com/events"}, ) ``` -------------------------------- ### Get SDK Version Async Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/async_sdk.html Retrieve the current version of the SDK, which is set to 'v4' for the default metrics. ```python @property def version(self) -> str: return "v4" ``` -------------------------------- ### TrustwiseSDKAsync Initialization Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/async_sdk.html Initializes the Trustwise asynchronous SDK client and exposes metrics directly. ```APIDOC ## TrustwiseSDKAsync ### Description Async SDK entrypoint for Trustwise. Use this class to access async metrics. ### Initialization ```python from trustwise.sdk import TrustwiseSDKAsync, TrustwiseConfig config = TrustwiseConfig(...) async_sdk = TrustwiseSDKAsync(config) # Access metrics directly answer_relevancy = async_sdk.answer_relevancy carbon = async_sdk.carbon # ... and so on for other metrics # Access metrics through the metrics object answer_relevancy_v4 = async_sdk.metrics.v4.answer_relevancy ``` ### Attributes - **client**: TrustwiseAsyncHTTPClient instance. - **metrics**: MetricsAsync instance for accessing various metrics. ``` -------------------------------- ### Evaluate Faithfulness Metric Source: https://trustwiseai.github.io/trustwise/_sources/usage.rst.txt Evaluate the faithfulness metric by providing a query, response, and context. This is an example of a synchronous evaluation. ```python # Evaluate faithfulness trustwise.metrics.faithfulness.evaluate( query="What is the capital of France?", response="The capital of France is Paris.", context=[ {"chunk_text": "Paris is the capital of France.", "chunk_id": "doc:idx:1"} ] ) ``` -------------------------------- ### Configuration Source: https://trustwiseai.github.io/trustwise/_sources/api.rst.txt Documentation for the configuration module of the Trustwise SDK. ```APIDOC ## Configuration .. automodule:: trustwise.sdk.config :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### TrustwiseSDKAsync Initialization Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/async_sdk.html Initializes the asynchronous Trustwise SDK client. ```APIDOC ## TrustwiseSDKAsync Initialization Initializes the asynchronous client for the Trustwise SDK. ### `__init__()` Constructor for the `TrustwiseSDKAsync` class. ``` -------------------------------- ### Get Single Evaluation Source: https://trustwiseai.github.io/trustwise/api.html Retrieves a single evaluation by its unique identifier within a project. Supports raw envelope returns. ```APIDOC ## get ### Description Get a single evaluation by ID. ### Parameters * **project_id** (str) - Project identifier. * **evaluation_id** (str) - Unique evaluation identifier. * **raw** (bool) - Return the full API envelope. ### Return Type `dict`[`str`, `Any`] ``` -------------------------------- ### V4 Metrics Evaluation Source: https://trustwiseai.github.io/trustwise/usage.html Demonstrates how to evaluate various V4 metrics using the SDK. ```APIDOC ## V4 Metrics Evaluation ### Description This section covers the evaluation of various metrics available in V4 of the Trustwise SDK. ### Available Metrics and Methods - **Adherence**: `metrics.adherence.evaluate()` - **Answer Relevancy**: `metrics.answer_relevancy.evaluate()` - **Clarity**: `metrics.clarity.evaluate()` - **Completion**: `metrics.completion.evaluate()` - **Context Relevancy**: `metrics.context_relevancy.evaluate()` - **Faithfulness**: `metrics.faithfulness.evaluate()` - **Formality**: `metrics.formality.evaluate()` - **Helpfulness**: `metrics.helpfulness.evaluate()` - **PII Detection**: `metrics.pii.evaluate()` - **Prompt Manipulation**: `metrics.prompt_manipulation.evaluate()` - **Refusal**: `metrics.refusal.evaluate()` - **Sensitivity**: `metrics.sensitivity.evaluate()` - **Stability**: `metrics.stability.evaluate()` - **Simplicity**: `metrics.simplicity.evaluate()` - **Tone**: `metrics.tone.evaluate()` - **Toxicity**: `metrics.toxicity.evaluate()` - **Carbon**: `metrics.carbon.evaluate()` ### Usage Example (Conceptual) ```python # Assuming 'client' is an initialized TrustwiseClient instance # Example for Faithfulness metric faithfulness_result = client.metrics.faithfulness.evaluate(prompt="...", response="...", context="...") print(faithfulness_result) # Example for Clarity metric clarity_result = client.metrics.clarity.evaluate(response="...") print(clarity_result) ``` ### Parameters (Specific parameters for each metric's `evaluate` method are not detailed in the source but typically include prompt, response, context, etc., depending on the metric.) ### Response (The structure of the response for each metric evaluation is not detailed in the source.) ``` -------------------------------- ### Risk Engine - Scaffold and Classification Source: https://trustwiseai.github.io/trustwise/platform.html Interact with the risk engine to get questionnaire scaffolds and classify risk based on answers. ```APIDOC ## Risk Engine ### Description Utilize the risk engine to obtain questionnaire scaffolds for risk assessment and to classify risk based on provided answers. ### Methods #### Get Questionnaire Scaffold ```python scaffold = client.risk_engine.scaffold("arc-v3") ``` #### Classify Risk ```python result = client.risk_engine.classify("arc-v3", answers={...}) ``` ``` -------------------------------- ### Policies - Management and Evaluation Source: https://trustwiseai.github.io/trustwise/platform.html Manage policies, including listing, evaluating content against single or multiple policies, and getting recommendations. ```APIDOC ## Policies ### Description Manage policies, including listing, evaluating content against policies, and obtaining policy recommendations based on tags. ### Methods #### List Policies ```python policies = client.policies.list() ``` #### Evaluate Content Against Policy ```python result = client.policies.evaluate(policy_id, input="test input") ``` #### Evaluate Content Against Multiple Policies ```python results = client.policies.evaluate_batch( policy_ids=["policy-1", "policy-2"], input={"text": "test input"}, ) ``` #### Get Policy Recommendations ```python recs = client.policies.recommend(tags=["safety", "pii"]) ``` ``` -------------------------------- ### Synchronous V4 Metrics Evaluation Source: https://trustwiseai.github.io/trustwise/v4_metrics.html Demonstrates how to use the Trustwise SDK for synchronous evaluation of v4 metrics, including setting up the configuration and defining context chunks. ```python from trustwise.sdk import TrustwiseSDK from trustwise.sdk.config import TrustwiseConfig from trustwise.sdk.metrics.v4.types import ContextChunk config = TrustwiseConfig(api_key="your-api-key") trustwise = TrustwiseSDK(config) # v4 context format context = [ ContextChunk(chunk_text="Paris is the capital of France.", chunk_id="doc:idx:1") ] # v4 metric calls (now default) result = trustwise.metrics.faithfulness.evaluate( query="What is the capital of France?", response="The capital of France is Paris.", context=context ) ``` -------------------------------- ### Get Policy Recommendations Source: https://trustwiseai.github.io/trustwise/api.html Provides policy recommendations based on tags describing an agent or use-case. Additional context can be provided in the body. ```APIDOC ## policies.recommend ### Description Get policy recommendations for a given agent or use-case. ### Parameters - **tags** (list[`str`]) - Required - Tags describing the agent or use-case. - **raw** (bool) - Optional - Return the full API envelope. - **body** (Any) - Optional - Extra context for recommendation, such as `agent_id`, `description`, etc. ### Return Type `list`[`PolicyRecommendation`] ### Returns List of `PolicyRecommendation`, or the raw envelope. ``` -------------------------------- ### Get a Single Agent Source: https://trustwiseai.github.io/trustwise/api.html Retrieve a specific agent by its ID within a project. Set `raw=True` to obtain the full API envelope. ```python agent = client.agents.get(project_id="project-id", agent_id="agent-id") ``` -------------------------------- ### TrustwiseClient Initialization Source: https://trustwiseai.github.io/trustwise/changelog.html Initializes the Trustwise client for interacting with the platform API. ```APIDOC ## TrustwiseClient ### Description The main client class for interacting with the Trustwise Platform API. It provides access to various resources. ### Method `TrustwiseClient.__init__(self, api_key: str, api_url: str = "https://api.trustwise.io/v1")` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from trustwise import TrustwiseClient client = TrustwiseClient(api_key="YOUR_API_KEY") ``` ### Response None (initialization) #### Success Response (200) None #### Response Example None ``` -------------------------------- ### TrustwiseConfig Initialization Source: https://trustwiseai.github.io/trustwise/api.html Initialize the Trustwise API configuration. Supports environment variables or direct parameter passing for API key and base URL. ```APIDOC ## TrustwiseConfig ### Description Configuration for Trustwise API. This class handles configuration for the Trustwise API, including authentication and endpoint URLs. It supports both direct initialization and environment variables. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method __init__ ### Endpoint N/A (Class constructor) ### Parameters - **api_key** (str, Optional) - API key for authentication. If not provided, will be read from TW_API_KEY environment variable. Required for API access. - **base_url** (str, Optional) - Base URL for API endpoints. If not provided, will be read from TW_BASE_URL environment variable or default to https://api.trustwise.ai. ### Request Example ```python from trustwise.sdk.config import TrustwiseConfig # Using environment variables config = TrustwiseConfig() # Using direct initialization config = TrustwiseConfig(api_key="your-api-key", base_url="https://api.trustwise.ai") ``` ### Response #### Success Response None (Constructor does not return a value, but initializes the object) #### Response Example None ``` -------------------------------- ### Get a Specific Event Source: https://trustwiseai.github.io/trustwise/platform.html Fetch details for a single event using its unique identifier. This is useful for inspecting individual event occurrences. ```python event = client.events.get("event-id") ``` -------------------------------- ### Manage Evaluations: List and Get Audit Logs Source: https://trustwiseai.github.io/trustwise/platform.html List evaluations within a project and retrieve their audit logs. Evaluations are project-scoped. ```python # List evaluations in a project evals = client.evaluations.list("my-project-id", limit=10) # Get audit logs logs = client.evaluations.audit_logs("my-project-id") ``` -------------------------------- ### TrustwiseConfig Initialization Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/config.html Initialize the TrustwiseConfig class, which handles API authentication and endpoint URLs. It supports reading credentials from environment variables or direct input. ```APIDOC ## TrustwiseConfig ### Description Configuration for Trustwise API. This class handles configuration for the Trustwise API, including authentication and endpoint URLs. It supports both direct initialization and environment variables. ### Parameters - **api_key** (str, Optional): API key for authentication. If not provided, will be read from TW_API_KEY environment variable. Required for API access. - **base_url** (str, Optional): Base URL for API endpoints. If not provided, will be read from TW_BASE_URL environment variable or default to https://api.trustwise.ai. ### Environment Variables - TW_API_KEY: API key for authentication - TW_BASE_URL: Base URL for API endpoints (defaults to https://api.trustwise.ai) ### Example ```python >>> from trustwise.sdk.config import TrustwiseConfig >>> # Using environment variables >>> config = TrustwiseConfig() >>> # Using direct initialization >>> config = TrustwiseConfig(api_key="your-api-key", base_url="https://api.trustwise.ai") ``` ### Raises - ValueError: If API key is missing or invalid, or if base URL is invalid ``` -------------------------------- ### Get Project Audit Logs Source: https://trustwiseai.github.io/trustwise/_sources/platform.rst.txt Fetch audit logs for a given project. This is essential for tracking changes and activities within the project. ```python # Get audit logs logs = client.evaluations.audit_logs("my-project-id") ``` -------------------------------- ### List Runtime Providers Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/client.html Retrieves a list of all available runtime providers. Use the `raw` parameter to get the full API response envelope. ```python client.runtime_providers.list() ``` -------------------------------- ### TrustwiseConfig Initialization and Attributes Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/config.html Details on initializing the TrustwiseConfig class and its core attributes like api_key and base_url. ```APIDOC ## TrustwiseConfig ### Description Configuration class for the Trustwise SDK. ### Attributes - **api_key** (str): The API key for authentication. - **base_url** (str): The base URL for the Trustwise API. ### Methods - **__init__(api_key: str, base_url: str = None)**: Initializes the configuration with an API key and an optional base URL. - **_validate_url()**: Internal method to validate the base URL. - **get_performance_url()**: Returns the URL for performance-related endpoints. - **get_metrics_url()**: Returns the URL for metrics-related endpoints. ``` -------------------------------- ### similar_prompt Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/platform/client.html Generate prompts similar to a seed prompt. Accepts optional `raw` flag and seed prompt along with generation parameters. ```APIDOC ## similar_prompt Generate prompts similar to a seed prompt. ### Method POST ### Endpoint /v1/generation/similar_prompt ### Parameters #### Query Parameters - **raw** (bool) - Optional - Return the full API envelope. #### Request Body - **seed_prompt** (str) - Required - The prompt to generate similar prompts from. - **...** (Any) - Other generation parameters. ``` -------------------------------- ### Get Available API Versions Source: https://trustwiseai.github.io/trustwise/_modules/trustwise/sdk/sdk.html Retrieves the available API versions for metrics. The returned dictionary maps 'metrics' to a list of its supported versions. ```python def get_versions(self) -> dict[str, list[str]]: """ Get the available API versions for the metrics. Returns: Dictionary mapping 'metrics' to its available versions. Example: {"metrics": ["v3"]} """ return {"metrics": ["v3", "v4"]} ```