Develop TPP solution code

Updated at:
Copy as MD

A solution is the business code used in a business scenario. Before you create a scenario, you must develop and publish the corresponding solution.

Before you begin

Prerequisites

1. Create a Codeup repository and configure its permissions. TPP currently supports only Codeup repositories. Support for other repository types may be added later.

2. Download the recommended TPP solution code template and develop your business code.

3. Upload your code to the Codeup repository.

Create a Codeup repository

Procedure

1. Log on to the Codeup console. The service is currently free to use.

2. In the left-side navigation pane, click Repositories.

3. On the right side of the page, click New Repository.

4. In the dialog box, enter the basic information. The following table describes the parameters.

Parameter

Description

Repository name

The name of the repository.

Repository path

The directory path of the repository. You can use groups to manage multiple related repositories separately.

Visibility

The visibility of the repository. Public repositories are visible to all members of your enterprise, excluding external members. Private repositories are visible only to repository members.

5. After you fill in the basic information, click OK to create the repository.

Authorize TPP to access the Codeup repository

Procedure

1. Prepare your local Git environment.

2. Log on to the Codeup console.

3. In the upper-right corner of the console, click your profile icon.

4. From the menu, click Personal Settings.

5. Set up an SSH key.

6. Configure the credentials for authentication when cloning over HTTPS.

Note: TPP requires these credentials to access your repository. Make sure to remember the username and password.

Download the solution template and develop locally

Procedure

Download the 2022-03-28 Open-source code template [Recommended]. For detailed instructions, refer to the README file.

# Demo for the recommended solution
# This repository contains multiple demos that you can modify and use directly. 
# Before you go live, ensure you test them thoroughly.
# Disclaimer: This code is for demonstration purposes only. We are not responsible for any business outcomes.

## Environment
* Code repository: Codeup
* JDK: 1.8
* Maven: 3.3+
* [maven settings.xml](#settings-xml-for-local-use) 

## Directory structure
* src
  * main 
    * java # Contains multiple demos you can modify and use.
      * ABFS # ABFS usage demo
      * BE # BE usage demo
      * HTTP # HTTP usage demo
      * Predict # Predict usage demo
      * Redis # Redis usage demo
      * hello # The simplest demo
      * demo # The complete recommended demo
        * Entry point: DemoSolution
        * match: BE and Redis (x2i)
        * feature: user-abfs, context-noting, item-redis
        * rank: PAI-EAS (multi_tower)
        * rerank: Reverse order + filter + shuffle
    * test # Test cases
# We highly recommend writing test cases. Publish to TPP only after the test cases pass locally.
* pom.xml # Do not modify this file. Newly added dependencies will not take effect.

## About dependencies
# Java dependencies are complex and can easily lead to conflicts, vulnerabilities, and security risks. 
# Therefore, TPP solution code does not allow you to add arbitrary jar files. We strictly control dependencies to ensure code safety and reliability.
# Control method:
# 1. Use a custom SDK.
# 2. Use a custom plugin.
# As a result, only the dependencies specified in the pom.xml file are available. Any newly added dependencies will not take effect.

### Basic SDK: solution-protocol
# Provides essential jar files.
<dependency>
  <groupId>com.aliyun.tpp</groupId>
  <artifactId>solution-protocol</artifactId>
  <version>1.0</version>
</dependency>
# For example: context, result, solution

### Common services SDK: ai-service-sdk
# Provides common jar files that are frequently used but not required by all solutions.
<dependency>
  <groupId>com.aliyun.tpp</groupId>
  <artifactId>ai-service-sdk</artifactId>
  <version>1.0</version>
</dependency>
# For example: ABFS, BE, PAI-EAS, Redis

### Local testing SDK: ai-service-sdk-testing
# Provides jar files required for testing.
<dependency>
  <groupId>com.aliyun.tpp</groupId>
  <artifactId>ai-service-sdk-testing</artifactId>
  <version>1.0</version>
  <scope>test</scope>
</dependency>

## FAQ
### settings.xml for local use
# Modify three sections: mirrors, profiles, and activeProfiles.
* Modify mirrors
<mirrors>
  <mirror>
    <id>maven-mirror</id>
    <mirrorOf>central</mirrorOf>
    <name>maven public mirror</name>
    <url>https://repo1.maven.org/maven2/</url>
  </mirror>
</mirrors>
* Modify profiles
<profiles>
  <profile>
    <id>aliyun</id>
    <repositories>
      <repository>
        <id>aliyun</id>
        <url>https://maven.aliyun.com/repository/public</url>
        <releases>
          <enabled>true</enabled>
        </releases>
        <snapshots>
          <enabled>false</enabled>
        </snapshots>
      </repository>
    </repositories>
    <pluginRepositories>
      <pluginRepository>
        <id>aliyun</id>
        <url>https://maven.aliyun.com/repository/public</url>
        <releases>
          <enabled>true</enabled>
        </releases>
        <snapshots>
          <enabled>false</enabled>
        </snapshots>
      </pluginRepository>
    </pluginRepositories>
  </profile>
</profiles>
* Modify activeProfiles
<activeProfiles>
  <activeProfile>aliyun</activeProfile>
</activeProfiles>

Important: You must run unit tests locally. For examples, refer to the test cases in the demo. Passing unit tests helps verify the logic of your code. The main difference between the online and local environments is the network configuration. For remote calls that use services such as HTTP, Redis, or PAI-EAS, you must provide the correct host information.

Commit code

Procedure

1. Log on to the Codeup console.

2. In your workspace, click the target repository.

3. After you edit the code, click Save to commit it.

Create a solution

Procedure

1. Log on to the TPP console.

2. In the left-side navigation pane, click TPP > Instance List.

3. In the top navigation bar, select the region where your instance is located.

4. Click the instance ID, select the Solution Management tab, and then click Create Solution.

5. Enter the basic information for the solution. The following table describes the parameters.

Parameter

Description

Clone from an existing solution

Use this option to quickly create a solution by cloning an existing one. This action clones both the basic information and the configuration of the source solution.

If you are creating a solution for the first time, do not select this option.

Solution name

The display name of the solution.

Code source

Currently, only Codeup is supported. Support for other code sources may be added in the future.

Repository URL

The URL of the code repository.

Branch

The name of the branch.

Git username

The HTTPS authentication username from your Codeup personal settings.

Git password

The HTTPS authentication password from your Codeup personal settings.

Solution directory name

The subdirectory in the repository that contains the solution code.

6. Click OK to create the solution.