Skip to main content

Server-side Java SDK

This topic describes the TingWu Java SDK and explains how to use it to quickly call the service.

Prerequisites

Activate the service and obtain and configure an API key. To prevent security risks from code leaks, configure the API key as an environment variable instead of hard coding it in your code.
To grant temporary access permissions to third-party applications or users, or want to strictly control risky operations such as accessing or deleting sensitive data, you can use a temporary authentication token.Compared to a long-term API key, a temporary authentication token is valid for only a short period (60 seconds) and offers higher security. It is suitable for temporary call scenarios and can effectively reduce the risk of API key leaks.Usage: In your code, replace the API key used for authentication with the obtained temporary authentication token.

API reference

TingWuParam.java

This class is used for parameter configuration. The following table lists the main parameters for creating a task, using Automotive Service Insights as an example. For more information about the parameters, see the Automotive Service Insights API Reference or the Car Buyer Portrait API Reference.
NameTypeRequiredDescriptionExample
modelstringYesDefines the business type.For specific parameters, see the API reference.tingwu-automotive-service-insights
inputobjectYesPasses relevant business parameters.
input.fileUrlstringChoose one of threeThe OSS URL of the file to be analyzed. Used for SDK calls.https://.oss-cn-hangzhou.aliyuncs.com/%E8%AF%95%E9%A9%BE%E6%A1%88%E4%BE%8Bsmall.wav?OSSAccessKeyId=YOUR_ACCESS_KEY_ID&Expires=&Signature=YOUR_SIGNATURE
input.textstringThe text to be analyzed.Each line must be in the following format:${Speaker Name}: ${Speaker Content}For example:
Zhang3: I want to buy an SUV.
Li4: What price range are you looking for?
input.dataIdstringAssociates a task that has been uploaded and parsed.
input.appIdstringYesApplication ID.
input.taskstringYesDefines the task type:
  • createTask: Creates a task.
  • getTask: Retrieves the task result.
createTask
parametersobjectNoRequest parameters. If a null object is passed, the published configuration items are reused.For specific parameters, see the API reference.

Example code

import java.util.Map;
import java.util.HashMap;
import com.alibaba.dashscope.multimodal.tingwu.TingWuParam;

// Build custom Input.
public static Map<String, Object> buildCustomInput(String appId) {
        Map<String, Object> params = new HashMap<>();
        params.put("fileUrl", "http://demo.com/test.mp3");
        params.put("appId", appId);
        params.put("task", "createTask");
        // Set other parameters.
        return params;
}
// Build TingWuParam.
TingWuParam param = TingWuParam.builder().
    model("tingwu-automotive-service-insights")
    .input(buildCustomInput("your_app_id"))
    .parameters(new HashMap<>())  // Set the parameters parameter.
    .apiKey("your_api_key")
    .build();

TingWu.java

  • This is the HTTP service interface class for TingWu.
/**
 * the tingwu client with baseUrl
 * param protocol : http or websocket, default should http
 * param baseUrl : custom server host
 */
public TingWu(String protocol, String baseUrl)
  • This class sends a request and returns a response.
/**
 * Call the server to get the whole result, only http protocol
 * param param: the TingWuParam
 * return DashScopeResult
 */
public DashScopeResult call(TingWuParam param)

Response

The following table lists the main response parameters, using Automotive Service Insights as an example. For more information, see the Automotive Service Insights API Reference or the Car Buyer Portrait API Reference.

Name

Type

Description

Example

output

object

output.dataId

string

Task ID.

output.status

string

  • 0: Success

  • 1: In progress

  • 2: Failed

0

usage

object

code

string

Error code.

InvalidParameter

message

string

Error message.

Agent Input text format error.

request_id

string

Request ID.

f97ee37d-0f9c-9b93-b6bf-bd263a232bf9

Example response:
{
    "output": {
        "dataId": "dj***"
    },
    "usage": {},
    "request_id": "8313c0bc-ff3f-98e8-b87a-0118f6fe3049"
}
Agent Development
Agent Context
Agent Governance & Evolution
Store
Application Marketplace