Function Description

The AI Request-Response Transformation plugin modifies the header and body of requests/responses using LLM.

Execution Attributes

Plugin execution phase: Authentication Phase
Plugin execution priority: 410

Configuration Description

NameTypeRequirementDefaultDescription
request.enableboolrequired-Whether to enable transformation in the request phase
request.promptstringrequired-Prompt used for transformation in the request phase
response.enableboolrequired-Whether to enable transformation in the response phase
response.promptstringrequired-Prompt used for transformation in the response phase
provider.serviceNamestringrequired-DNS type service name, currently only supports Qwen
provider.domainstringrequired-LLM service domain
provider.apiKeystringrequired-Alibaba Cloud Dashscope service API Key

Configuration Example

  1. request:
  2. enable: false
  3. prompt: If the request path starts with /httpbin, please remove the /httpbin prefix and do not change anything else.”
  4. response:
  5. enable: true
  6. prompt: Please modify the following HTTP response information with the requirements: 1. change content-type to application/json; 2. convert body from xml to json; 3. remove content-length.”
  7. provider:
  8. serviceName: qwen
  9. domain: dashscope.aliyuncs.com
  10. apiKey: xxxxxxxxxxxxx

Accessing the original httpbin’s /xml interface yields:

  1. <?xml version=’1.0 encoding=’us-ascii’?>
  2. <!— A SAMPLE set of slides —>
  3. <slideshow
  4. title=”Sample Slide Show
  5. date=”Date of publication
  6. author=”Yours Truly
  7. >
  8. <!— TITLE SLIDE —>
  9. <slide type=”all”>
  10. <title>Wake up to WonderWidgets!</title>
  11. </slide>
  12. <!— OVERVIEW —>
  13. <slide type=”all”>
  14. <title>Overview</title>
  15. <item>Why <em>WonderWidgets</em> are great</item>
  16. <item/>
  17. <item>Who <em>buys</em> WonderWidgets</item>
  18. </slide>
  19. </slideshow>

Using the above configuration, accessing the httpbin’s /xml interface through the gateway yields:

  1. {
  2. slideshow”: {
  3. title”: Sample Slide Show”,
  4. date”: Date of publication”,
  5. author”: Yours Truly”,
  6. slides”: [
  7. {
  8. type”: all”,
  9. title”: Wake up to WonderWidgets!”
  10. },
  11. {
  12. type”: all”,
  13. title”: Overview”,
  14. items”: [
  15. Why <em>WonderWidgets</em> are great”,
  16. “”,
  17. Who <em>buys</em> WonderWidgets
  18. ]
  19. }
  20. ]
  21. }
  22. }