AI-assisted plugin development

Updated at:

Use AI large language models (LLMs) to automatically generate plugin code from your natural language requirements.

Overview

AI Gateway provides end-to-end plugin generation powered by LLMs. Describe your plugin logic in natural language to automatically generate code for customized gateway scenarios.

Describe requirements in natural language

AI Gateway generates plugin code from your natural language requirements, with automated compilation and testing. To improve accuracy, structure your requirements as shown below:

# The request header handler
Return a fixed string to all incoming requests and allow the string to be modified.
# The request body handler
None
# The response header handler
None
# The response body handler
None
Important

The LLM evaluates requirement validity. If any of the requirements are deemed impractical, the process terminates with improvement suggestions. Then, revise your requirements accordingly.

Plugin basic code structure

Gateway plugin development involves two aspects:

  • Configuration parsing: reads the plugin input configurations.

  • Handler function: implements request header, request body, response header, and response body handling.

The following example shows an empty plugin in Go:

type MyConfig struct {
    // config items
}

func parseConfig(json gjson.Result, config *MyConfig, log wrapper.Log) error {
    // parse config form json
    return nil
}

// The request header handler
func onHttpRequestHeaders(ctx wrapper.HttpContext, config MyConfig, log wrapper.Log) types.Action {}

// The request body handler
func onHttpRequestBody(ctx wrapper.HttpContext, config MyConfig, body []byte, log wrapper.Log) types.Action {}

// The response header handler
func onHttpResponseHeaders(ctx wrapper.HttpContext, config MyConfig, log wrapper.Log) types.Action {}

// The response body handler
func onHttpResponseBody(ctx wrapper.HttpContext, config MyConfig, body []byte, log wrapper.Log) types.Action {}

Plugin generation and debugging

After the LLM generates the plugin code, it is automatically imported into WebIDE for functional validation and adjustments.