Skip to main content

Server-side Python SDK

This topic describes the TingWu Python SDK to help developers 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 description

TingWu.py

You can call the service using the call method of TingWu.py:
def call(
          model: str,
          user_defined_input: Dict[str, Any],
          parameters: Dict[str, Any] = None,
          api_key: str = None,
          **kwargs
  ) -> DashScopeAPIResponse:
"""Calls the generation model service.

    Args:
          model (str): The requested model, such as qwen3.5-flash.
          api_key (str, optional): The API key. If this parameter is not specified,
              the SDK obtains the API key by following the default rule.
          user_defined_input: The custom input.
          parameters: The custom parameters.
          **kwargs:
              base_address: The base address.
              Additional parameters for the request.

    Raises:
          InvalidInput: The history and auto_history parameters are mutually exclusive.

    Returns:
          Union[GenerationResponse,
                Generator[GenerationResponse, None, None]]: If
          stream is set to True, a Generator is returned. Otherwise, a GenerationResponse is returned.
"""
Using Automotive Service Insights as an example, the key parameters are described as follows. For more information about the parameters, see the Automotive Service Insights API Reference or the Customer Portrait for Car Purchase API Reference:
  • model

    Name

    Type

    Required

    Description

    Example

    model

    string

    Yes

    Defines the business type.

    For more information about the parameters, see the API reference.

    tingwu-automotive-service-insights

  • user_defined_input
    NameTypeRequiredDescriptionExample
    fileUrlstringSelect one of the threeThe OSS URL of the file to be analyzed.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
    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?
    
    dataIdstringThe ID of the task that has been uploaded and parsed.
    appIdstringYesApplication ID.
    taskstringYesTask type:
    • createTask: Creates a task.
    • getTask: Obtains the task result.
    createTask
  • parameters (For more information, see the API reference.)

Sample code

from dashscope.multimodal.tingwu.tingwu import TingWu
import os

# Create a TingWu instance.
tingwu = TingWu()
resp = TingWu.call(
    model='tingwu-automotive-service-insights',
    user_defined_input={"task": "createTask", "text": "Zhang*:I want to buy an SUV\nLi*:What price range are you looking for?", "appId": "123456"},
    api_key="your_api_key",
    base_address="https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation",
    parameters={"serviceInsights": {"insightsContents": [
        {"title": "Store Arrival Welcome - Greeting", "content": "The sales representative actively greets the customer upon arrival.", "score": "20"},
        {"title": "Store Departure Farewell - Customer Information Retention", "content": "The sales representative asks the customer to leave their contact information, such as WeChat, phone number, or business card.", "score": "30"},
        {"title": "Store Arrival Welcome - Beverage Offer",
         "content": "The sales representative proactively asks the customer if they would like a beverage (such as coffee, orange juice, water, or tea), snacks, or fruit.", "score": "50"}]}}
)
print(resp)

Response

Using Automotive Service Insights as an example, the main response parameters are described as follows. For more information, see the Automotive Service Insights API Reference or the Customer Portrait for Car Purchase API Reference:

Name

Type

Description

Example

output

object

output.dataId

string

Task ID.

output.status

string

  • 0: Succeeded

  • 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

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