All Products
Search
Document Center

Microservices Engine:AI transformer

Last Updated:Jan 02, 2025

This topic describes the ai-transformer plug-in that calls a large language model (LLM) to modify the header and body of a request or response.

Running attributes

Plug-in execution stage: authentication stage. Plug-in execution priority: 410.

Configuration description

Name

Data type

Required

Default value

Description

request.enable

bool

Yes

-

Specifies whether to enable conversion in the request phase.

request.prompt

string

Yes

-

The prompt used for conversion in the request phase.

response.enable

string

Yes

-

Specifies whether to enable conversion in the response phase.

response.prompt

string

Yes

-

The prompt used for conversion in the response phase.

provider.serviceName

string

Yes

-

The service name of the Domain Name System (DNS) type. Only Qwen is supported.

provider.domain

string

Yes

-

The domain name of the LLM service.

provider.apiKey

string

Yes

-

The API key of the Alibaba Cloud DashScope service.

Configuration example

request:
    enable: false
    prompt: "If the request path starts with /httpbin, remove the /httpbin prefix. If the request path does not start with /httpbin, do not modify the request path."
response: 
    enable: true
    prompt: "Modify the HTTP response based on the following requirements: 1. Change content-type to application/json. 2. Convert the body from XML to JSON. 3. Remove content-length."
provider: 
    serviceName: qwen
    domain: dashscope.aliyuncs.com
    apiKey: xxxxxxxxxxxxx

Access the /xml interface of the httpbin application. The following sample code shows the response:

<?xml version='1.0' encoding='us-ascii'?>

<!--  A SAMPLE set of slides  -->

<slideshow
    title="Sample Slide Show"
    date="Date of publication"
    author="Yours Truly"
    >

    <!-- TITLE SLIDE -->
    <slide type="all">
      <title>Wake up to WonderWidgets!</title>
    </slide>

    <!-- OVERVIEW -->
    <slide type="all">
        <title>Overview</title>
        <item>Why <em>WonderWidgets</em> are great</item>
        <item/>
        <item>Who <em>buys</em> WonderWidgets</item>
    </slide>

</slideshow>

Use the preceding configuration to access the /xml interface of the httpbin application by using a gateway. The following sample code shows the response:

{
  "slideshow": {
    "title": "Sample Slide Show",
    "date": "Date of publication",
    "author": "Yours Truly",
    "slides": [
      {
        "type": "all",
        "title": "Wake up to WonderWidgets!"
      },
      {
        "type": "all",
        "title": "Overview",
        "items": [
          "Why <em>WonderWidgets</em> are great",
          "",
          "Who <em>buys</em> WonderWidgets"
        ]
      }
    ]
  }
}