Skip to content

GenTelAI/shield-java-sdk

Repository files navigation

Shield Java SDK

Shield Java Client SDK provides simple APIs to access risk control services.

This quickstart guide will show you how to install the client SDK and execute example Java programs.

Minimum Requirements

Java 1.8 or higher:

Using Maven

<dependency>
    <groupId>com.gentel.shield</groupId>
    <artifactId>shield</artifactId>
    <version>0.2.0</version>
</dependency>

Using Gradle

dependencies {
    implementation 'com.gentel.shield:shield:0.2.0'
}

Quick Start Example

This example demonstrates how to send a risk control request using Shield SDK and receive a response.

You need the following parameters to use the service:

Parameter Description
BaseURL Service URL
API Key API key for authentication

ShieldExample.java

import com.gentel.shield.ShieldClient;
import com.gentel.shield.core.ShieldRequest;
import com.gentel.shield.core.ShieldResponse;

public class ShieldExample {
    public static void main(String[] args) {
        try {
            // Create Shield client instance
            ShieldClient client = ShieldClient.builder()
                .baseUrl("https://shield.gentel.com/api/shield/v1/")
                .apikey("your-api-key")
                .build();

            // Build request
            ShieldRequest request = ShieldRequest.builder()
                .Modal(Modal.TEXT)
                .format(Format.PLAIN)
                .content("Test Content")
                .role(Role.USER);

            // Send request and get response
            ShieldResponse response = client.Detect(request);
            
            // Handle response
            System.out.println("Sanitized Content: " + response.getSanitized());
            System.out.println("Risk List: " + response.getRisks());
            
        } catch(Exception e) {
            System.out.println("Error occurred: " + e.getMessage());
        }
    }
}

API Documentation

Here's an overview of the main API classes:

ShieldClient

The main client class for sending risk control requests:

  • Detect - Risk Detection
  • TextDetect - Text Risk Detection
  • ImageDectect - Image Risk Detection

Core Classes

  • ShieldRequest - Request object
  • ShieldResponse - Response object
  • HttpRiskEvent - Risk event object
  • Risk - Risk details object

Data Models

  • RiskLevel - Risk level enumeration
  • Format - Format enumeration
  • Role - Role enumeration
  • Modal - Modal enumeration

Complete Examples

The SDK provides the following example code:

Exception Handling

The SDK defines the following exception types:

  • ShieldException - Base SDK exception
  • BadRequestException - Request parameter error
  • ServerException - Server-side error
  • ConnectionException - Network connection error

Learn More

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages